Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect with followOriginalHttpMethod:true does not mantain the original body #2608

Closed
mirkods opened this issue Mar 24, 2017 · 9 comments · May be fixed by #2645
Closed

Redirect with followOriginalHttpMethod:true does not mantain the original body #2608

mirkods opened this issue Mar 24, 2017 · 9 comments · May be fixed by #2645
Labels

Comments

@mirkods
Copy link
Contributor

mirkods commented Mar 24, 2017

Summary

Hi there, I'm currently working with Cisco Meraki web APIs and they return a redirect for each request. During my test I noticed that the request's body is not propagated in the redirected requests.

Simplest Example to Reproduce

I created a simple express server to test it easily (it's online so you can use it for testing)

app.use(bodyParser.json());

app.post('/', (req, res) => {
  res.writeHead(308, {
    'location': 'https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body'
  });
  res.end();
});

app.post('/show-body', (req, res) => {
  res.send(200, req.body);
});

and this is a simple request snippet to prove that behavior:

const request = require('request');

const settings = { 
  method: 'POST',
  followAllRedirects: true,
  followOriginalHttpMethod: true,
  url: 'https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect',
  json: true,
  body: {
    test: 'redirect'
  }
}

request(settings, (err, response, body) => {
  console.log(response.statusCode)
  console.log(body) // this is empty instead of return the body that has been sent
})

This is the output running the snippet with request in debugging mode:

REQUEST { method: 'POST',
  followAllRedirects: true,
  followOriginalHttpMethod: true,
  url: 'https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect',
  json: true,
  body: { test: 'redirect' },
  callback: [Function] }
REQUEST make request https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect
REQUEST onRequestResponse https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect 308 { server: 'openresty',
  date: 'Fri, 24 Mar 2017 14:34:50 GMT',
  'transfer-encoding': 'chunked',
  connection: 'close',
  'cache-control': 'no-cache, no-store, must-revalidate',
  pragma: 'no-cache',
  expires: '0',
  'x-frame-options': 'DENY',
  'x-powered-by': 'Express',
  location: 'https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body',
  'access-control-allow-origin': 'http://body-redirect.stamplayapp.com',
  'access-control-allow-credentials': 'true',
  'access-control-allow-methods': 'GET, PUT, POST, DELETE, PATCH, OPTIONS',
  'access-control-allow-headers': 'Content-Type, Authorization, stamplay-app, x-stamplay-jwt, X-Requested-With',
  'access-control-expose-headers': 'Content-Type, Link, X-total-page, X-total-elements, x-stamplay-jwt' }
REQUEST redirect https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body
REQUEST redirect to https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body
REQUEST {}
REQUEST response end https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body 308 { server: 'openresty',
  date: 'Fri, 24 Mar 2017 14:34:50 GMT',
  'transfer-encoding': 'chunked',
  connection: 'close',
  'cache-control': 'no-cache, no-store, must-revalidate',
  pragma: 'no-cache',
  expires: '0',
  'x-frame-options': 'DENY',
  'x-powered-by': 'Express',
  location: 'https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body',
  'access-control-allow-origin': 'http://body-redirect.stamplayapp.com',
  'access-control-allow-credentials': 'true',
  'access-control-allow-methods': 'GET, PUT, POST, DELETE, PATCH, OPTIONS',
  'access-control-allow-headers': 'Content-Type, Authorization, stamplay-app, x-stamplay-jwt, X-Requested-With',
  'access-control-expose-headers': 'Content-Type, Link, X-total-page, X-total-elements, x-stamplay-jwt' }
REQUEST make request https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body
REQUEST onRequestResponse https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body 200 { server: 'openresty',
  date: 'Fri, 24 Mar 2017 14:34:50 GMT',
  'content-type': 'application/json; charset=utf-8',
  'content-length': '2',
  connection: 'close',
  'cache-control': 'no-cache, no-store, must-revalidate',
  pragma: 'no-cache',
  expires: '0',
  'x-frame-options': 'DENY',
  'x-powered-by': 'Express',
  etag: 'W/"2-a3a6bf43"',
  'access-control-allow-origin': 'https://body-redirect.stamplayapp.com',
  'access-control-allow-credentials': 'true',
  'access-control-allow-methods': 'GET, PUT, POST, DELETE, PATCH, OPTIONS',
  'access-control-allow-headers': 'Content-Type, Authorization, stamplay-app, x-stamplay-jwt, X-Requested-With',
  'access-control-expose-headers': 'Content-Type, Link, X-total-page, X-total-elements, x-stamplay-jwt' }
REQUEST reading response's body
REQUEST finish init function https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body
REQUEST response end https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body 200 { server: 'openresty',
  date: 'Fri, 24 Mar 2017 14:34:50 GMT',
  'content-type': 'application/json; charset=utf-8',
  'content-length': '2',
  connection: 'close',
  'cache-control': 'no-cache, no-store, must-revalidate',
  pragma: 'no-cache',
  expires: '0',
  'x-frame-options': 'DENY',
  'x-powered-by': 'Express',
  etag: 'W/"2-a3a6bf43"',
  'access-control-allow-origin': 'https://body-redirect.stamplayapp.com',
  'access-control-allow-credentials': 'true',
  'access-control-allow-methods': 'GET, PUT, POST, DELETE, PATCH, OPTIONS',
  'access-control-allow-headers': 'Content-Type, Authorization, stamplay-app, x-stamplay-jwt, X-Requested-With',
  'access-control-expose-headers': 'Content-Type, Link, X-total-page, X-total-elements, x-stamplay-jwt' }
REQUEST end event https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body
REQUEST has body https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body 2
REQUEST emitting complete https://body-redirect.stamplayapp.com/api/codeblock/v1/run/redirect/show-body

Expected Behavior

The expected behavior is that the original body is propagated about the redirects

Current Behavior

In the current behavior the redirected requests do not contain the original body

Possible Solution

Probably if the followOriginalHttpMethod is true and the method is different from GET or HEAD the request module should insert the original body in the redirected request.

Context

I'm currently working with Cisco Meraki web APIs and they return a redirect for each request. Since the request module an important part of my system I need to fix this behavior soon.

Environment

software version
request 2.81.02.81.0
node 6.10.0
npm 3.10.10
Operating System Mac OSx

Mirko

@claudiopetrini
Copy link

Any update on this?

@joelkelley
Copy link

I have the same issue... running PHP cURL exported straight from Postman and it returns "You are being redirected." rather than the actual response from Dashboard.

@mirkods
Copy link
Contributor Author

mirkods commented Apr 7, 2017

@mikeal @simov if you guys think that this could be a bug or a feature I can spend my time to perform a PR

@claudiopetrini
Copy link

Is there any update on this?

@nmarus
Copy link

nmarus commented Apr 28, 2017

Having same issue with Meraki Dashboard API that does a bunch of 302s and then a 308 redirect after which the POST body is gone. Changing the URL from their published one to the one that the redirects are using, fixes the issue.

@mirkods
Copy link
Contributor Author

mirkods commented May 2, 2017

@nmarus yes, you right. I have already tried this but anyway this remains a valid but in the module

@mirkods
Copy link
Contributor Author

mirkods commented Jan 25, 2018

Any news?

@Lorenzovds
Copy link

Lorenzovds commented Sep 20, 2018

This PR fixes this? Any reason the merge hasn't happened yet?

@stale
Copy link

stale bot commented Sep 20, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 20, 2019
@stale stale bot closed this as completed Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants