Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 00de598

Browse files
committed
feat(request): Added raw method to access raw data sent to a given request
_raw data is set on the request using the bodyParser middleware, now added a method to access that value
1 parent a81a4f7 commit 00de598

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Request/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ class Request {
123123
return nodeReq.post(this.request) || {}
124124
}
125125

126+
raw () {
127+
return this._raw
128+
}
129+
126130
/**
127131
* @description returns header value for a given key
128132
* @method header

test/unit/request.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ describe('Request', function () {
9595
expect(res.body.body).deep.equal({})
9696
})
9797

98+
it('should return raw object attached to request using raw method', function * () {
99+
const server = http.createServer(function (req, res) {
100+
const request = new Request(req, res, Config)
101+
request._raw = {foo: 'bar'}
102+
const raw = request.raw()
103+
res.writeHead(200, {"Content-type":"application/json"})
104+
res.end(JSON.stringify({raw}),'utf8')
105+
})
106+
107+
const res = yield supertest(server).get("/").expect(200).end()
108+
expect(res.body.raw).to.be.an('object')
109+
expect(res.body.raw).deep.equal({foo: 'bar'})
110+
})
111+
98112
it('should get value for a given key using input method', function * () {
99113
const server = http.createServer(function (req, res) {
100114
const request = new Request(req, res, Config)

0 commit comments

Comments
 (0)