Normalized header conventions.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
For example use Content-Type instead of content-type, Request#header() lowercases when reading a header, however does not when writing.
authored by visionmedia · committed by visionmedia · parent f76092e · Browse files · 15 files·+39 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
15 files+39 added−39 removed
- tests:+20 added−20 removed
- other:+19 added−19 removed
Provenance
- Commit
2e3f806- Tree
a7c446b- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
f76092e
15 files changed+39 added−39 removed
modified:lib/express/plugins/body-decoder.js+2 added-2 removed
18 unmodified lines19202122232423242526272818 unmodified lines */ request: function(event) { var request = event.request if (request.header('content-type') && request.header('content-type').includes('application/x-www-form-urlencoded')) if (request.header('Content-Type') && request.header('Content-Type').includes('application/x-www-form-urlencoded')) request.params.post = queryString.parseQuery(request.body) } }})No newline at end of fileNo newline at end of filemodified:lib/express/plugins/content-length.js+2 added-2 removed
9 unmodified lines10111213141514151617189 unmodified lines response: function(event) { var response = event.request.response if (!response.chunkedEncoding) if (!response.headers['content-length'] && response.body) response.headers['content-length'] = response.body.length if (!response.headers['Content-Length'] && response.body) response.headers['Content-Length'] = response.body.length } }})No newline at end of fileNo newline at end of filemodified:lib/express/plugins/cookie.js+1 added-1 removed
106 unmodified linesExpand all107108109110111111112113114106 unmodified linesExpand all response: function(event) { if (event.response.cookies && event.response.cookies.length) event.request.header('set-cookie', event.response.cookies.join('\nset-cookie: ')) event.request.header('Set-Cookie', event.response.cookies.join('\nSet-Cookie: ')) } }})No newline at end of fileNo newline at end of filemodified:lib/express/plugins/redirect.js+2 added-2 removed
39 unmodified lines40 */41 42 redirect: function(url, code) {43 if (url === 'back' || url === 'home') url = this[url]44- this.header('location', url)44+ this.header('Location', url)45 this.halt(code || 303)46 } 47 })48 }9 unmodified lines58 */59 60 request: function(event) {61 event.request.home = set('home') || set('basepath') || '/'62- event.request.back = event.request.header('referrer') || event.request.header('referer')62+ event.request.back = event.request.header('Referrer') || event.request.header('Referer')63 }64 }65 })modified:lib/express/plugins/static.js+4 added-4 removed
64 unmodified lines65 return 'errno' in err && err.errno === 266 ? self.notFound()67 : self.error(err)68 var etag = stat.ino + '-' + stat.size + '-' + Number(stat.mtime)69- if (self.header('if-none-match') && 70- self.header('if-none-match') == etag)69+ if (self.header('If-None-Match') && 70+ self.header('If-None-Match') == etag)71 return self.halt(304, null)72- self.header('content-length', stat.size)73- self.header('etag', etag)72+ self.header('Content-Length', stat.size)73+ self.header('ETag', etag)74 self.stream(fs.createReadStream(path, options))75 })76 return this77 },20 unmodified linesmodified:lib/express/core.js+3 added-3 removed
224 unmodified lines225 request.error(err)226 else if (!pendingFiles)227 self.route(request)228 }229- if (request.header('content-type') &&230- request.header('content-type').includes('multipart/form-data')) {229+ if (request.header('Content-Type') &&230+ request.header('Content-Type').includes('multipart/form-data')) {231 var stream,232- contentLength = parseInt(request.header('content-length')),232+ contentLength = parseInt(request.header('Content-Length')),233 maxBodyLength = set('max upload size')234 if (maxBodyLength && contentLength > maxBodyLength)235 return callback(new Error('upload size limit exceeded'))236 stream = multipart.parse(req)98 unmodified linesmodified:lib/express/http.js+2 added-2 removed
37 unmodified lines38 data = queryString.stringify(data)39 if (method === 'GET')40 search += (search ? '&' : '?') + data41 else42- headers['content-length'] = data.length,43- headers['content-type'] = 'application/x-www-form-urlencoded'42+ headers['Content-Length'] = data.length,43+ headers['Content-Type'] = 'application/x-www-form-urlencoded'44 }45 var req = client.request(method, path + search + hash, headers)46 if (data && method !== 'GET') req.write(data)47 req.addListener('response', function(res){45 unmodified linesmodified:lib/express/request.js+3 added-3 removed
72 unmodified lines73 74 header: function(key, val) {75 return val === undefined76 ? this.headers[key.lowercase]77- : this.response.headers[key.lowercase] = val77+ : this.response.headers[key] = val78 },79 80 /**81 * Return the param _key_ value or undefined.197 unmodified lines279 * @api public280 */281 282 contentType: function(path) {283- this.header('content-type', mime.type(path))283+ this.header('Content-Type', mime.type(path))284 return this285 },286 287 /**41 unmodified lines329 * @api public330 */331 332 attachment: function(filename) {333- this.header('content-disposition', filename333+ this.header('Content-Disposition', filename334 ? 'attachment; filename="' + filename + '"'335 : 'attachment')336 return this337 },72 unmodified linesmodified:spec/spec.plugins.content-length.js+3 added-3 removed
10 unmodified lines11 it 'should set the content-length header'12 get('/style.css', function(){13 return 'body { background: #000; }'14 })15- get('/style.css').headers['content-length'].should.eql 2615+ get('/style.css').headers['Content-Length'].should.eql 2616 end17 18 it 'should not override when manually set'19 get('/style.css', function(){20- this.header('content-length', 10)20+ this.header('Content-Length', 10)21 return 'body { background: #000; }'22 })23- get('/style.css').headers['content-length'].should.eql 1023+ get('/style.css').headers['Content-Length'].should.eql 1024 end25 end26 end27 end1 unmodified linemodified:spec/spec.plugins.cookie.js+2 added-2 removed
71 unmodified lines72 get('/user', function(){73 this.cookie('SID', '732423sdfs73243', { path: '/', secure: true })74 return '' 75 })76- get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/; secure'76+ get('/user').headers['Set-Cookie'].should.eql 'SID=732423sdfs73243; path=/; secure'77 end78 79 it 'should set multiple cookies'80 get('/user', function(){81 this.cookie('SID', '732423sdfs73243', { path: '/', secure: true })82 this.cookie('foo', 'bar')83 return '' 84 })85- get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/; secure\nset-cookie: foo=bar; path=/'85+ get('/user').headers['Set-Cookie'].should.eql 'SID=732423sdfs73243; path=/; secure\nSet-Cookie: foo=bar; path=/'86 end87 end88 end89 11 unmodified linesmodified:spec/spec.plugins.js+1 added-1 removed
7 unmodified lines8 }9 },10 on: {11 response: function(event) {12- if (event.response.headers['content-type'] == mime.type('css'))12+ if (event.response.headers['Content-Type'] === mime.type('css'))13 event.response.body = event.response.body.replace('black', '#000')14 }15 }16 })25 unmodified linesmodified:spec/spec.plugins.redirect.js+7 added-7 removed
10 unmodified lines11 get('/logout', function(){12 this.redirect('/')13 })14 get('/logout').status.should.eql 30315- get('/logout').headers['location'].should.eql '/'15+ get('/logout').headers['Location'].should.eql '/'16 end17 18 it 'should allow optional status code'19 get('/logout', function(){20 this.redirect('/', 304)21 })22 get('/logout').status.should.eql 30423- get('/logout').headers['location'].should.eql '/'23+ get('/logout').headers['Location'].should.eql '/'24 end25 end26 27 describe 'redirect("back")'1 unmodified line29 get('/logout', function(){30 this.redirect('back')31 })32 var response = get('/logout', { headers: { referrer: '/login' }})33- response.headers['location'].should.eql '/login'33+ response.headers['Location'].should.eql '/login'34 end35 36 it 'should check referer header'37 get('/logout', function(){38 this.redirect('back')39 })40 var response = get('/logout', { headers: { referer: '/login' }})41- response.headers['location'].should.eql '/login'41+ response.headers['Location'].should.eql '/login'42 end43 end44 45 describe 'redirect(home)'1 unmodified line47 set('home', '/login')48 get('/logout', function(){49 this.redirect('home')50 })51- get('/logout').headers['location'].should.eql '/login'51+ get('/logout').headers['Location'].should.eql '/login'52 end53 54 it 'should check set("basepath")'55 set('basepath', '/web/')56 get('/logout', function(){57 this.redirect('home')58 })59- get('/logout').headers['location'].should.eql '/web/'59+ get('/logout').headers['Location'].should.eql '/web/'60 end61 62 it 'should default to "/"'63 get('/logout', function(){64 this.redirect('home')65 })66- get('/logout').headers['location'].should.eql '/'66+ get('/logout').headers['Location'].should.eql '/'67 end68 end69 end70 endmodified:spec/spec.plugins.session.js+3 added-3 removed
10 unmodified lines11 describe 'Session'12 describe 'when sid cookie is not present'13 it 'should set sid cookie'14 get('/login', function(){ return '' })15- get('/login').headers['set-cookie'].should.match(/^sid=(\w+);/)15+ get('/login').headers['Set-Cookie'].should.match(/^sid=(\w+);/)16 end17 end18 19 describe 'when existing sid cookie is present'20 it 'should not set sid'21 Session.store.commit(new Base(123))22 get('/login', function(){ return '' })23- get('/login', { headers: { cookie: 'sid=123' }}).headers.should.not.have_property 'set-cookie'23+ get('/login', { headers: { cookie: 'sid=123' }}).headers.should.not.have_property 'Set-Cookie'24 end25 end26 27 describe 'when unknown sid cookie is present'28 it 'should set new sid'29 get('/login', function(){ return '' })30 var headers= get('/login', { headers: { cookie: 'sid=123' }}).headers31 32- headers.should.have_property 'set-cookie'32+ headers.should.have_property 'Set-Cookie'33 headers['set-cookie'].should.not.be '123'34 end35 end 36 97 unmodified linesmodified:spec/spec.plugins.view.js+1 added-1 removed
109 unmodified lines110 it 'should set the content type based on the last path segment'111 get('/', function(){112 this.render('hello.html.haml')113 })114- get('/').headers['content-type'].should.eql 'text/html'114+ get('/').headers['Content-Type'].should.eql 'text/html'115 end116 end117 118 describe 'and layout of the same type does not exist'86 unmodified linesmodified:spec/spec.request.js+3 added-3 removed
130 unmodified lines131 get('/style.css', function(){132 this.contentType('css')133 return 'body { background: white; }'134 })135- get('/style.css').headers['content-type'].should.eql 'text/css'135+ get('/style.css').headers['Content-Type'].should.eql 'text/css'136 end137 end138 139 describe '#attachment()'1 unmodified line141 get('/report', function(){142 this.attachment()143 return 'foo'144 })145- get('/report').headers['content-disposition'].should.eql 'attachment'145+ get('/report').headers['Content-Disposition'].should.eql 'attachment'146 end147 148 it 'should set attachment filename'149 get('/report', function(){150 this.attachment('report.pdf')151 return 'foo'152 })153- get('/report').headers['content-disposition'].should.eql 'attachment; filename="report.pdf"'153+ get('/report').headers['Content-Disposition'].should.eql 'attachment; filename="report.pdf"'154 end155 end156 157 describe '#param()'212 unmodified lines