Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-http-proxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
node-http-proxy
Commits
eb6f9a63
Commit
eb6f9a63
authored
Jun 26, 2011
by
indexzero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[api] Simplify the usage for the `.changeHeaders` option. Fixes #34
parent
9d9509f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
9 deletions
+20
-9
lib/node-http-proxy.js
lib/node-http-proxy.js
+20
-9
No files found.
lib/node-http-proxy.js
View file @
eb6f9a63
...
...
@@ -235,11 +235,22 @@ var HttpProxy = exports.HttpProxy = function (options) {
var
self
=
this
;
options
=
options
||
{};
options
.
target
=
options
.
target
||
{};
//
// Setup basic proxying options
//
this
.
https
=
options
.
https
;
this
.
forward
=
options
.
forward
;
this
.
target
=
options
.
target
;
this
.
target
=
options
.
target
||
{};
//
// Setup additional options for WebSocket proxying. When forcing
// the WebSocket handshake to change the `sec-websocket-location`
// and `sec-websocket-origin` headers `options.source` **MUST**
// be provided or the operation will fail with an `origin mismatch`
// by definition.
//
this
.
source
=
options
.
source
||
{
host
:
'
localhost
'
,
port
:
8000
};
this
.
changeOrigin
=
options
.
changeOrigin
||
false
;
if
(
options
.
router
)
{
...
...
@@ -684,12 +695,18 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
// Setup the incoming client socket.
_socket
(
socket
);
function
getPort
(
port
)
{
port
=
port
||
80
;
return
port
-
80
===
0
?
''
:
'
:
'
+
port
}
//
// Get the protocol, and host for this request and create an instance
// of `http.Agent` or `https.Agent` from the pool managed by `node-http-proxy`.
//
var
protocolName
=
options
.
https
||
this
.
target
.
https
?
'
https
'
:
'
http
'
,
remoteHost
=
options
.
host
+
(
options
.
port
-
80
===
0
?
''
:
'
:
'
+
options
.
port
),
portUri
=
getPort
(
this
.
source
.
port
),
remoteHost
=
options
.
host
+
portUri
,
agent
=
_getAgent
(
options
.
host
,
options
.
port
,
options
.
https
||
this
.
target
.
https
);
// Change headers (if requested).
...
...
@@ -777,12 +794,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
// Get the Non-Printable data
data
=
data
.
slice
(
Buffer
.
byteLength
(
sdata
),
data
.
length
);
//
// Replace the host and origin headers in the Printable data
//
sdata
=
sdata
.
replace
(
remoteHost
,
options
.
host
)
.
replace
(
remoteHost
,
options
.
host
);
if
(
self
.
https
&&
!
self
.
target
.
https
)
{
//
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment