Repository: caddyserver/caddy
File: modules/caddyhttp/reverseproxy/fastcgi/client_test.go (Go)

Code before:

	time.Sleep(250 * time.Millisecond)

	// init
	fcgiParams := make(map[string]string)
	fcgiParams["REQUEST_METHOD"] = "GET"
	fcgiParams["SERVER_PROTOCOL"] = "HTTP/1.1"
	// fcgi_params["GATEWAY_INTERFACE"] = "CGI/1.1"
	fcgiParams["SCRIPT_FILENAME"] = scriptFile

	// simple GET
	log.Println("test:", "get")
	sendFcgi(0, fcgiParams, nil, nil, nil)

	// simple post data
	log.Println("test:", "post")
	sendFcgi(0, fcgiParams, []byte("c4ca4238a0b923820dcc509a6f75849b=1&7b8b965ad4bca0e41ab51de7b31363a1=n"), nil, nil)

	log.Println("test:", "post data (more than 60KB)")
	var data strings.Builder
	for i := 0x00; i < 0xff; i++ {
		v0 := strings.Repeat(fmt.Sprint(i), 256)
		h := md5.New()
		_, _ = io.WriteString(h, v0)
		k0 := fmt.Sprintf("%x", h.Sum(nil))
		data.WriteString(k0 + "=" + url.QueryEscape(v0) + "&")
	}
	sendFcgi(0, fcgiParams, []byte(data.String()), nil, nil)

	log.Println("test:", "post form (use url.Values)")
	p0 := make(map[string]string, 1)
	p0["c4ca4238a0b923820dcc509a6f75849b"] = "1"
	p0["7b8b965ad4bca0e41ab51de7b31363a1"] = "n"
	sendFcgi(1, fcgiParams, nil, p0, nil)

	log.Println("test:", "post forms (256 keys, more than 1MB)")
	p1 := make(map[string]string, 1)
	for i := 0x00; i < 0xff; i++ {
		v0 := strings.Repeat(fmt.Sprint(i), 4096)
		h := md5.New()
		_, _ = io.WriteString(h, v0)
		k0 := fmt.Sprintf("%x", h.Sum(nil))
		p1[k0] = v0
	}
	sendFcgi(1, fcgiParams, nil, p1, nil)

	log.Println("test:", "post file (1 file, 500KB)) ")
	f0 := make(map[string]string, 1)
	path0, m0 := generateRandFile(500000)
	f0[m0] = path0
	sendFcgi(1, fcgiParams, nil, p1, f0)

Review comment (security):
```suggestion
		data.WriteString(k0)
		data.WriteByte('=')
		data.WriteString(url.QueryEscape(v0))
		data.WriteByte('&')
```

But I'm not sure it is worth it to use builders in tests.

Code after:

	time.Sleep(250 * time.Millisecond)

	// init
	fcgiParams := make(map[string]string)
	fcgiParams["REQUEST_METHOD"] = "GET"
	fcgiParams["SERVER_PROTOCOL"] = "HTTP/1.1"
	// fcgi_params["GATEWAY_INTERFACE"] = "CGI/1.1"
	fcgiParams["SCRIPT_FILENAME"] = scriptFile

	// simple GET
	log.Println("test:", "get")
	sendFcgi(0, fcgiParams, nil, nil, nil)

	// simple post data
	log.Println("test:", "post")
	sendFcgi(0, fcgiParams, []byte("c4ca4238a0b923820dcc509a6f75849b=1&7b8b965ad4bca0e41ab51de7b31363a1=n"), nil, nil)

	log.Println("test:", "post data (more than 60KB)")
	data := ""
	for i := 0x00; i < 0xff; i++ {
		v0 := strings.Repeat(fmt.Sprint(i), 256)
		h := md5.New()
		_, _ = io.WriteString(h, v0)
		k0 := fmt.Sprintf("%x", h.Sum(nil))
		data += k0 + "=" + url.QueryEscape(v0) + "&"
	}
	sendFcgi(0, fcgiParams, []byte(data), nil, nil)

	log.Println("test:", "post form (use url.Values)")
	p0 := make(map[string]string, 1)
	p0["c4ca4238a0b923820dcc509a6f75849b"] = "1"
	p0["7b8b965ad4bca0e41ab51de7b31363a1"] = "n"
	sendFcgi(1, fcgiParams, nil, p0, nil)

	log.Println("test:", "post forms (256 keys, more than 1MB)")
	p1 := make(map[string]string, 1)
	for i := 0x00; i < 0xff; i++ {
		v0 := strings.Repeat(fmt.Sprint(i), 4096)
		h := md5.New()
		_, _ = io.WriteString(h, v0)
		k0 := fmt.Sprintf("%x", h.Sum(nil))
		p1[k0] = v0
	}
	sendFcgi(1, fcgiParams, nil, p1, nil)

	log.Println("test:", "post file (1 file, 500KB)) ")
	f0 := make(map[string]string, 1)
	path0, m0 := generateRandFile(500000)
	f0[m0] = path0
	sendFcgi(1, fcgiParams, nil, p1, f0)