Skip to content

Commit 6d7f5c6

Browse files
committed
Merge pull request #7 from tjanczuk/master
Update azure/master with latest changes from tjanczuk/master
2 parents c08f4bd + c02e410 commit 6d7f5c6

File tree

6 files changed

+75
-43
lines changed

6 files changed

+75
-43
lines changed

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ Hosting node.js applications in IIS on Windows
88

99
**Why would I want to do it?**
1010

11-
[Benefits](https://github.com/tjanczuk/iisnode/wiki)
11+
[Benefits](https://github.com/tjanczuk/iisnode/wiki)
1212

1313
**Who uses iisnode?**
1414

15-
[windows azure - benefits](http://blogs.msdn.com/b/hanuk/archive/2012/05/05/top-benefits-of-running-node-js-on-windows-azure.aspx)
16-
[windows azure - get started with node.js](https://www.windowsazure.com/en-us/develop/nodejs/)
17-
[appharbor.com](http://blog.appharbor.com/2012/01/19/announcing-node-js-support)
18-
[discountasp.net](http://discountasp.net/press/2012_06_12_free-webmatrix-v2-rc-hosting-with-nodejs.aspx)
19-
[arvixe.com](http://arvixe.com)
20-
[smarterasp.net](http://www.smarterasp.net/)
21-
[gearhost.com](http://gearhost.com/)
22-
[webecs.com](http://webecs.com/)
15+
- [Microsoft azure - benefits](http://blogs.msdn.com/b/hanuk/archive/2012/05/05/top-benefits-of-running-node-js-on-windows-azure.aspx)
16+
- [Microsoft azure - get started with node.js](http://azure.microsoft.com/en-us/develop/nodejs/)
17+
- [appharbor.com](http://blog.appharbor.com/2012/01/19/announcing-node-js-support)
18+
- [discountasp.net](http://discountasp.net/press/2012_06_12_free-webmatrix-v2-rc-hosting-with-nodejs.aspx)
19+
- [arvixe.com](http://arvixe.com)
20+
- [smarterasp.net](http://www.smarterasp.net/)
21+
- [gearhost.com](http://gearhost.com/)
22+
- [webecs.com](http://webecs.com/)
2323

2424
**Prerequisites for using**
2525

@@ -31,8 +31,8 @@ Hosting node.js applications in IIS on Windows
3131

3232
**Installing for IIS 7.x/8.x**
3333

34-
- Install iisnode for IIS 7.x/8.x: [x86](http://go.microsoft.com/?linkid=9784330) or [x64](http://go.microsoft.com/?linkid=9784331) - choose bitness matching your system
35-
- To set up samples, from the administrative command prompt call `%programfiles%\iisnode\setupsamples.bat`
34+
- Install iisnode for IIS 7.x/8.x: [x86](https://github.com/tjanczuk/iisnode/releases/download/v0.2.11/iisnode-full-v0.2.11-x86.msi) or [x64](https://github.com/tjanczuk/iisnode/releases/download/v0.2.11/iisnode-full-v0.2.11-x64.msi) - choose bitness matching your system
35+
- To set up samples, from the administrative command prompt call `%programfiles%\iisnode\setupsamples.bat`
3636
- Go to `http://localhost/node`
3737

3838
**Installing for IIS Express/WebMatrix**
@@ -43,20 +43,20 @@ Hosting node.js applications in IIS on Windows
4343

4444
**Howtos**
4545

46-
[the basics](http://tomasz.janczuk.org/2011/08/hosting-nodejs-applications-in-iis-on.html)
47-
[the basics (Pусский перевод)](http://softdroid.net/hosting-nodejs-applications-ru)
48-
[**NEW: websockets**] (http://tomasz.janczuk.org/2012/11/how-to-use-websockets-with-nodejs-apps.html)
49-
[using with express framework](http://tomasz.janczuk.org/2011/08/hosting-express-nodejs-applications-in.html)
50-
[using with URL rewrite module](http://tomasz.janczuk.org/2011/08/using-url-rewriting-with-nodejs.html)
51-
[using with WebMatrix and IIS Express](http://tomasz.janczuk.org/2011/08/developing-nodejs-applications-in.html)
52-
[site templates for WebMatrix](https://github.com/SteveSanderson/Node.js-Site-Templates-for-WebMatrix)
53-
[using with mongodb](http://www.amazedsaint.com/2011/09/creating-10-minute-todo-listing-app-on.html)
54-
[diagnosing problems with ETW traces](http://tomasz.janczuk.org/2011/09/using-event-tracing-for-windows-to.html)
55-
[using with MVC](http://weblogs.asp.net/jgalloway/archive/2011/10/26/using-node-js-in-an-asp-net-mvc-application-with-iisnode.aspx)
56-
[portuguese: node.js no windows: instalando o iisnode](http://vivina.com.br/nodejs-windows-parte-2)
57-
[integrated debugging](http://tomasz.janczuk.org/2011/11/debug-nodejs-applications-on-windows.html)
58-
[pub/sub server using faye](http://weblogs.asp.net/cibrax/archive/2011/12/12/transform-your-iis-into-a-real-time-pub-sub-engine-with-faye-node.aspx)
59-
[appharbor uses iisnode](http://blog.appharbor.com/2012/01/19/announcing-node-js-support)
46+
[the basics](http://tomasz.janczuk.org/2011/08/hosting-nodejs-applications-in-iis-on.html)
47+
[the basics (Pусский перевод)](http://softdroid.net/hosting-nodejs-applications-ru)
48+
[**NEW: websockets**] (http://tomasz.janczuk.org/2012/11/how-to-use-websockets-with-nodejs-apps.html)
49+
[using with express framework](http://tomasz.janczuk.org/2011/08/hosting-express-nodejs-applications-in.html)
50+
[using with URL rewrite module](http://tomasz.janczuk.org/2011/08/using-url-rewriting-with-nodejs.html)
51+
[using with WebMatrix and IIS Express](http://tomasz.janczuk.org/2011/08/developing-nodejs-applications-in.html)
52+
[site templates for WebMatrix](https://github.com/SteveSanderson/Node.js-Site-Templates-for-WebMatrix)
53+
[using with mongodb](http://www.amazedsaint.com/2011/09/creating-10-minute-todo-listing-app-on.html)
54+
[diagnosing problems with ETW traces](http://tomasz.janczuk.org/2011/09/using-event-tracing-for-windows-to.html)
55+
[using with MVC](http://weblogs.asp.net/jgalloway/archive/2011/10/26/using-node-js-in-an-asp-net-mvc-application-with-iisnode.aspx)
56+
[portuguese: node.js no windows: instalando o iisnode](http://vivina.com.br/nodejs-windows-parte-2)
57+
[integrated debugging](http://tomasz.janczuk.org/2011/11/debug-nodejs-applications-on-windows.html)
58+
[pub/sub server using faye](http://weblogs.asp.net/cibrax/archive/2011/12/12/transform-your-iis-into-a-real-time-pub-sub-engine-with-faye-node.aspx)
59+
[appharbor uses iisnode](http://blog.appharbor.com/2012/01/19/announcing-node-js-support)
6060

6161
**Prerequisites for building**
6262

@@ -67,15 +67,15 @@ Hosting node.js applications in IIS on Windows
6767

6868
**Building**
6969

70-
Build commands should be issued from the build environment set up with `"%programfiles(x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"`, assuming default installation location of Visual Studio 2012 on x64 platform.
70+
Build commands should be issued from the build environment set up with `"%programfiles(x86)%\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"`, assuming default installation location of Visual Studio 2012 on x64 platform.
7171

72-
For x86 build:
72+
For x86 build:
7373

7474
```
7575
msbuild /p:Platform=Win32 src\iisnode\iisnode.sln
7676
```
7777

78-
For x64 build:
78+
For x64 build:
7979

8080
```
8181
msbuild /p:Platform=x64 src\iisnode\iisnode.sln
@@ -85,7 +85,7 @@ msbuild /p:Platform=x64 src\iisnode\iisnode.sln
8585

8686
- For IIS 7.x/8.0: `build\debug\{x64|x86}\iisnode-full.msi`
8787
- For IIS Express 7.x: `build\debug\x86\iisnode-express.msi`
88-
88+
8989
**Running tests**
9090

9191
- Install for IIS 7.x/8.x (see previous sections)
@@ -94,6 +94,6 @@ msbuild /p:Platform=x64 src\iisnode\iisnode.sln
9494

9595
**Resources & documentation**
9696

97-
[Releases](https://github.com/tjanczuk/iisnode/wiki/iisnode-releases)
98-
[Wiki](https://github.com/tjanczuk/iisnode/wiki)
99-
[Blog](http://tomasz.janczuk.org)
97+
[Releases](https://github.com/tjanczuk/iisnode/wiki/iisnode-releases)
98+
[Wiki](https://github.com/tjanczuk/iisnode/wiki)
99+
[Blog](http://tomasz.janczuk.org)

src/iisnode/chttpprotocol.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ PCSTR CHttpProtocol::httpRequestHeaders[] = {
4646
"User-Agent"
4747
};
4848

49+
const PCSTR CHttpProtocol::schemeHttp = "http";
50+
const PCSTR CHttpProtocol::schemeHttps = "https";
51+
4952
HRESULT CHttpProtocol::Append(IHttpContext* context, const char* content, DWORD contentLength, void** buffer, DWORD* bufferLength, DWORD* offset)
5053
{
5154
HRESULT hr;
@@ -93,7 +96,7 @@ HRESULT CHttpProtocol::SerializeRequestHeaders(CNodeHttpStoredContext* ctx, void
9396
USHORT originalUrlLength;
9497
DWORD remoteHostSize = INET6_ADDRSTRLEN + 1;
9598
char remoteHost[INET6_ADDRSTRLEN + 1];
96-
BOOL addXFF;
99+
BOOL addXFF, addXFP;
97100
char** serverVars;
98101
int serverVarCount;
99102

@@ -160,11 +163,11 @@ HRESULT CHttpProtocol::SerializeRequestHeaders(CNodeHttpStoredContext* ctx, void
160163

161164
// Unknown headers
162165

163-
if (TRUE == (addXFF = CModuleConfiguration::GetEnableXFF(context)))
166+
if (TRUE == (addXFF = addXFP = CModuleConfiguration::GetEnableXFF(context)))
164167
{
165168
PSOCKADDR addr = request->GetRemoteAddress();
166169
DWORD addrSize = addr->sa_family == AF_INET ? sizeof SOCKADDR_IN : sizeof SOCKADDR_IN6;
167-
ErrorIf(0 != WSAAddressToString(addr, addrSize, NULL, remoteHost, &remoteHostSize), GetLastError());
170+
ErrorIf(0 != GetNameInfo(addr, addrSize, remoteHost, remoteHostSize, NULL, 0, NI_NUMERICHOST), GetLastError());
168171
}
169172

170173
for (int i = 0; i < raw->Headers.UnknownHeaderCount; i++)
@@ -173,15 +176,20 @@ HRESULT CHttpProtocol::SerializeRequestHeaders(CNodeHttpStoredContext* ctx, void
173176
CheckError(CHttpProtocol::Append(context, ": ", 2, result, &bufferLength, &offset));
174177
CheckError(CHttpProtocol::Append(context, raw->Headers.pUnknownHeaders[i].pRawValue, raw->Headers.pUnknownHeaders[i].RawValueLength, result, &bufferLength, &offset));
175178

176-
if (addXFF && 15 == raw->Headers.pUnknownHeaders[i].NameLength && 0 == strcmpi("X-Forwarded-For", raw->Headers.pUnknownHeaders[i].pName))
179+
if (addXFF && 15 == raw->Headers.pUnknownHeaders[i].NameLength && 0 == _stricmp("X-Forwarded-For", raw->Headers.pUnknownHeaders[i].pName))
177180
{
178181
// augment existing X-Forwarded-For header
179182

180183
CheckError(CHttpProtocol::Append(context, ", ", 2, result, &bufferLength, &offset));
181-
CheckError(CHttpProtocol::Append(context, remoteHost, remoteHostSize - 1, result, &bufferLength, &offset));
184+
CheckError(CHttpProtocol::Append(context, remoteHost, 0, result, &bufferLength, &offset));
182185

183186
addXFF = FALSE;
184187
}
188+
else if (addXFP && 17 == raw->Headers.pUnknownHeaders[i].NameLength && 0 == _stricmp("X-Forwarded-Proto", raw->Headers.pUnknownHeaders[i].pName))
189+
{
190+
// Already exists in incoming headers; don't add a second one
191+
addXFP = FALSE;
192+
}
185193

186194
CheckError(CHttpProtocol::Append(context, "\r\n", 2, result, &bufferLength, &offset));
187195
}
@@ -191,10 +199,29 @@ HRESULT CHttpProtocol::SerializeRequestHeaders(CNodeHttpStoredContext* ctx, void
191199
// add a new X-Forwarded-For header
192200

193201
CheckError(CHttpProtocol::Append(context, "X-Forwarded-For: ", 17, result, &bufferLength, &offset));
194-
CheckError(CHttpProtocol::Append(context, remoteHost, remoteHostSize - 1, result, &bufferLength, &offset));
202+
CheckError(CHttpProtocol::Append(context, remoteHost, 0, result, &bufferLength, &offset));
195203
CheckError(CHttpProtocol::Append(context, "\r\n", 2, result, &bufferLength, &offset));
196204
}
197205

206+
if (addXFP)
207+
{
208+
// Determine the incoming request protocol scheme
209+
PCSTR varValue, varScheme = schemeHttp;
210+
DWORD varValueLength;
211+
if (S_OK == context->GetServerVariable("HTTPS", &varValue, &varValueLength))
212+
{
213+
if (0 == _stricmp("on", varValue))
214+
{
215+
varScheme = schemeHttps;
216+
}
217+
}
218+
219+
// Add the X-Forwarded-Proto header (default is http)
220+
CheckError(CHttpProtocol::Append(context, "X-Forwarded-Proto: ", 19, result, &bufferLength, &offset));
221+
CheckError(CHttpProtocol::Append(context, varScheme, 0, result, &bufferLength, &offset));
222+
CheckError(CHttpProtocol::Append(context, "\r\n", 2, result, &bufferLength, &offset));
223+
}
224+
198225
// promote server variables
199226

200227
CheckError(CModuleConfiguration::GetPromoteServerVars(context, &serverVars, &serverVarCount));

src/iisnode/chttpprotocol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class CHttpProtocol
77
{
88
private:
99

10+
static const PCSTR schemeHttp;
11+
static const PCSTR schemeHttps;
12+
1013
static PCSTR httpRequestHeaders[HttpHeaderRequestMaximum];
1114
static HRESULT Append(IHttpContext* context, const char* content, DWORD contentLength, void** buffer, DWORD* bufferLength, DWORD* offset);
1215

src/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.10
1+
0.2.11

test/functional/tests/118_xff.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ iisnode adds X-Forwarded-For header to HTTP requests when issnode\@enableXFF is
55
var iisnodeassert = require("iisnodeassert");
66

77
iisnodeassert.sequence([
8-
iisnodeassert.get(10000, "/118_xff/hello.js", 200, "Request contains X-Forwarded-For header")
8+
iisnodeassert.get(10000, "/118_xff/hello.js", 200, "Request contains X-Forwarded-For and X-Forwarded-Proto headers", { 'x-echo-x-forwarded-for': '127.0.0.1', 'x-echo-x-forwarded-proto': 'http' }),
9+
iisnodeassert.post(10000, "/118_xff/hello.js", { headers: { 'X-Forwarded-Proto': 'https' }}, 200, "Request contains X-Forwarded-For and X-Forwarded-Proto headers", { 'x-echo-x-forwarded-for': '127.0.0.1', 'x-echo-x-forwarded-proto': 'https' })
910
]);

test/functional/www/118_xff/hello.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ var http = require('http');
22

33
http.createServer(function (req, res) {
44
res.setHeader('Content-Type', 'text/html');
5-
if (req.headers.hasOwnProperty('x-forwarded-for')) {
5+
if (req.headers.hasOwnProperty('x-forwarded-for') && req.headers.hasOwnProperty('x-forwarded-proto')) {
66
res.setHeader('x-echo-x-forwarded-for', req.headers['x-forwarded-for']);
7+
res.setHeader('x-echo-x-forwarded-proto', req.headers['x-forwarded-proto']);
78
res.writeHead(200);
8-
res.end('Request contains X-Forwarded-For header');
9+
res.end('Request contains X-Forwarded-For and X-Forwarded-Proto headers');
910
}
1011
else {
1112
res.writeHead(200);
1213
res.end('Request does not contain X-Forwarded-For header');
1314
}
14-
}).listen(process.env.PORT);
15+
}).listen(process.env.PORT);

0 commit comments

Comments
 (0)