@@ -34,19 +34,12 @@ var OBJECT_TSV = require(path.join(__dirname, '/files/object-tsv.json'));
3434
3535describe ( 'fielded text parser' , function ( ) {
3636
37- before ( function ( done ) {
37+ beforeEach ( function ( done ) {
3838 SERVER = restify . createServer ( {
3939 dtrace : helper . dtrace ,
4040 log : helper . getLog ( 'server' )
4141 } ) ;
4242 SERVER . use ( plugins . bodyParser ( ) ) ;
43- SERVER . post ( '/data' , function respond ( req , res , next ) {
44- res . send ( {
45- status : 'okay' ,
46- parsedReq : req . body
47- } ) ;
48- return next ( ) ;
49- } ) ;
5043 SERVER . listen ( PORT , '127.0.0.1' , function ( ) {
5144 CLIENT = restifyClients . createClient ( {
5245 url : 'http://127.0.0.1:' + PORT ,
@@ -57,7 +50,7 @@ describe('fielded text parser', function () {
5750 } ) ;
5851 } ) ;
5952
60- after ( function ( done ) {
53+ afterEach ( function ( done ) {
6154 CLIENT . close ( ) ;
6255 SERVER . close ( done ) ;
6356 } ) ;
@@ -70,6 +63,15 @@ describe('fielded text parser', function () {
7063 'Content-Type' : 'text/csv'
7164 }
7265 } ;
66+
67+ SERVER . post ( '/data' , function respond ( req , res , next ) {
68+ res . send ( {
69+ status : 'okay' ,
70+ parsedReq : req . body
71+ } ) ;
72+ return next ( ) ;
73+ } ) ;
74+
7375 CLIENT . post ( options , function ( err , req ) {
7476 assert . ifError ( err ) ;
7577 req . on ( 'result' , function ( errReq , res ) {
@@ -99,6 +101,15 @@ describe('fielded text parser', function () {
99101 'Content-Type' : 'text/tsv'
100102 }
101103 } ;
104+
105+ SERVER . post ( '/data' , function respond ( req , res , next ) {
106+ res . send ( {
107+ status : 'okay' ,
108+ parsedReq : req . body
109+ } ) ;
110+ return next ( ) ;
111+ } ) ;
112+
102113 CLIENT . post ( options , function ( err , req ) {
103114 assert . ifError ( err ) ;
104115 req . on ( 'result' , function ( errReq , res ) {
@@ -121,5 +132,35 @@ describe('fielded text parser', function () {
121132 } ) ;
122133 } ) ;
123134
135+ it ( 'plugins-GH-6: should expose rawBody on request' , function ( done ) {
136+ var options = {
137+ path : '/data' ,
138+ headers : {
139+ 'Content-Type' : 'text/csv'
140+ }
141+ } ;
142+
143+ SERVER . post ( '/data' , function respond ( req , res , next ) {
144+ assert . ok ( req . rawBody ) ;
145+ res . send ( ) ;
146+ return next ( ) ;
147+ } ) ;
148+
149+ CLIENT . post ( options , function ( err , req ) {
150+ assert . ifError ( err ) ;
151+ req . on ( 'result' , function ( errReq , res ) {
152+ assert . ifError ( errReq ) ;
153+ res . body = '' ;
154+ res . setEncoding ( 'utf8' ) ;
155+ res . on ( 'data' , function ( chunk ) {
156+ res . body += chunk ;
157+ } ) ;
158+ res . on ( 'end' , done ) ;
159+ } ) ;
160+ req . write ( DATA_TSV ) ;
161+ req . end ( ) ;
162+ } ) ;
163+ } ) ;
164+
124165} ) ;
125166
0 commit comments