From 6374d0e59478191ad1f4ea2a93fd53ff4e4a6fca Mon Sep 17 00:00:00 2001 From: goodhumored Date: Thu, 31 Jul 2025 17:05:53 +0300 Subject: [PATCH] fix: capitalize headers --- lib/needle.js | 80 ++++++++++++++++++------------------ test/basic_auth_spec.js | 30 +++++++------- test/compression_spec.js | 4 +- test/cookies_spec.js | 10 ++--- test/headers_spec.js | 46 ++++++++++----------- test/post_data_spec.js | 82 ++++++++++++++++++------------------- test/proxy_spec.js | 2 +- test/redirect_spec.js | 18 ++++---- test/request_stream_spec.js | 8 ++-- test/utils/proxy.js | 6 +-- 10 files changed, 143 insertions(+), 143 deletions(-) diff --git a/lib/needle.js b/lib/needle.js index e153b92eb..465ed9317 100644 --- a/lib/needle.js +++ b/lib/needle.js @@ -230,21 +230,21 @@ Needle.prototype.setup = function(uri, options) { for (var key in defaults.headers) config.headers[key] = defaults.headers[key]; - config.headers['accept'] = options.accept || defaults.accept; - config.headers['user-agent'] = options.user_agent || defaults.user_agent; + config.headers['Accept'] = options.accept || defaults.accept; + config.headers['User-Agent'] = options.user_agent || defaults.user_agent; if (options.content_type) - config.headers['content-type'] = options.content_type; + config.headers['Content-Type'] = options.content_type; // set connection header if opts.connection was passed, or if node < 0.11.4 (close) if (options.connection || close_by_default) - config.headers['connection'] = options.connection || 'close'; + config.headers['Connection'] = options.connection || 'close'; if ((options.compressed || defaults.compressed) && typeof zlib != 'undefined') - config.headers['accept-encoding'] = decompressors['br'] ? 'gzip, deflate, br' : 'gzip, deflate'; + config.headers['Accept-Encoding'] = decompressors['br'] ? 'gzip, deflate, br' : 'gzip, deflate'; if (options.cookies) - config.headers['cookie'] = cookies.write(options.cookies); + config.headers['Cookie'] = cookies.write(options.cookies); ////////////////////////////////////////////////// // basic/digest auth @@ -259,7 +259,7 @@ Needle.prototype.setup = function(uri, options) { if (options.auth && (options.auth == 'auto' || options.auth == 'digest')) { config.credentials = [options.username, options.password]; } else { - config.headers['authorization'] = auth.basic(options.username, options.password); + config.headers['Authorization'] = auth.basic(options.username, options.password); } } @@ -281,7 +281,7 @@ Needle.prototype.setup = function(uri, options) { } if (options.proxy_user) - config.headers['proxy-authorization'] = auth.basic(options.proxy_user, options.proxy_pass); + config.headers['Proxy-Authorization'] = auth.basic(options.proxy_user, options.proxy_pass); } else { delete config.proxy; } @@ -289,7 +289,7 @@ Needle.prototype.setup = function(uri, options) { // now that all our headers are set, overwrite them if instructed. for (var h in options.headers) - config.headers[h.toLowerCase()] = options.headers[h]; + config.headers[h] = options.headers[h]; config.uri_modifier = get_option('uri_modifier', null); @@ -312,7 +312,7 @@ Needle.prototype.start = function() { var self = this, body, waiting = false, config = this.setup(uri, options); // unless options.json was set to false, assume boss also wants JSON if content-type matches. - var json = options.json || (options.json !== false && config.headers['content-type'] == 'application/json'); + var json = options.json || (options.json !== false && config.headers['Content-Type'] == 'application/json'); if (data) { @@ -323,7 +323,7 @@ Needle.prototype.start = function() { multipart.build(data, boundary, function(err, parts) { if (err) throw(err); - config.headers['content-type'] = 'multipart/form-data; boundary=' + boundary; + config.headers['Content-Type'] = 'multipart/form-data; boundary=' + boundary; next(parts); }); @@ -370,11 +370,11 @@ Needle.prototype.start = function() { function next(body) { if (body) { - if (body.length) config.headers['content-length'] = body.length; + if (body.length) config.headers['Content-Length'] = body.length; // if no content-type was passed, determine if json or not. - if (!config.headers['content-type']) { - config.headers['content-type'] = json + if (!config.headers['Content-Type']) { + config.headers['Content-Type'] = json ? 'application/json; charset=utf-8' : 'application/x-www-form-urlencoded'; // no charset says W3 spec. } @@ -382,7 +382,7 @@ Needle.prototype.start = function() { // unless a specific accept header was set, assume json: true wants JSON back. if (options.json && (!options.accept && !(options.headers || {}).accept)) - config.headers['accept'] = 'application/json'; + config.headers['Accept'] = 'application/json'; self.send_request(1, method, uri, config, body, out, callback); } @@ -403,14 +403,14 @@ Needle.prototype.get_request_opts = function(method, uri, config) { opts.method = method; opts.headers = config.headers; - if (!opts.headers['host']) { + if (!opts.headers['Host']) { // if using proxy, make sure the host header shows the final destination var target = proxy ? url.parse(uri) : remote; - opts.headers['host'] = target.hostname; + opts.headers['Host'] = target.hostname; // and if a non standard port was passed, append it to the port header if (target.port && [80, 443].indexOf(target.port) === -1) { - opts.headers['host'] += ':' + target.port; + opts.headers['Host'] += ':' + target.port; } } @@ -519,59 +519,59 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data, // if we got cookies, parse them unless we were instructed not to. make sure to include any // cookies that might have been set on previous redirects. - if (config.parse_cookies && (headers['set-cookie'] || config.previous_resp_cookies)) { - resp.cookies = extend(config.previous_resp_cookies || {}, cookies.read(headers['set-cookie'])); + if (config.parse_cookies && (headers['Set-Cookie'] || config.previous_resp_cookies)) { + resp.cookies = extend(config.previous_resp_cookies || {}, cookies.read(headers['Set-Cookie'])); debug('Got cookies', resp.cookies); } // if redirect code is found, determine if we should follow it according to the given options. - if (redirect_codes.indexOf(resp.statusCode) !== -1 && self.should_follow(headers.location, config, uri)) { + if (redirect_codes.indexOf(resp.statusCode) !== -1 && self.should_follow(headers['Location'], config, uri)) { // clear timer before following redirects to prevent unexpected setTimeout consequence clearTimeout(timer); if (count <= config.follow_max) { - out.emit('redirect', headers.location); + out.emit('redirect', headers['Location']); // unless 'follow_keep_method' is true, rewrite the request to GET before continuing. if (!config.follow_keep_method) { method = 'GET'; post_data = null; - delete config.headers['content-length']; // in case the original was a multipart POST request. + delete config.headers['Content-Length']; // in case the original was a multipart POST request. } // if follow_set_cookies is true, insert cookies in the next request's headers. // we set both the original request cookies plus any response cookies we might have received. - if (config.follow_set_cookies && utils.host_and_ports_match(headers.location, uri)) { - var request_cookies = cookies.read(config.headers['cookie']); + if (config.follow_set_cookies && utils.host_and_ports_match(headers['Location'], uri)) { + var request_cookies = cookies.read(config.headers['Cookie']); config.previous_resp_cookies = resp.cookies; if (Object.keys(request_cookies).length || Object.keys(resp.cookies || {}).length) { - config.headers['cookie'] = cookies.write(extend(request_cookies, resp.cookies)); + config.headers['Cookie'] = cookies.write(extend(request_cookies, resp.cookies)); } - } else if (config.headers['cookie']) { - debug('Clearing original request cookie', config.headers['cookie']); - delete config.headers['cookie']; + } else if (config.headers['Cookie']) { + debug('Clearing original request cookie', config.headers['Cookie']); + delete config.headers['Cookie']; } if (config.follow_set_referer) - config.headers['referer'] = encodeURI(uri); // the original, not the destination URL. + config.headers['Referer'] = encodeURI(uri); // the original, not the destination URL. - config.headers['host'] = null; // clear previous Host header to avoid conflicts. + config.headers['Host'] = null; // clear previous Host header to avoid conflicts. - var redirect_url = utils.resolve_url(headers.location, uri); + var redirect_url = utils.resolve_url(headers['Location'], uri); debug('Redirecting to ' + redirect_url.toString()); return self.send_request(++count, method, redirect_url.toString(), config, post_data, out, callback); } else if (config.follow_max > 0) { - return done(new Error('Max redirects reached. Possible loop in: ' + headers.location)); + return done(new Error('Max redirects reached. Possible loop in: ' + headers['Location'])); } } // if auth is requested and credentials were not passed, resend request, provided we have user/pass. - if (resp.statusCode == 401 && headers['www-authenticate'] && config.credentials) { - if (!config.headers['authorization']) { // only if authentication hasn't been sent - var auth_header = auth.header(headers['www-authenticate'], config.credentials, request_opts); + if (resp.statusCode == 401 && headers['WWW-Authenticate'] && config.credentials) { + if (!config.headers['Authorization']) { // only if authentication hasn't been sent + var auth_header = auth.header(headers['WWW-Authenticate'], config.credentials, request_opts); if (auth_header) { - config.headers['authorization'] = auth_header; + config.headers['Authorization'] = auth_header; return self.send_request(count, method, uri, config, post_data, out, callback); } } @@ -582,13 +582,13 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data, out.emit('headers', headers); var pipeline = [], - mime = utils.parse_content_type(headers['content-type']), + mime = utils.parse_content_type(headers['Content-Type']), text_response = mime.type && (mime.type.indexOf('text/') != -1 || !!mime.type.match(/(\/|\+)(xml|json)$/)); // To start, if our body is compressed and we're able to inflate it, do it. - if (headers['content-encoding'] && decompressors[headers['content-encoding']]) { + if (headers['Content-Encoding'] && decompressors[headers['Content-Encoding']]) { - var decompressor = decompressors[headers['content-encoding']](); + var decompressor = decompressors[headers['Content-Encoding']](); // make sure we catch errors triggered by the decompressor. decompressor.on('error', had_error); diff --git a/test/basic_auth_spec.js b/test/basic_auth_spec.js index 343f1db0e..542f6cb96 100644 --- a/test/basic_auth_spec.js +++ b/test/basic_auth_spec.js @@ -27,7 +27,7 @@ describe('Basic Auth', function() { it('doesnt send any Authorization headers', function(done) { needle.get('localhost:' + port, { parse: true }, function(err, resp) { var sent_headers = resp.body.headers; - Object.keys(sent_headers).should.not.containEql('authorization'); + Object.keys(sent_headers).should.not.containEql('Authorization'); done(); }) }) @@ -41,7 +41,7 @@ describe('Basic Auth', function() { it('doesnt send any Authorization headers', function(done) { needle.get('localhost:' + port, { parse: true }, function(err, resp) { var sent_headers = resp.body.headers; - Object.keys(sent_headers).should.not.containEql('authorization'); + Object.keys(sent_headers).should.not.containEql('Authorization'); done(); }) }) @@ -55,7 +55,7 @@ describe('Basic Auth', function() { it('sends Authorization header', function(done) { needle.get('localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - Object.keys(sent_headers).should.containEql('authorization'); + Object.keys(sent_headers).should.containEql('Authorization'); done(); }) }) @@ -63,7 +63,7 @@ describe('Basic Auth', function() { it('Basic Auth only includes username, without colon', function(done) { needle.get('localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - var auth = get_auth(sent_headers['authorization']); + var auth = get_auth(sent_headers['Authorization']); auth[0].should.equal('foobar'); auth.should.have.lengthOf(1); done(); @@ -79,7 +79,7 @@ describe('Basic Auth', function() { it('sends Authorization header', function(done) { needle.get('localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - Object.keys(sent_headers).should.containEql('authorization'); + Object.keys(sent_headers).should.containEql('Authorization'); done(); }) }) @@ -87,7 +87,7 @@ describe('Basic Auth', function() { it('Basic Auth only includes both username and password', function(done) { needle.get('localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - var auth = get_auth(sent_headers['authorization']); + var auth = get_auth(sent_headers['Authorization']); auth[0].should.equal('foobar'); auth[1].should.equal(''); done(); @@ -103,7 +103,7 @@ describe('Basic Auth', function() { it('sends Authorization header', function(done) { needle.get('localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - Object.keys(sent_headers).should.containEql('authorization'); + Object.keys(sent_headers).should.containEql('Authorization'); done(); }) }) @@ -111,7 +111,7 @@ describe('Basic Auth', function() { it('Basic Auth only includes both username and password', function(done) { needle.get('localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - var auth = get_auth(sent_headers['authorization']); + var auth = get_auth(sent_headers['Authorization']); auth[0].should.equal('foobar'); auth[1].should.equal(''); auth.should.have.lengthOf(2); @@ -128,7 +128,7 @@ describe('Basic Auth', function() { it('sends Authorization header', function(done) { needle.get('localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - Object.keys(sent_headers).should.containEql('authorization'); + Object.keys(sent_headers).should.containEql('Authorization'); done(); }) }) @@ -136,7 +136,7 @@ describe('Basic Auth', function() { it('Basic Auth only includes both user and password', function(done) { needle.get('localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - var auth = get_auth(sent_headers['authorization']); + var auth = get_auth(sent_headers['Authorization']); auth[0].should.equal('foobar'); auth[1].should.equal('jakub'); auth.should.have.lengthOf(2); @@ -152,7 +152,7 @@ describe('Basic Auth', function() { needle.get(url, {}, function(err, resp) { var sent_headers = resp.body.headers; - Object.keys(sent_headers).should.not.containEql('authorization'); + Object.keys(sent_headers).should.not.containEql('Authorization'); done(); }) }) @@ -162,8 +162,8 @@ describe('Basic Auth', function() { needle.get(url, { username: 'foo' }, function(err, resp) { var sent_headers = resp.body.headers; - Object.keys(sent_headers).should.containEql('authorization'); - sent_headers['authorization'].should.eql('Basic Zm9v') + Object.keys(sent_headers).should.containEql('Authorization'); + sent_headers['Authorization'].should.eql('Basic Zm9v') done(); }) }) @@ -175,7 +175,7 @@ describe('Basic Auth', function() { it('sends Authorization header', function(done) { needle.get('foobar:jakub@localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - Object.keys(sent_headers).should.containEql('authorization'); + Object.keys(sent_headers).should.containEql('Authorization'); done(); }) }) @@ -183,7 +183,7 @@ describe('Basic Auth', function() { it('Basic Auth only includes both user and password', function(done) { needle.get('foobar:jakub@localhost:' + port, opts, function(err, resp) { var sent_headers = resp.body.headers; - var auth = get_auth(sent_headers['authorization']); + var auth = get_auth(sent_headers['Authorization']); auth[0].should.equal('foobar'); auth[1].should.equal('jakub'); auth.should.have.lengthOf(2); diff --git a/test/compression_spec.js b/test/compression_spec.js index 227ae0935..4e941288b 100644 --- a/test/compression_spec.js +++ b/test/compression_spec.js @@ -18,7 +18,7 @@ describe('compression', function(){ server = http.createServer(function(req, res) { var raw = new stream.PassThrough(); - var acceptEncoding = req.headers['accept-encoding']; + var acceptEncoding = req.headers['Accept-Encoding']; if (!acceptEncoding) { acceptEncoding = ''; } @@ -37,7 +37,7 @@ describe('compression', function(){ } res.setHeader('Content-Type', 'application/json') - if (req.headers['with-bad']) { + if (req.headers['With-Bad']) { res.end('foo'); // end, no deflate data } else { raw.end(jsonData) diff --git a/test/cookies_spec.js b/test/cookies_spec.js index 745f4c71f..1f17a03a4 100644 --- a/test/cookies_spec.js +++ b/test/cookies_spec.js @@ -55,7 +55,7 @@ describe('cookies', function() { it('no cookie header is set on request', function(done) { needle.get( 'localhost:' + ALL_COOKIES_TEST_PORT, function(err, response) { - should.not.exist(response.req._headers.cookie); + should.not.exist(response.req._headers['Cookie']); done(); }); }); @@ -158,7 +158,7 @@ describe('cookies', function() { var nextUrl = 'http://' + 'localhost:' + testPort + '/' + (number + 1); if (number == 0) requestCookies = []; // reset - requestCookies.push(req.headers['cookie']); + requestCookies.push(req.headers['Cookie']); if (responseCookies[number]) { // we should send cookies for this request res.statusCode = 302; @@ -336,7 +336,7 @@ describe('cookies', function() { ].join('; ') needle.get('localhost:' + ALL_COOKIES_TEST_PORT, opts, function(error, response) { - var cookieString = response.req._headers.cookie; + var cookieString = response.req._headers['Cookie']; cookieString.should.be.type('string'); cookieString.split(/\s*;\s*/).forEach(function(pair) { @@ -355,7 +355,7 @@ describe('cookies', function() { needle.get('localhost:' + ALL_COOKIES_TEST_PORT, opts, function(error, response) { var cookieObj = {}, - cookieString = response.req._headers.cookie; + cookieString = response.req._headers['Cookie']; cookieString.split(/\s*;\s*/).forEach(function(str) { var pair = COOKIE_PAIR.exec(str); @@ -375,7 +375,7 @@ describe('cookies', function() { needle.get('localhost:' + ALL_COOKIES_TEST_PORT, opts, function(error, response) { var cookieObj = {}, - cookieString = response.req._headers.cookie; + cookieString = response.req._headers['Cookie']; cookieString.split(/\s*;\s*/).forEach(function(str) { var pair = COOKIE_PAIR.exec(str); diff --git a/test/headers_spec.js b/test/headers_spec.js index 5ae62592b..6a37fbddb 100644 --- a/test/headers_spec.js +++ b/test/headers_spec.js @@ -56,7 +56,7 @@ describe('request headers', function() { it('sends a Connection: close header', function(done) { send_request({}, function(err, resp) { - resp.body.headers['connection'].should.eql('close'); + resp.body.headers['Connection'].should.eql('close'); done(); }) }) @@ -75,14 +75,14 @@ describe('request headers', function() { describe('passing connection: close', function() { it('sends a Connection: close header', function(done) { - send_request({ connection: 'close' }, function(err, resp) { - resp.body.headers['connection'].should.eql('close'); + send_request({ Connection: 'close' }, function(err, resp) { + resp.body.headers['Connection'].should.eql('close'); done(); }) }) it('no open sockets remain after request', function(done) { - send_request({ connection: 'close' }, function(err, resp) { + send_request({ Connection: 'close' }, function(err, resp) { setTimeout(function() { get_active_sockets().length.should.eql(existing_sockets); done(); @@ -94,22 +94,22 @@ describe('request headers', function() { describe('passing connection: keep-alive', function() { - it('sends a Connection: keep-alive header (using options.headers.connection)', function(done) { - send_request({ headers: { connection: 'keep-alive' }}, function(err, resp) { - resp.body.headers['connection'].should.eql('keep-alive'); + it('sends a Connection: keep-alive header (using options.headers.Connection)', function(done) { + send_request({ headers: { Connection: 'keep-alive' }}, function(err, resp) { + resp.body.headers['Connection'].should.eql('keep-alive'); done(); }) }) it('sends a Connection: keep-alive header (using options.connection)', function(done) { - send_request({ connection: 'keep-alive' }, function(err, resp) { - resp.body.headers['connection'].should.eql('keep-alive'); + send_request({ Connection: 'keep-alive' }, function(err, resp) { + resp.body.headers['Connection'].should.eql('keep-alive'); done(); }) }) it('one open socket remain after request', function(done) { - send_request({ connection: 'keep-alive' }, function(err, resp) { + send_request({ Connection: 'keep-alive' }, function(err, resp) { get_active_sockets().length.should.eql(existing_sockets + 1); done(); }); @@ -141,7 +141,7 @@ describe('request headers', function() { it('sets Connection header to close (> v4)', function(done) { send_request({}, function(err, resp) { - resp.body.headers['connection'].should.eql('close'); + resp.body.headers['Connection'].should.eql('close'); done() }) }) @@ -150,7 +150,7 @@ describe('request headers', function() { it('sets Connection header to keep-alive (< v4)', function(done) { send_request({}, function(err, resp) { - resp.body.headers['connection'].should.eql('keep-alive'); + resp.body.headers['Connection'].should.eql('keep-alive'); done(); }) }) @@ -193,7 +193,7 @@ describe('request headers', function() { it('sends a Connection: close header', function(done) { send_request({ connection: 'close' }, function(err, resp) { - resp.body.headers['connection'].should.eql('close'); + resp.body.headers['Connection'].should.eql('close'); done(); }) }) @@ -211,16 +211,16 @@ describe('request headers', function() { describe('passing connection: keep-alive', function() { - it('sends a Connection: keep-alive header (using options.headers.connection)', function(done) { - send_request({ headers: { connection: 'keep-alive' }}, function(err, resp) { - resp.body.headers['connection'].should.eql('keep-alive'); + it('sends a Connection: keep-alive header (using options.headers.Connection)', function(done) { + send_request({ headers: { Connection: 'keep-alive' }}, function(err, resp) { + resp.body.headers['Connection'].should.eql('keep-alive'); done(); }) }) it('sends a Connection: keep-alive header (using options.connection)', function(done) { send_request({ connection: 'keep-alive' }, function(err, resp) { - resp.body.headers['connection'].should.eql('keep-alive'); + resp.body.headers['Connection'].should.eql('keep-alive'); done(); }) }) @@ -251,7 +251,7 @@ describe('request headers', function() { it('sends a Connection: keep-alive header', function(done) { send_request({}, function(err, resp) { - resp.body.headers['connection'].should.eql('keep-alive'); + resp.body.headers['Connection'].should.eql('keep-alive'); done(); }) }) @@ -271,7 +271,7 @@ describe('request headers', function() { it('sends a Connection: close header', function(done) { send_request({ connection: 'close' }, function(err, resp) { - resp.body.headers['connection'].should.eql('close'); + resp.body.headers['Connection'].should.eql('close'); done(); }) }) @@ -289,16 +289,16 @@ describe('request headers', function() { describe('passing connection: keep-alive', function() { - it('sends a Connection: keep-alive header (using options.headers.connection)', function(done) { - send_request({ headers: { connection: 'keep-alive' }}, function(err, resp) { - resp.body.headers['connection'].should.eql('keep-alive'); + it('sends a Connection: keep-alive header (using options.headers.Connection)', function(done) { + send_request({ headers: { Connection: 'keep-alive' }}, function(err, resp) { + resp.body.headers['Connection'].should.eql('keep-alive'); done(); }) }) it('sends a Connection: keep-alive header (using options.connection)', function(done) { send_request({ connection: 'keep-alive' }, function(err, resp) { - resp.body.headers['connection'].should.eql('keep-alive'); + resp.body.headers['Connection'].should.eql('keep-alive'); done(); }) }) diff --git a/test/post_data_spec.js b/test/post_data_spec.js index 5c826d67a..b4b3d3951 100644 --- a/test/post_data_spec.js +++ b/test/post_data_spec.js @@ -49,7 +49,7 @@ describe('post data (e.g. request body)', function() { function check_request(method) { stub.calledOnce.should.be.true; - stub.args[0][0]['headers']['host'].should.equal('localhost:4321'); + stub.args[0][0]['headers']['Host'].should.equal('localhost:4321'); stub.args[0][0]['method'].should.equal(method); } @@ -68,7 +68,7 @@ describe('post data (e.g. request body)', function() { it('doesnt set Content-Type header', function(done) { post(null, { multipart: true }, function(err, resp) { - should.not.exist(resp.body.headers['content-type']); + should.not.exist(resp.body.headers['Content-Type']); done(); }) }) @@ -76,7 +76,7 @@ describe('post data (e.g. request body)', function() { it('doesnt change default Accept header', function(done) { post(null, { multipart: true }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -118,14 +118,14 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header', function(done) { post({ foo: 'bar', test: '测试' }, { multipart: true }, function(err, resp) { - resp.body.headers['content-type'].should.equal('multipart/form-data; boundary=--------------------NODENEEDLEHTTPCLIENT'); + resp.body.headers['Content-Type'].should.equal('multipart/form-data; boundary=--------------------NODENEEDLEHTTPCLIENT'); done(); }) }) it('doesnt change default Accept header', function(done) { post({ foo: 'bar', test: '测试' }, { multipart: true }, function(err, resp) { - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -328,7 +328,7 @@ describe('post data (e.g. request body)', function() { it('doesnt set Content-Type header', function(done) { get('foo=bar', { json: false }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - should.not.exist(resp.body.headers['content-type']); + should.not.exist(resp.body.headers['Content-Type']); done(); }) }) @@ -336,7 +336,7 @@ describe('post data (e.g. request body)', function() { it('doesnt change default Accept header', function(done) { get('foo=bar', { json: false }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -365,14 +365,14 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header', function(done) { get('foo=bar', { json: true }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json; charset=utf-8'); + resp.body.headers['Content-Type'].should.equal('application/json; charset=utf-8'); done(); }) }) it('set Accept header to application/json', function(done) { get('foo=bar', { json: true }, function(err, resp) { - resp.body.headers['accept'].should.equal('application/json'); + resp.body.headers['Accept'].should.equal('application/json'); done(); }) }) @@ -405,7 +405,7 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header to www-form-urlencoded', function(done) { post('foo=bar', { json: false }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/x-www-form-urlencoded'); + resp.body.headers['Content-Type'].should.equal('application/x-www-form-urlencoded'); done(); }) }) @@ -413,7 +413,7 @@ describe('post data (e.g. request body)', function() { it('doesnt change default Accept header', function(done) { post('foo=bar', { json: false }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -443,14 +443,14 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header', function(done) { post('foo=bar', { json: true }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json; charset=utf-8'); + resp.body.headers['Content-Type'].should.equal('application/json; charset=utf-8'); done(); }) }) it('set Accept header to application/json', function(done) { post('foo=bar', { json: true }, function(err, resp) { - resp.body.headers['accept'].should.equal('application/json'); + resp.body.headers['Accept'].should.equal('application/json'); done(); }) }) @@ -490,7 +490,7 @@ describe('post data (e.g. request body)', function() { it('doesnt set Content-Type header', function(done) { get({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - should.not.exist(resp.body.headers['content-type']); + should.not.exist(resp.body.headers['Content-Type']); done(); }) }) @@ -498,7 +498,7 @@ describe('post data (e.g. request body)', function() { it('doesnt change default Accept header', function(done) { get({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -527,14 +527,14 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header', function(done) { get({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json; charset=utf-8'); + resp.body.headers['Content-Type'].should.equal('application/json; charset=utf-8'); done(); }) }) it('set Accept header to application/json', function(done) { get({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) { - resp.body.headers['accept'].should.equal('application/json'); + resp.body.headers['Accept'].should.equal('application/json'); done(); }) }) @@ -568,7 +568,7 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header to www-form-urlencoded', function(done) { post({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/x-www-form-urlencoded'); + resp.body.headers['Content-Type'].should.equal('application/x-www-form-urlencoded'); done(); }) }) @@ -576,7 +576,7 @@ describe('post data (e.g. request body)', function() { it('doesnt change default Accept header', function(done) { post({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -608,7 +608,7 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header to application/json', function(done) { post({ foo: 'bar', test: '测试' }, opts, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json'); + resp.body.headers['Content-Type'].should.equal('application/json'); done(); }) }) @@ -616,7 +616,7 @@ describe('post data (e.g. request body)', function() { it('doesnt change default Accept header', function(done) { post({ foo: 'bar', test: '测试' }, opts, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -635,7 +635,7 @@ describe('post data (e.g. request body)', function() { describe('with json: undefined but content-type = application/json', function() { - var opts = { headers: { 'content-type': 'application/json' } }; + var opts = { headers: { 'Content-Type': 'application/json' } }; it('sends request', function(done) { spystub_request(); @@ -648,14 +648,14 @@ describe('post data (e.g. request body)', function() { it('doesnt change Content-Type header', function(done) { post({ foo: 'bar', test: '测试' }, opts, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json'); + resp.body.headers['Content-Type'].should.equal('application/json'); done(); }) }) it('leaves default Accept header', function(done) { post({ foo: 'bar', test: '测试' }, opts, function(err, resp) { - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -684,14 +684,14 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header', function(done) { post({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json; charset=utf-8'); + resp.body.headers['Content-Type'].should.equal('application/json; charset=utf-8'); done(); }) }) it('set Accept header to application/json', function(done) { post({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) { - resp.body.headers['accept'].should.equal('application/json'); + resp.body.headers['Accept'].should.equal('application/json'); done(); }) }) @@ -724,14 +724,14 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header to application/json', function(done) { post({ foo: 'bar', test: '测试' }, opts, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json; charset=utf-8'); + resp.body.headers['Content-Type'].should.equal('application/json; charset=utf-8'); done(); }) }) it('respects Accept header set by user', function(done) { post({ foo: 'bar', test: '测试' }, opts, function(err, resp) { - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -769,8 +769,8 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header', function(done) { get(Buffer.from('foobar'), { json: false }, function(err, resp) { - // should.not.exist(resp.body.headers['content-type']); - resp.body.headers['content-type'].should.equal('application/x-www-form-urlencoded'); + // should.not.exist(resp.body.headers['Content-Type']); + resp.body.headers['Content-Type'].should.equal('application/x-www-form-urlencoded'); done(); }) @@ -779,7 +779,7 @@ describe('post data (e.g. request body)', function() { it('doesnt change default Accept header', function(done) { get(Buffer.from('foobar'), { json: false }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -809,14 +809,14 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header', function(done) { get(Buffer.from('foobar'), { json: true }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json; charset=utf-8'); + resp.body.headers['Content-Type'].should.equal('application/json; charset=utf-8'); done(); }) }) it('set Accept header to application/json', function(done) { get(Buffer.from('foobar'), { json: true }, function(err, resp) { - resp.body.headers['accept'].should.equal('application/json'); + resp.body.headers['Accept'].should.equal('application/json'); done(); }) }) @@ -849,7 +849,7 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header to www-form-urlencoded', function(done) { post(Buffer.from('foobar'), { json: false }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/x-www-form-urlencoded'); + resp.body.headers['Content-Type'].should.equal('application/x-www-form-urlencoded'); done(); }) }) @@ -857,7 +857,7 @@ describe('post data (e.g. request body)', function() { it('doesnt change default Accept header', function(done) { post(Buffer.from('foobar'), { json: false }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -887,14 +887,14 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header', function(done) { post(Buffer.from('foobar'), { json: true }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json; charset=utf-8'); + resp.body.headers['Content-Type'].should.equal('application/json; charset=utf-8'); done(); }) }) it('set Accept header to application/json', function(done) { post(Buffer.from('foobar'), { json: true }, function(err, resp) { - resp.body.headers['accept'].should.equal('application/json'); + resp.body.headers['Accept'].should.equal('application/json'); done(); }) }) @@ -951,7 +951,7 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header to www-form-urlencoded', function(done) { post(input_stream, { json: false }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/x-www-form-urlencoded'); + resp.body.headers['Content-Type'].should.equal('application/x-www-form-urlencoded'); done(); }) }) @@ -959,7 +959,7 @@ describe('post data (e.g. request body)', function() { it('doesnt change default Accept header', function(done) { post(input_stream, { json: false }, function(err, resp) { // resp.body contains 'header' and 'body', mirroring what we sent - resp.body.headers['accept'].should.equal('*/*'); + resp.body.headers['Accept'].should.equal('*/*'); done(); }) }) @@ -989,14 +989,14 @@ describe('post data (e.g. request body)', function() { it('sets Content-Type header', function(done) { post(input_stream, { json: true }, function(err, resp) { - resp.body.headers['content-type'].should.equal('application/json; charset=utf-8'); + resp.body.headers['Content-Type'].should.equal('application/json; charset=utf-8'); done(); }) }) it('set Accept header to application/json', function(done) { post(input_stream, { json: true }, function(err, resp) { - resp.body.headers['accept'].should.equal('application/json'); + resp.body.headers['Accept'].should.equal('application/json'); done(); }) }) diff --git a/test/proxy_spec.js b/test/proxy_spec.js index 46b0b5ec3..a80d8e763 100644 --- a/test/proxy_spec.js +++ b/test/proxy_spec.js @@ -57,7 +57,7 @@ describe('proxy option', function() { function no_proxy_auth(done) { return function(err, resp) { var headers = spy.args[0][0].headers; - Object.keys(headers).should.not.containEql('proxy-authorization'); + Object.keys(headers).should.not.containEql('Proxy-Authorization'); done(); } } diff --git a/test/redirect_spec.js b/test/redirect_spec.js index 5b97c5a8f..7b049740d 100644 --- a/test/redirect_spec.js +++ b/test/redirect_spec.js @@ -265,7 +265,7 @@ describe('redirects', function() { opts.cookies = {foo: 'bar'}; opts.follow_set_cookies = false; send_request(opts, function(err, resp) { - should.not.exist(spies.http.args[0][0].headers['cookie']); + should.not.exist(spies.http.args[0][0].headers['Cookie']); done(); }) }) @@ -274,7 +274,7 @@ describe('redirects', function() { opts.cookies = {foo: 'bar'}; opts.follow_set_cookies = true; send_request(opts, function(err, resp) { - spies.http.args[0][0].headers['cookie'].should.eql('foo=bar') + spies.http.args[0][0].headers['Cookie'].should.eql('foo=bar') done(); }) }) @@ -301,7 +301,7 @@ describe('redirects', function() { it('sets Referer header when following redirect', function(done) { send_request(opts, function(err, resp) { // spies.http.args[0][3].should.eql({ foo: 'bar'}); - spies.http.args[0][0].headers['referer'].should.eql("http://" + host + ":8888/hello"); + spies.http.args[0][0].headers['Referer'].should.eql("http://" + host + ":8888/hello"); done(); }) }) @@ -310,7 +310,7 @@ describe('redirects', function() { opts.cookies = {foo: 'bar'}; opts.follow_set_cookies = false; send_request(opts, function(err, resp) { - should.not.exist(spies.http.args[0][0].headers['cookie']); + should.not.exist(spies.http.args[0][0].headers['Cookie']); done(); }) }) @@ -319,7 +319,7 @@ describe('redirects', function() { opts.cookies = {foo: 'bar'}; opts.follow_set_cookies = true; send_request(opts, function(err, resp) { - spies.http.args[0][0].headers['cookie'].should.eql('foo=bar') + spies.http.args[0][0].headers['Cookie'].should.eql('foo=bar') done(); }) }) @@ -355,7 +355,7 @@ describe('redirects', function() { opts.cookies = {foo: 'bar'}; opts.follow_set_cookies = false; send_request(opts, function(err, resp) { - should.not.exist(spies.http.args[0][0].headers['cookie']); + should.not.exist(spies.http.args[0][0].headers['Cookie']); done(); }) }) @@ -364,7 +364,7 @@ describe('redirects', function() { opts.cookies = {foo: 'bar'}; opts.follow_set_cookies = true; send_request(opts, function(err, resp) { - spies.http.args[0][0].headers['cookie'].should.eql('foo=bar') + spies.http.args[0][0].headers['Cookie'].should.eql('foo=bar') done(); }) }) @@ -391,7 +391,7 @@ describe('redirects', function() { opts.cookies = {foo: 'bar'}; opts.follow_set_cookies = true; send_request(opts, function(err, resp) { - should.not.exist(spies.http.args[0][0].headers['cookie']); + should.not.exist(spies.http.args[0][0].headers['Cookie']); done(); }) }) @@ -434,7 +434,7 @@ describe('redirects', function() { opts.cookies = {foo: 'bar'}; opts.follow_set_cookies = true; send_request(opts, function(err, resp) { - should.not.exist(spies.http.args[0][0].headers['cookie']); + should.not.exist(spies.http.args[0][0].headers['Cookie']); done(); }) }) diff --git a/test/request_stream_spec.js b/test/request_stream_spec.js index 8f375339a..7f681ccda 100644 --- a/test/request_stream_spec.js +++ b/test/request_stream_spec.js @@ -54,7 +54,7 @@ describe('request stream length', function() { it('doesnt set Content-Length header', function(done) { send_request({}, function(err, resp) { - should.not.exist(resp.body.headers['content-length']); + should.not.exist(resp.body.headers['Content-Length']); done() }) }) @@ -73,7 +73,7 @@ describe('request stream length', function() { it('sets Content-Length header to that value', function(done) { send_request({ stream_length: 11 }, function(err, resp) { - resp.body.headers['content-length'].should.eql('11'); + resp.body.headers['Content-Length'].should.eql('11'); done() }) }) @@ -117,7 +117,7 @@ describe('request stream length', function() { it('sets Content-Length header to streams length', function(done) { send_request({ stream_length: 0 }, function(err, resp) { - resp.body.headers['content-length'].should.eql('11'); + resp.body.headers['Content-Length'].should.eql('11'); done() }) }) @@ -145,7 +145,7 @@ describe('request stream length', function() { it('does not set Content-Length header', function(done) { send_request({ stream_length: 0 }, function(err, resp) { - should.not.exist(resp.body.headers['content-length']); + should.not.exist(resp.body.headers['Content-Length']); done() }) }) diff --git a/test/utils/proxy.js b/test/utils/proxy.js index 531bf4935..b5ea4c02d 100644 --- a/test/utils/proxy.js +++ b/test/utils/proxy.js @@ -10,10 +10,10 @@ http.createServer(function(request, response) { console.log(request.headers); console.log("Got request: " + request.url); - console.log("Forwarding request to " + request.headers['host']); + console.log("Forwarding request to " + request.headers['Host']); if (request_auth) { - if (!request.headers['proxy-authorization']) { + if (!request.headers['Proxy-Authorization']) { response.writeHead(407, {'Proxy-Authenticate': 'Basic realm="proxy.com"'}) return response.end('Hello.'); } @@ -23,7 +23,7 @@ http.createServer(function(request, response) { var protocol = remote.protocol == 'https:' ? https : http; var opts = { - host: request.headers['host'], + host: request.headers['Host'], port: remote.port || (remote.protocol == 'https:' ? 443 : 80), method: request.method, path: remote.pathname,