Skip to content
Myr

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

15 files+39 added−39 removed

modified:lib/express/plugins/body-decoder.js+2 added-2 removed
modified:lib/express/plugins/content-length.js+2 added-2 removed
modified:lib/express/plugins/cookie.js+1 added-1 removed
modified:lib/express/plugins/redirect.js+2 added-2 removed
39 unmodified lines
40 */4142 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 lines
58 */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 lines
65 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 lines
modified:lib/express/core.js+3 added-3 removed
224 unmodified lines
225 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 lines
modified:lib/express/http.js+2 added-2 removed
37 unmodified lines
38 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 lines
modified:lib/express/request.js+3 added-3 removed
72 unmodified lines
7374 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 lines
279 * @api public280 */281282 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 lines
329 * @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 lines
modified:spec/spec.plugins.content-length.js+3 added-3 removed
10 unmodified lines
11 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 end
1 unmodified line
modified:spec/spec.plugins.cookie.js+2 added-2 removed
71 unmodified lines
72 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 lines
modified:spec/spec.plugins.js+1 added-1 removed
7 unmodified lines
8 }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 lines
modified:spec/spec.plugins.redirect.js+7 added-7 removed
10 unmodified lines
11 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 line
29 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 line
47 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 end70end
modified:spec/spec.plugins.session.js+3 added-3 removed
10 unmodified lines
11 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 end1819 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 lines
modified:spec/spec.plugins.view.js+1 added-1 removed
109 unmodified lines
110 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 lines
modified:spec/spec.request.js+3 added-3 removed
130 unmodified lines
131 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 line
141 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 end147148 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 end156157 describe '#param()'
212 unmodified lines