Skip to content

Commit 179e0cb

Browse files
committed
fix #131: correct handling of empty http request headers
1 parent 2676e57 commit 179e0cb

File tree

5 files changed

+77
-19
lines changed

5 files changed

+77
-19
lines changed

Diff for: src/iisnode/chttpprotocol.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ HRESULT CHttpProtocol::Append(IHttpContext* context, const char* content, DWORD
5050
{
5151
HRESULT hr;
5252

53-
if (contentLength == 0)
53+
if (contentLength == 0 && NULL != content)
5454
{
5555
contentLength = strlen(content);
5656
}
@@ -75,8 +75,11 @@ HRESULT CHttpProtocol::Append(IHttpContext* context, const char* content, DWORD
7575
*bufferLength = newBufferLength;
7676
}
7777

78-
memcpy((char*)*buffer + *offset, content, contentLength);
79-
*offset += contentLength;
78+
if (contentLength > 0)
79+
{
80+
memcpy((char*)*buffer + *offset, content, contentLength);
81+
*offset += contentLength;
82+
}
8083

8184
return S_OK;
8285
Error:

Diff for: test/functional/tests/115_customheaders.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Custom request and response headers are processed correctly
3+
*/
4+
5+
var iisnodeassert = require("iisnodeassert");
6+
7+
iisnodeassert.sequence([
8+
iisnodeassert.post(10000, "/115_customheaders/hello.js", { headers: { 'x-foo': 'foobar'} }, 200, "Hello, world", { 'x-bar': 'foobar', 'x-got-foo': 'true' }),
9+
iisnodeassert.post(2000, "/115_customheaders/hello.js", { headers: { 'x-foo': ''} }, 200, "Hello, world", { 'x-bar': '', 'x-got-foo': 'true' }),
10+
iisnodeassert.post(2000, "/115_customheaders/hello.js", { headers: { 'x-foo': '', 'x-baz': 'foobar' } }, 200, "Hello, world", { 'x-bar': '', 'x-got-foo': 'true' })
11+
]);

Diff for: test/functional/tests/node_modules/iisnodeassert.js

+41-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: test/functional/www/115_customheaders/hello.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var http = require('http');
2+
3+
http.createServer(function (req, res) {
4+
console.log(JSON.stringify(req.headers));
5+
res.setHeader('Content-Type', 'text/html');
6+
if (req.headers.hasOwnProperty('x-foo')) {
7+
res.setHeader('x-bar', req.headers['x-foo']);
8+
res.setHeader('x-got-foo', 'true');
9+
}
10+
res.writeHead(200);
11+
res.end('Hello, world');
12+
}).listen(process.env.PORT);

Diff for: test/functional/www/115_customheaders/web.config

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<configuration>
2+
<system.webServer>
3+
<handlers>
4+
<add name="iisnode" path="hello.js" verb="*" modules="iisnode" />
5+
</handlers>
6+
</system.webServer>
7+
</configuration>

0 commit comments

Comments
 (0)