Comments (6)
fetch
goes through a different polyfill on server v on browser - node-fetch
on server v whatwg-fetch
on browser (both via isomorphic-fetch
). You could look at those.
from marty.
I'm actually not seeing what you report. If I run:
import {HttpStateSource} from 'marty';
HttpStateSource.removeHook('parseJSON');
const source = new HttpStateSource({});
source.post({
url: 'http://httpbin.org/post',
body: 'a=1'
})
.then(res => res.json())
.then(json => {
console.log('state source');
console.log(json)
});
fetch(
'http://httpbin.org/post',
{body: 'a=1', method: 'POST'}
)
.then(res => res.json())
.then(json => {
console.log('node-fetch');
console.log(json)
});
I get:
state source
{ args: {},
data: 'a=1',
files: {},
form: {},
headers:
{ Accept: '*/*',
'Accept-Encoding': 'gzip,deflate',
'Content-Length': '3',
Host: 'httpbin.org',
'User-Agent': 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)' },
json: null,
origin: '104.226.1.2',
url: 'http://httpbin.org/post' }
node-fetch
{ args: {},
data: 'a=1',
files: {},
form: {},
headers:
{ Accept: '*/*',
'Accept-Encoding': 'gzip,deflate',
'Content-Length': '3',
Host: 'httpbin.org',
'User-Agent': 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)' },
json: null,
origin: '104.226.1.2',
url: 'http://httpbin.org/post' }
i.e. the same behavior, with Content-Length
properly supplied in both cases.
Let me know if you see further issues.
from marty.
And you tested this running the system through app.renderToString
?
Becuase when I have the ran through renderToString
and then insert a
before hook. The request that is passed to the before hook does not have a
content-length header.
Also, what you are sending to console log is the response headers. My issue
is that the request headers do not have a content-length.
And the API I am hitting requires that on the request.
from marty.
The httpbin.org/post
endpoint echoes back the request headers - note the "Accept" settings and "User-Agent".
Your "before" hook will not see the content-length
header, because the content-length header is generated after that, i.e. the before hooks are all run before we call into fetch
.
from marty.
Gotcha. However, when I have fetch send route the request right back into my node API, and then I look at the request coming into that endpoint, I don't have a content-length header at the endpoint. Right now I have hacked around this by adding the header in the before hook, and this resolves the issue. That said, this feels like a hack, and something that will trip me up down the line.
from marty.
Try to see if you can reproduce the issue with node-fetch
(via isomorphic-fetch
) on its own. What you're describing sounds a lot like an issue there, which you should file as an issue w/the node-fetch
devs if possible.
from marty.
Related Issues (20)
- Cannot read property '0' of undefined HOT 2
- Does the GitHub fetch library have to be used in HTTP Sources? HOT 3
- webpack, babel, karma & marty v0.9.17 problem with requiring react HOT 5
- I can't get Marty session storage to persist between tabs or Marty localStorage to work at all! HOT 8
- Running headless tests with PhantomJS as a 'browser' fails HOT 2
- Return error in locally HOT 5
- Optionally require `es6-promise` and `isomorphic-fetch` HOT 2
- not properly escaping "</script>" in app state dehydration HOT 2
- test-utils component specs throw on undefined `document` element HOT 10
- Performance Implications? HOT 2
- React.createElement called on each store change
- Consider reversing order in this.handlers HOT 4
- Application.renderToString performance HOT 5
- Application.RenderToString hangs when fetch result returns the value false. HOT 1
- no-iisue HOT 1
- Fetch state in a container based on the result of another fetch HOT 1
- Support React 0.14.0 HOT 6
- Update Docs HOT 2
- How awesome this project has been! HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marty.