node-XMLHttpRequest icon indicating copy to clipboard operation
node-XMLHttpRequest copied to clipboard

.abort: Don't set headers to default

Open nicjansma opened this issue 9 years ago • 7 comments

In .abort(), we were setting headers to defaultHeaders. This causes a couple problems.

First, this means you can't set the full User-Agent. Since .open() calls this.abort(), User-Agent will be set after the consumer calls xhr.open(...). If the consumer then calls xhr.setRequestHeader("User-Agent", "foo");, the actual User-Agent would end up as node-XMLHttpRequest, foo instead of just foo because setRequestHeader() appends to the existing value (set by .abort()) if it already exists.

The test-headers.js test actually sets user-agent to node-XMLHttpRequest-test and validates this, but it only works because it sets user-agent and not User-Agent. Since .abort() was just calling headers = defaultHeaders without setting headersCase as well, the test headers ended up as:

{
  "User-Agent": "node-XMLHttpRequest",
  "user-agent": "node-XMLHttpRequest-test"
}

Which would send node-XMLHttpRequest-test over the wire since it was last.

To solve this, I think we can simply not set headers = {} in .abort(), as .send() will set the default headers later anyways.

nicjansma avatar Mar 08 '16 18:03 nicjansma

@driverdan Any chance you have time to review these changes?

nicjansma avatar Aug 02 '16 20:08 nicjansma

@driverdan Are you no longer maintaining this project? It would be great to get feedback so others know whether they can expect their PRs to be answered or not.

nicjansma avatar Feb 05 '17 02:02 nicjansma

@driverdan If you don't have time to review PRs and issues, would you consider adding additional collaborators to help review changes?

nicjansma avatar Jul 24 '17 14:07 nicjansma

Would still like to get this merged in

nicjansma avatar Nov 20 '17 02:11 nicjansma

checkout https://www.npmjs.com/package/xmlhttprequest-ts - i added your pull request

hmoog avatar Jun 13 '18 15:06 hmoog

Ping?

nicjansma avatar Jul 01 '18 17:07 nicjansma

Ping...

nicjansma avatar Nov 18 '19 14:11 nicjansma