relay-tools / react-relay-network-modern

Relay Modern Network Layer with middlewares — cache, auth, retry, batch, logger, SSR
MIT License
327 stars 61 forks source link

Ensure GET requests do not include a body #145

Closed wyattjoh closed 1 year ago

wyattjoh commented 2 years ago

When a middleware changes the req.fetchOpts.method to GET, at the moment, it will try to send the body parameter down to fetch which causes an error:

TypeError: Window.fetch: HEAD or GET Request cannot have a body.

This change ensures that requests sent as GET will not include the body.

wyattjoh commented 2 years ago

Note that this further only sends down the parameters used by fetch, noteably not the url. It also ensures that the Content-Type header is not set on the upstream object, and is only sent to fetch if the body is being sent (it is a POST request and not form data).