MCPcopy
hub / github.com/valyala/fasthttp / TestServerMultipartFormDataRequest

Function TestServerMultipartFormDataRequest

server_test.go:1444–1575  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1442}
1443
1444func TestServerMultipartFormDataRequest(t *testing.T) {
1445 t.Parallel()
1446
1447 for _, test := range []struct {
1448 StreamRequestBody bool
1449 DisablePreParseMultipartForm bool
1450 }{
1451 {StreamRequestBody: false, DisablePreParseMultipartForm: false},
1452 {StreamRequestBody: false, DisablePreParseMultipartForm: true},
1453 {StreamRequestBody: true, DisablePreParseMultipartForm: false},
1454 {StreamRequestBody: true, DisablePreParseMultipartForm: true},
1455 } {
1456 b := strings.ReplaceAll(`------WebKitFormBoundaryJwfATyF8tmxSJnLg
1457Content-Disposition: form-data; name="f1"
1458
1459value1
1460------WebKitFormBoundaryJwfATyF8tmxSJnLg
1461Content-Disposition: form-data; name="fileaaa"; filename="TODO"
1462Content-Type: application/octet-stream
1463
1464- SessionClient with referer and cookies support.
1465- Client with requests' pipelining support.
1466- ProxyHandler similar to FSHandler.
1467- WebSockets. See https://tools.ietf.org/html/rfc6455 .
1468- HTTP/2.0. See https://tools.ietf.org/html/rfc7540 .
1469
1470------WebKitFormBoundaryJwfATyF8tmxSJnLg--
1471`, "\n", "\r\n")
1472
1473 reqS := fmt.Sprintf(strings.ReplaceAll(`POST /upload HTTP/1.1
1474Host: qwerty.com
1475Content-Length: %d
1476Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryJwfATyF8tmxSJnLg
1477
1478%s
1479
1480GET / HTTP/1.1
1481Host: asbd
1482Connection: close
1483
1484`, "\n", "\r\n"), len(b), b)
1485
1486 ln := fasthttputil.NewInmemoryListener()
1487
1488 s := &Server{
1489 StreamRequestBody: test.StreamRequestBody,
1490 DisablePreParseMultipartForm: test.DisablePreParseMultipartForm,
1491 Handler: func(ctx *RequestCtx) {
1492 switch string(ctx.Path()) {
1493 case "/upload":
1494 f, err := ctx.MultipartForm()
1495 if err != nil {
1496 t.Errorf("unexpected error: %v", err)
1497 }
1498 if len(f.Value) != 1 {
1499 t.Errorf("unexpected values %d. Expecting %d", len(f.Value), 1)
1500 }
1501 if len(f.File) != 1 {

Callers

nothing calls this directly

Calls 15

ServeMethod · 0.95
DialMethod · 0.95
ReadMethod · 0.95
StatusCodeMethod · 0.95
BodyMethod · 0.95
CloseMethod · 0.95
NewInmemoryListenerFunction · 0.92
FormValueMethod · 0.80
RedirectMethod · 0.80
NewReaderMethod · 0.80
WriteMethod · 0.65
PeekMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…