@@ -138,9 +138,12 @@ func init() {
138
138
var tests = []Test {
139
139
Test {"GET" , "/" , "" , 200 , "index" },
140
140
Test {"GET" , "/echo/hello" , "" , 200 , "hello" },
141
+ Test {"GET" , "/echo/hello" , "" , 200 , "hello" },
141
142
Test {"GET" , "/multiecho/a/b/c/d" , "" , 200 , "abcd" },
142
143
Test {"POST" , "/post/echo/hello" , "" , 200 , "hello" },
144
+ Test {"POST" , "/post/echo/hello" , "" , 200 , "hello" },
143
145
Test {"POST" , "/post/echoparam/a" , "a=hello" , 200 , "hello" },
146
+ Test {"POST" , "/post/echoparam/a" , "a=hello\x00 " , 200 , "hello\x00 " },
144
147
//long url
145
148
Test {"GET" , "/echo/" + strings .Repeat ("0123456789" , 100 ), "" , 200 , strings .Repeat ("0123456789" , 100 )},
146
149
@@ -195,8 +198,8 @@ func TestRouting(t *testing.T) {
195
198
}
196
199
}
197
200
198
- func buildScgiFields (fields map [string ]string ) []byte {
199
- var buf bytes. Buffer
201
+ func buildScgiFields (fields map [string ]string , buf * bytes. Buffer ) []byte {
202
+
200
203
for k , v := range (fields ) {
201
204
buf .WriteString (k )
202
205
buf .Write ([]byte {0 })
@@ -208,34 +211,40 @@ func buildScgiFields(fields map[string]string) []byte {
208
211
}
209
212
210
213
func buildTestScgiRequest (method string , path string , body string , headers map [string ]string ) * bytes.Buffer {
214
+
215
+ var hbuf bytes.Buffer
211
216
scgiHeaders := make (map [string ]string )
212
217
218
+ hbuf .WriteString ("CONTENT_LENGTH" )
219
+ hbuf .Write ([]byte {0 })
220
+ hbuf .WriteString (fmt .Sprintf ("%d" , len (body )))
221
+ hbuf .Write ([]byte {0 })
222
+
213
223
scgiHeaders ["REQUEST_METHOD" ] = method
214
224
scgiHeaders ["HTTP_HOST" ] = "127.0.0.1"
215
225
scgiHeaders ["REQUEST_URI" ] = path
216
226
scgiHeaders ["SERVER_PORT" ] = "80"
217
227
scgiHeaders ["SERVER_PROTOCOL" ] = "HTTP/1.1"
218
228
scgiHeaders ["USER_AGENT" ] = "web.go test framework"
219
229
230
+ buildScgiFields (scgiHeaders , & hbuf )
231
+
220
232
if method == "POST" {
221
233
headers ["Content-Length" ] = fmt .Sprintf ("%d" , len (body ))
222
234
headers ["Content-Type" ] = "text/plain"
223
235
}
224
236
225
- f1 := buildScgiFields (scgiHeaders )
226
- fields := f1
227
-
228
237
if len (headers ) > 0 {
229
- f2 := buildScgiFields (headers )
230
- fields = bytes .Join ([][]byte {f1 , f2 }, []byte {})
238
+ buildScgiFields (headers , & hbuf )
231
239
}
232
-
233
- var buf bytes.Buffer
234
-
235
- //comma at the end
236
- clen := len (fields ) + len (body ) + 1
237
- fmt .Fprintf (& buf , "%d:" , clen )
238
- buf .Write (fields )
240
+
241
+ fielddata := hbuf .Bytes ()
242
+ var buf bytes.Buffer ;
243
+
244
+ //extra 1 is for the comma at the end
245
+ dlen := len (fielddata ) + len (body ) + 1
246
+ fmt .Fprintf (& buf , "%d:" , dlen )
247
+ buf .Write (fielddata )
239
248
buf .WriteString ("," )
240
249
buf .WriteString (body )
241
250
@@ -289,17 +298,20 @@ func buildTestFcgiRequest(method string, path string, bodychunks []string, heade
289
298
var req bytes.Buffer
290
299
fcgiHeaders := make (map [string ]string )
291
300
301
+ bodylength := 0
302
+ for _ , s := range (bodychunks ) {
303
+ bodylength += len (s )
304
+ }
305
+
306
+ fcgiHeaders ["CONTENT_LENGTH" ] = fmt .Sprintf ("%d" , bodylength )
292
307
fcgiHeaders ["REQUEST_METHOD" ] = method
293
308
fcgiHeaders ["HTTP_HOST" ] = "127.0.0.1"
294
309
fcgiHeaders ["REQUEST_URI" ] = path
295
310
fcgiHeaders ["SERVER_PORT" ] = "80"
296
311
fcgiHeaders ["SERVER_PROTOCOL" ] = "HTTP/1.1"
297
312
fcgiHeaders ["USER_AGENT" ] = "web.go test framework"
298
313
299
- bodylength := 0
300
- for _ , s := range (bodychunks ) {
301
- bodylength += len (s )
302
- }
314
+
303
315
304
316
if method == "POST" {
305
317
fcgiHeaders ["Content-Length" ] = fmt .Sprintf ("%d" , bodylength )
0 commit comments