This pull request is to replace #260 (#260)
It contains the same changes + TESTS:
1. Set the connection header only if not already set by the target server.
2. Copy response headers case-insensitively
In addition it contains another fix:
support unix domain sockets and windows named pipes (socketPath) - This was transparent in node 0.6.x by using port for named pipe, but in node 0.8.x it should be passed explicitly.
- support unix donain sockets and windows named pipes (socketPath) on…
… node 0.8.x. On node 0.6.x the support was opaque via port, but on the new node, socketPath should be set explicitely.
- avoid adding multiple headers with the same name
- fix bug in setting connection
Add tests for headers bug fixes
Doing a copy of headers on every request isn't a good thing to do - I'm worried about memory usage. Can you explain exactly why is it needed (an example would be appreciated)? Test case doesn't tell me much.
If response headers are copied using the res.writeHead() function, then the copy is case sensitive. It means that eventually we may have two headers with same name but different casing, for example: x-My-Header: "a", x-my-header: "b", and then it is unpredictable which value will be taken by the client, and doesn't meet HTTP standard.
HTTP headers are case insensitive, so the copy needs to be done with res.setHeader(), which overrides existing headers case-insensitively.
I don't see a difference in mem usage as in one case we copy all the headers at once, and in another case we copy them one by one.
I would even say the opposite - if you use the current implementation you'll use more memory.
If I have "myheader: x", and then I get a request with "MYHEADER: y", then I'll end up with two headers. And same thing if I get another header "MyHeader: z", and "MyHeAdEr: a" and so on...
But - if I copy them with setHeader() then the headers will be overridden and I will have only one header with the same name.
@gilad61 @mmalecki This is a subtle but good fix; we should be setting header names consistently. res._renderHeaders() is still case sensitive even in the latest stable versions of node:
I spoke with @isaacs, this behavior is not going to change even in 0.10.0, but likely in 0.12.0. So going to pull this in if all the tests pass.