80 Commits

Author SHA1 Message Date
shaohui.tsh
89f9ef87e0 feat: 添加response自处理参数 2018-04-20 11:35:07 -04:00
Sean Willis
2c98416ac2 Adding ability to set cookie path 2018-04-20 11:35:07 -04:00
Yuta Shimizu
961f457622 [WIP] Revert default behavior of writeHeaders method (#1104)
* Replace header key only

* Add preserveHeaderKeyCase Option
2016-12-06 09:51:01 -05:00
Kris Williams
8cb451f20c Enable proxy response to have multiple Set-Cookie raw headers #1101 2016-12-04 10:58:49 -05:00
Maarten ter Horst
927357bedc Fix newly introduced error in error handler for ECONNREFUSED in forward proxy (#1100) 2016-12-02 09:09:11 -05:00
Yuta Shimizu
4edbb62cc5 Keep original letter case of response header keys (#1098)
* Keep original letter case of response header keys

* Support node older than v0.11.6

messege.rawHeaders was added in v0.11.6

* Extract duplicated logic to method
2016-12-01 20:03:13 -05:00
Maarten ter Horst
69cf892519 Handle errors for forward request, add test case (#1099) 2016-12-01 09:39:46 -05:00
Jarrett Cruger
d0f1dfeb82 [fix] style nits 2016-10-22 11:45:16 -04:00
François Leurent
220f5fb795 Expose full callback names 2016-10-22 11:45:16 -04:00
François Leurent
d48f67eb90 Do not rely on func.name (no scope) 2016-10-22 11:45:16 -04:00
François Leurent
61c2889109 Do not rely on func.name (no scope) 2016-10-22 11:45:16 -04:00
Niranjan Ojha
2d01edc5a5 not setting connection header in case of http2 as it is deprecated 2016-10-06 16:24:44 -04:00
briman0094
84087208dd Properly write response header optionally including statusMessage (#1061) 2016-09-14 17:08:26 -04:00
Alex Indigo
b781af641a Made it not to crash with omited Host http header (#1050) 2016-09-14 07:03:48 -04:00
Cole Chamberlain
d8fb344715 Fix for Reason-Phrase being overwritten on proxy response. (#1051)
* Fix for Reason-Phrase being overwritten on proxy response.

Calling res.writeHead has the side effect of defaulting the Reason-Phrase to default ones.  I'm using Reason-Phrase codes to sub-route api responses and they were all being reset.  This change only sets the statusMessage (Reason-Phrase) if it exists on the proxyRes and is successfully passing it through in my tests.

* Fixed spaces and bracket formatting.
2016-09-13 18:19:33 -04:00
Jeremy Judeaux
1e52f660f0 cookieDomainRewrite option (#1009) 2016-08-12 13:42:18 -04:00
Gabriel Boucher
183b5bb4fc Location rewriting for responses with status 201 (#1024)
Implement rewriting of the location header for responses with status code 201, according to RFC2616 section 10.2.2
2016-08-11 12:36:17 -04:00
Deividy Metheler
42df703830 Emit disconnected event instead of error when ECONNRESET (#966)
* Emit disconnected event instead of error when ECONNRESET

ECONNRESET means the other side of the TCP conversation abruptly
closed its end of the connection.

If we get an ECONNRESET error from the proxy request and the
socket is destroyed this means that the client has closed
his connection, and emit this as an error can lead to
confusion and hacks to filter that kind of message.

I think that the best we can do is abort and emit another event,
so if any caller wants to handle with that kind of error, he can
by listen the disconnected event.

https://github.com/nodejitsu/node-http-proxy/issues/813

* code standards, move econnreset check, change ev name
2016-06-03 13:39:40 -04:00
Mihai Ene
284903d379 Sanitize header keys before setting them (#997)
Fixes #996.
2016-04-26 13:26:35 -07:00
Jakob Backlund
ef86b50427 Set the x-forwarded-host flag when xfwd is enabled
Reasoning: Rack's request class [makes use of](https://github.com/rack/rack/blob/master/lib/rack/request.rb#L243) this HTTP header. Certain edge-case scenarios (proxying from ember-cli to a Rails backend) can be problematic without this header being present.

/cc @perlun, @jesjos
2016-02-26 14:29:55 +02:00
Tobias Bieniek
5c46e4b754 Remove "transfer-encoding" header if "content-length" is set to zero 2016-02-15 15:43:14 +01:00
merpnderp
3b39d2c3dc Added check to passes/web-outgoing.js to make sure the header being set is not undefined, which should be the only falsey value that could accidently show up and break that call. This fixes windows NTLM auth issues behind http-proxy. 2016-01-22 09:17:14 -06:00
Laurent Brucher
9752652e76 fixes after PR review 2015-10-22 18:38:58 +02:00
Laurent Brucher
a05fc2d169 Provide a "proxyReq" event also for websocket connections. 2015-10-22 15:56:34 +02:00
Jarrett Cruger
cea0e8676b [fix] make more functional 2015-08-30 17:28:05 -04:00
Arttu Liimola
3d2350c54f Replaced Object.keys().map with for in loop. 2015-08-30 17:16:42 -04:00
Arttu Liimola
da674ec4df Modify the set-cookie header fix to work with node 0.10.x. 2015-08-30 17:16:07 -04:00
Arttu Liimola
8bfd90c4d9 Use raw headers instead parsed.
Set-Cookie headers are parsed into single header with cookies in array.
This messes up the Set-Cookie headers, because browser receives multiple Set-Cookie headers as single with cookies separted with comma.
2015-08-30 17:15:54 -04:00
Jeremy Judeaux
5f14bcaa70 fix protocol and default port detection on node 0.12.x, compatible with 0.10.x 2015-04-02 14:23:58 +02:00
Jarrett Cruger
5a969d077b Merge pull request #787 from mokafive/master
Fixes / additions to URL rewriting
2015-04-01 12:20:37 -04:00
Feross Aboukhadijeh
6d074eff47 fix "x-forwarded-proto" in node 0.12 and iojs
The way to detect TLSSockets in node 0.12 and iojs has changed. You can
just check `socket.encrypted` now :)

Fixes #772
2015-03-11 00:33:34 -07:00
Matt Hauck
26029ba7ac only rewrite redirect urls when it matches target
if functioning as a reverse proxy for host1.foo.com,
with a backend target of backend.foo.com:8080, the
node proxy should only rewrite the redirect if it is
a redirect to somewhere on backend.foo.com:8080
2015-03-09 13:17:52 -07:00
Matt Hauck
7f2f3ac35c Add support for auto host rewriting and protocol rewriting
auto host rewriting allows rewriting to work as expected in most
cases without extra cumbersome configuration

protocol rewriting allows node-http-proxy to be able to listen
over HTTPS and properly reverse-proxy to sites running over HTTP
(to avoid doing SSL twice)
2015-02-05 12:17:26 -08:00
Jarrett Cruger
ea0a4ded80 [fix] style spacing wtf 2014-12-17 00:53:51 -07:00
Jorge Leal
c62610e8e4 Deprecated proxySocket event in favor to open event.
Maintained both proxySocket and open for backward compatibility.

Conflicts:
	test/lib-http-proxy-test.js
2014-12-17 00:52:19 -07:00
Jorge
26537866b3 [api] add close event in ws-incoming.js 2014-12-17 00:51:06 -07:00
Jarrett Cruger
c04485671a [fix] use simple regex instead of indexOf to check the protocol to support without the colon fixes #711 2014-12-08 23:04:23 -05:00
Jarrett Cruger
8d68ac0e0f [fix] be defensive and ensure location is in headers before running url.parse() 2014-11-25 17:22:23 -05:00
Jarrett Cruger
48ae5d828c [minor] style consistency 2014-11-25 17:21:24 -05:00
Jarrett Cruger
95a588706b Merge pull request #741 from samccone/sjs/redirect-host-rewrite
Allow optional redirect host rewriting.
2014-11-25 17:08:54 -05:00
Mike Pennisi
8a24a1e18f Set Content-Length header for OPTIONS requests
Web browsers automatically issue an OPTIONS request in advance of other
HTTP requests when the document's domain does not match the target in
order to facilitate Cross-Origin Resource Sharing. These requests are
forbidden from specifying a body and typically do not specify an
(unecessary) `Length` header.

Node.js automatically adds the `Content-Encoding: chunked` header value
to requests that do not specify a `Length` header. This makes proxied
OPTIONS requests from web browsers invalid.

Explicitly set the `Content-Length` header of all `OPTIONS` requests to
"0", disabling the default "chunked" encoding behavior [2].

[1] http://www.w3.org/TR/cors/
[2] http://nodejs.org/api/http.html
2014-11-24 17:14:48 -05:00
Sam Saccone
daf66a7a88 Allow optional redirect host rewriting. 2014-11-23 19:22:07 -05:00
jleal52
9ba8311343 Updated to support error callback on proxy.web and start/proxyReq/end continue working. 2014-11-12 14:41:46 +00:00
MinRK
c62766391e close socket if upstream request fails
adds socket.end() to on('error') handlers for proxyReq and proxySocket
2014-09-30 19:58:57 -07:00
MinRK
bcd8a564a8 close websocket if proxyReq is closed before upgrade
avoids leaving client sockets open when upstream
connections are rejected.
2014-09-30 17:01:20 -07:00
Jarrett Cruger
10a294af4d [fix] do a check to make sure the server exists before we try and emit 2014-09-30 15:22:52 -04:00
Thorsten Lorenz
000eb533de emitting proxySocket on proxyServer
- emitted once proxySocket was created and socket was piped into it
- needed to support sniffing messages coming from proxy target
2014-09-29 20:09:46 -04:00
Manu Sporny
db5f2954b2 [api] Add event-based ability to modify pre-flight proxy requests. 2014-07-18 11:46:04 -04:00
Jarrett Cruger
d1baa3684e [api] also emit the target on a proxy error 2014-07-08 16:12:57 -04:00
Damian Kaczmarek
7b79a7409a Change name targetTimeout to proxyTimeout 2014-06-10 19:04:12 +02:00