http request does not emit 'end' after proxy

ngourley

I need to be able to use the http request body in my request proxy application and then again in the actual web service. I am using restreamer to 'reset' the stream (and even wrote the middleware myself with no change). The web service receives the body just fine, but because end is never emitted, I cannot continue with the request.

Testing with postman, sending a raw body, with content type set. Any suggestions would be greatly appreciated. Thanks!

var   express = require('express')
    , bodyParser = require('body-parser')
    , http = require('http')
    , restreamer = require('connect-restreamer')
    , httpProxy = require('http-proxy')

var app = express();

app.use(function (req, res, next) {
    var body = '';
    req.on('data', function (chunk) {
        body += chunk.toString('utf8');

    });
    req.on('end', function (chunk) {
        req.body = JSON.parse(body)
        next();
    });
});

app.use(restreamer());

var proxy = httpProxy.createServer();

app.all('*', function (req, res) {
    proxy.web(req, res, {
        target: 'http://localhost:8001'
    });
});

http.createServer(app).listen(8000);

app2 = express();

app2.use(function (req, res, next) {
    var body = '';
    req.on('data', function (chunk) {
        body += chunk.toString('utf8');

    });
    req.on('end', function (chunk) {
        req.body = JSON.parse(body)
        next();
    });
});

app2.all('*', function (req, res) {
    res.send(req.body)
});

http.createServer(app2).listen(8001);
ngourley

Using the request library in my application, it worked:

var request = require('request')
request.post({
    url: 'http://localhost:8000',
    json: {content: 123, type: "greeting", access_token: "here i am"}
},function(err, res,data){
    console.log('return:' ,err, data)
});

But using curl with a file containing the same message, it would not work:

curl -X POST -d @data.json http://localhost:8000 --header "Content-Type:application/json"

I compared the request objects against each other and found a few differences and when I got to the request header for content-length, I found that editing it the "correct" length would end the steam (and the web server would send a response).

I will make the modifications needed and commit to connect-restreamer module.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

XMLHTTP-Request (AJAX) with VBSkript does not work with proxy connection

분류에서Dev

Does emit copy its arguments?

분류에서Dev

Send HTTP GET Request After X Seconds, Service Gets Killed

분류에서Dev

Angular doesn't update my object after http request

분류에서Dev

Async HTTP response is holding some seconds after finish the request

분류에서Dev

Can't make recursive call to Http.Request from within end event of Response

분류에서Dev

HTTP Request with No HTTP Response

분류에서Dev

Why does c++ program crash after temporary object is destroyed at end of scope

분류에서Dev

Why does suffixing an ampersand at the end of a GTK command, result in extra output in the next command after close?

분류에서Dev

http post request curl

분류에서Dev

Nginx proxy: rewrite rule for root request

분류에서Dev

Charles web debugging proxy request java

분류에서Dev

CentOS http_proxy 대 https_proxy

분류에서Dev

acquire::http::proxy for only specified repositories

분류에서Dev

export HTTP_PROXY and special characters in passwd

분류에서Dev

Node-HTTP-Proxy 오류

분류에서Dev

http-proxy-rules 및 Websockets

분류에서Dev

Node http-proxy - HTTP message contains illegal headers

분류에서Dev

http_proxy 설정의 추가 http

분류에서Dev

Waiting for an async HTTP request to complete

분류에서Dev

HTTP Request from Dockerfile not successful

분류에서Dev

Load Angular Spinner on http request

분류에서Dev

Weird response with Xcode and HTTP request

분류에서Dev

Issue with submitting an HTTP POST request

분류에서Dev

Debian Linux: How can I expose a SOCKS proxy as a HTTP proxy for the purpose of HTTP/HTTPS requests?

분류에서Dev

Xubuntu: No password request after suspension

분류에서Dev

GET Request after POST(login)

분류에서Dev

How to remove referer from get request in Nginx reverse proxy?

분류에서Dev

How can I make a c# https web request that works in both proxy and no proxy situations

Related 관련 기사

  1. 1

    XMLHTTP-Request (AJAX) with VBSkript does not work with proxy connection

  2. 2

    Does emit copy its arguments?

  3. 3

    Send HTTP GET Request After X Seconds, Service Gets Killed

  4. 4

    Angular doesn't update my object after http request

  5. 5

    Async HTTP response is holding some seconds after finish the request

  6. 6

    Can't make recursive call to Http.Request from within end event of Response

  7. 7

    HTTP Request with No HTTP Response

  8. 8

    Why does c++ program crash after temporary object is destroyed at end of scope

  9. 9

    Why does suffixing an ampersand at the end of a GTK command, result in extra output in the next command after close?

  10. 10

    http post request curl

  11. 11

    Nginx proxy: rewrite rule for root request

  12. 12

    Charles web debugging proxy request java

  13. 13

    CentOS http_proxy 대 https_proxy

  14. 14

    acquire::http::proxy for only specified repositories

  15. 15

    export HTTP_PROXY and special characters in passwd

  16. 16

    Node-HTTP-Proxy 오류

  17. 17

    http-proxy-rules 및 Websockets

  18. 18

    Node http-proxy - HTTP message contains illegal headers

  19. 19

    http_proxy 설정의 추가 http

  20. 20

    Waiting for an async HTTP request to complete

  21. 21

    HTTP Request from Dockerfile not successful

  22. 22

    Load Angular Spinner on http request

  23. 23

    Weird response with Xcode and HTTP request

  24. 24

    Issue with submitting an HTTP POST request

  25. 25

    Debian Linux: How can I expose a SOCKS proxy as a HTTP proxy for the purpose of HTTP/HTTPS requests?

  26. 26

    Xubuntu: No password request after suspension

  27. 27

    GET Request after POST(login)

  28. 28

    How to remove referer from get request in Nginx reverse proxy?

  29. 29

    How can I make a c# https web request that works in both proxy and no proxy situations

뜨겁다태그

보관