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

POST with body hangs when proxied #530

Closed
tikonen opened this issue Dec 4, 2013 · 2 comments
Closed

POST with body hangs when proxied #530

tikonen opened this issue Dec 4, 2013 · 2 comments

Comments

@tikonen
Copy link

tikonen commented Dec 4, 2013

Example app http-proxy-post-test.js:

var express = require('express'),
    httpProxy = require('http-proxy');

var app = express();
app.use(express.cookieParser());
app.use(express.bodyParser());


app.all('/noproxy', function(req, res) {
    res.send('Hello World\n');
});

var proxy = new httpProxy.RoutingProxy();
app.all('/proxyme', function(req, res) {
    proxy.proxyRequest(req, res, {
        host: 'google.com',
        port: 80
    });
});

app.listen(8080);

Run this with node and try with CURL

node http-proxy-post-test.js

Get to non-proxied URL is ok

~ $ curl http://localhost:8080/noproxy
Hello World

Get to proxied URL is ok (request goes to google.com)

~ $ curl http://localhost:8080/proxyme
<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 404 (Not Found)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
  </style>
  <a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/proxyme</code> was not found on this server.  <ins>That’s all we know.</ins>

Post with no body is ok

~ $ curl -X POST http://localhost:8080/proxyme
<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 404 (Not Found)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
  </style>
  <a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/proxyme</code> was not found on this server.  <ins>That’s all we know.</ins>

Post with body hangs and proxyRequest never sends response or tries to connect to google.com

~ $ curl -X POST -d '{"foo":1}' http://localhost:8080/proxyme
^C
@tikonen
Copy link
Author

tikonen commented Dec 9, 2013

Seems to be duplicate of this #180 and caused by express bodyParser

@tikonen tikonen closed this as completed Dec 9, 2013
@danday74
Copy link

remove use of "body-parser" module and use "body" module instead.

see this SO post ... https://stackoverflow.com/questions/49393092/webpack-config-proxy-request-body-logging/49400672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants