Skip to content
Myr

added accepts support for media groups

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Example: this.accepts('html') will now return true when Accepts header contains 'text/*'. Support for */* was not added since it seems a bit too blunt in the real world.

authored by Aaron Heckmann · committed by Aaron Heckmann · parent fbd9cdd · Browse files · 2 files+14 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−1 removed

  • tests:+11 added−0 removed
  • other:+3 added−1 removed

2 files+14 added−1 removed

modified:lib/express/request.js+3 added-1 removed
125 unmodified lines
126 accepts: function() {127 var accept = this.header('accept')128 return accept ? 129 $(arguments).any(function(path){130 return accept.indexOf(mime.type(path)) !== -1130 var type = mime.type(path)131 return accept.indexOf(type) !== -1 ||132 accept.indexOf(type.split('/')[0]+'/*') !== -1133 }) :134 true135 },136
131 unmodified lines
modified:spec/spec.request.js+11 added
68 unmodified lines
69 get('/user', function(){ return this.accepts('jpeg', 'png').toString() })70 get('/user', { headers: { accept: 'text/plain,text/html' }}).body.should.eql 'false'71 end72 end73 74 describe 'when a media type range was sent'75 it 'should return true if the group media type matches'76 get('/user', function(){ return this.accepts('html').toString() })77 get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'true'78 end79 it 'should return false if the group media type does not match'80 get('/user', function(){ return this.accepts('ogg').toString() })81 get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'false'82 end83 end84 end85 86 describe '#halt()'87 describe 'when given no arguments'
128 unmodified lines