2022-02-09 01:07:08 -05:00
|
|
|
'use strict'
|
2012-02-07 04:47:51 -08:00
|
|
|
|
|
|
|
|
var express = require('../')
|
2014-03-05 22:06:14 -08:00
|
|
|
, request = require('supertest')
|
2024-12-21 22:58:33 +01:00
|
|
|
, assert = require('node:assert');
|
2012-02-07 04:47:51 -08:00
|
|
|
|
|
|
|
|
describe('req', function(){
|
2012-02-07 08:32:08 -08:00
|
|
|
describe('.get(field)', function(){
|
2012-02-07 04:47:51 -08:00
|
|
|
it('should return the header field value', function(done){
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
|
|
app.use(function(req, res){
|
2012-05-30 14:25:43 -07:00
|
|
|
assert(req.get('Something-Else') === undefined);
|
2012-02-07 08:32:08 -08:00
|
|
|
res.end(req.get('Content-Type'));
|
2012-02-07 04:47:51 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
|
.post('/')
|
|
|
|
|
.set('Content-Type', 'application/json')
|
2012-06-26 17:14:07 -07:00
|
|
|
.expect('application/json', done);
|
2012-02-07 04:47:51 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should special-case Referer', function(done){
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
|
|
app.use(function(req, res){
|
2012-02-07 08:32:08 -08:00
|
|
|
res.end(req.get('Referer'));
|
2012-02-07 04:47:51 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
|
.post('/')
|
|
|
|
|
.set('Referrer', 'http://foobar.com')
|
2012-06-26 17:14:07 -07:00
|
|
|
.expect('http://foobar.com', done);
|
2012-02-07 04:47:51 -08:00
|
|
|
})
|
2016-06-03 00:07:34 -04:00
|
|
|
|
|
|
|
|
it('should throw missing header name', function (done) {
|
|
|
|
|
var app = express()
|
|
|
|
|
|
|
|
|
|
app.use(function (req, res) {
|
|
|
|
|
res.end(req.get())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
|
.get('/')
|
|
|
|
|
.expect(500, /TypeError: name argument is required to req.get/, done)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should throw for non-string header name', function (done) {
|
|
|
|
|
var app = express()
|
|
|
|
|
|
|
|
|
|
app.use(function (req, res) {
|
|
|
|
|
res.end(req.get(42))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
|
.get('/')
|
|
|
|
|
.expect(500, /TypeError: name must be a string to req.get/, done)
|
|
|
|
|
})
|
2012-02-07 04:47:51 -08:00
|
|
|
})
|
2016-06-03 00:07:34 -04:00
|
|
|
})
|