Removed InvalidResponseBody / InvalidStatusCode
Before adoption: this commit came in with the history the project adopted, so no landing records it.
stupid anyway, just dont fuck shit up :)
authored by visionmedia · committed by visionmedia · parent 90de1fa · Browse files · 4 files·+3 added−52 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+3 added−52 removed
- tests:+0 added−25 removed
- other:+3 added−27 removed
Provenance
- Commit
693e374- Tree
ce1c87d- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
90de1fa
4 files changed+3 added−52 removed
modified:lib/express/plugins/common-logger.js-1 removed
43 unmodified lines44454647484849505143 unmodified lines '"' + event.request.method.toUpperCase() + ' ' + (event.request.url.pathname || '/') + ' HTTP/' + event.request.httpVersion + '"', event.request.response.status, event.request.response.headers['content-length'] || 0].join(' ')) callback(); return true; } }})No newline at end of fileNo newline at end of filemodified:lib/express/request.js+3 added-26 removed
10 unmodified lines11 mime = require('express/mime'),12 utils = require('express/utils'),13 url = require('url')14 15-// --- InvalidStatusCode16-17-InvalidStatusCode = ExpressError.extend({18- name: 'InvalidStatusCode',19- init: function(status) {20- this.message = status + ' is an invalid HTTP response code'21- }22-})23-24-// --- InvalidResponseBody25-26-InvalidResponseBody = ExpressError.extend({27- name: 'InvalidResponseBody',28- init: function(request) {29- this.message = request.method + ' ' + JSON.encode(request.url.pathname) + ' did not respond with a body string'30- }31-})32-15 // --- Helpers16 17 /**18 * Normalize the given _path_.123 unmodified lines142 * The status _code_ defaults to to 404, and _body_ will143 * default to the default body associated with the response144 * _code_.145 *164- * When an invalid status _code_ is passed, InvalidStatusCode165- * will be thrown.166- *146 * @param {int} code147 * @param {string} body148 * @param {string} encoding149 * @see statusBodies3 unmodified lines153 halt: function(code, body, encoding, callback) {154 this.status(code = code || 404)155 if (body = body || statusBodies[code])156 return this.respond(body, encoding, callback)178- throw new InvalidStatusCode(code)157 },158 159 /**160 * Respond with _body_ and optional _encoding_.7 unmodified lines168 respond: function(body, encoding, callback) {169 var self = this170 this.response.body = body171 this.trigger('response', null, function(e) {194- if (typeof self.response.body !== 'string')195- return callback(new InvalidResponseBody(self))196- if (typeof self.response.status !== 'number')197- return callback(new InvalidStatusCode(self.response.status))172+ if (e)173+ if (callback !== undefined) callback(e)174+ else throw e175 self.response.writeHeader(self.response.status, self.response.headers)176 self.response.write(self.response.body, encoding)177 self.response.close()178 });88 unmodified linesmodified:spec/spec.request.js-12 removed
105 unmodified lines106 get('/user').status.should.eql 400107 get('/user').body.should.include('Oh noes!')108 end109 end110-111- describe 'when given an invalid status code'112- it 'should throw an InvalidStatusCode exception'113- // TODO: use throw_error when fixed...114- get('/user', function(){ this.halt(123123) })115- try { get('/user') }116- catch (e) {117- e.should.be_an_instance_of ExpressError118- e.should.be_an_instance_of InvalidStatusCode119- }120- end121- end110 end111 112 describe '#contentType()'113 it 'should set Content-Type header with mime type passed'90 unmodified linesmodified:spec/spec.routing.js-13 removed
82 unmodified lines83 get('/foo').body.should.eql 'bar'84 end85 end86 87- describe 'with no response body'88- it 'should throw a InvalidResponseBody'89- // TODO: use throw_error when fixed...90- get('/user', function(){91- this.respond()92- })93- try { get('/user') }94- catch (e) {95- e.should.be_an_instance_of InvalidResponseBody96- }97- end98- end99- 87 describe 'with regular expression'88 it 'should match'89 get(/^\/user\/(\d+)\/(\w+)/, function(id, operation){90 return [id, operation].join(', ')218 unmodified lines