@@ -81,50 +81,56 @@ class Server extends Base {
8181 }
8282 res . end ( ) ;
8383 } else if ( req . method === 'POST' ) {
84- res . setHeader ( 'Content-Type' , req . headers [ 'content-type' ] ) ;
85- var chunks = [ ] , gunzip ;
86- if ( compress && req . headers [ 'content-encoding' ] === 'gzip' ) {
87- gunzip = new compress . Gunzip ( ) ;
88- gunzip . init ( ) ;
89- }
90- req . on ( 'data' , function ( chunk ) {
91- if ( gunzip )
92- chunk = gunzip . inflate ( chunk , 'binary' ) ;
93- chunks . push ( chunk ) ;
94- } ) ;
95- req . on ( 'end' , function ( ) {
96- var xml = chunks . join ( '' ) ;
97- var result ;
98- var error ;
99- if ( gunzip ) {
100- gunzip . end ( ) ;
101- gunzip = null ;
84+ if ( ! req . headers [ 'content-type' ] ) {
85+ res . statusCode = 415 ;
86+ res . write ( 'The Content-Type is expected in the headers' ) ;
87+ res . end ( ) ;
88+ } else {
89+ res . setHeader ( 'Content-Type' , req . headers [ 'content-type' ] ) ;
90+ var chunks = [ ] , gunzip ;
91+ if ( compress && req . headers [ 'content-encoding' ] === 'gzip' ) {
92+ gunzip = new compress . Gunzip ( ) ;
93+ gunzip . init ( ) ;
10294 }
103- try {
104- if ( typeof self . log === 'function' ) {
105- self . log ( 'received' , xml ) ;
95+ req . on ( 'data' , function ( chunk ) {
96+ if ( gunzip )
97+ chunk = gunzip . inflate ( chunk , 'binary' ) ;
98+ chunks . push ( chunk ) ;
99+ } ) ;
100+ req . on ( 'end' , function ( ) {
101+ var xml = chunks . join ( '' ) ;
102+ var result ;
103+ var error ;
104+ if ( gunzip ) {
105+ gunzip . end ( ) ;
106+ gunzip = null ;
106107 }
107- self . _process ( xml , req , function ( result , statusCode ) {
108- if ( statusCode ) {
109- res . statusCode = statusCode ;
108+ try {
109+ if ( typeof self . log === 'function' ) {
110+ self . log ( 'received' , xml ) ;
110111 }
111- res . write ( result ) ;
112+ self . _process ( xml , req , function ( result , statusCode ) {
113+ if ( statusCode ) {
114+ res . statusCode = statusCode ;
115+ }
116+ res . write ( result ) ;
117+ res . end ( ) ;
118+ if ( typeof self . log === 'function' ) {
119+ self . log ( 'replied' , result ) ;
120+ }
121+ } ) ;
122+ }
123+ catch ( err ) {
124+ error = err . stack || err ;
125+ res . statusCode = 500 ;
126+ res . write ( error ) ;
112127 res . end ( ) ;
113128 if ( typeof self . log === 'function' ) {
114- self . log ( 'replied ' , result ) ;
129+ self . log ( 'error ' , error ) ;
115130 }
116- } ) ;
117- }
118- catch ( err ) {
119- error = err . stack || err ;
120- res . statusCode = 500 ;
121- res . write ( error ) ;
122- res . end ( ) ;
123- if ( typeof self . log === 'function' ) {
124- self . log ( 'error' , error ) ;
125131 }
126- }
127- } ) ;
132+ } ) ;
133+ }
128134 }
129135 else {
130136 res . end ( ) ;
0 commit comments