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

Function TestServerWriteFastError

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

Source from the content-addressed store, hash-verified

1087}
1088
1089func TestServerWriteFastError(t *testing.T) {
1090 t.Parallel()
1091
1092 s := &Server{
1093 Name: "foobar",
1094 }
1095 var buf bytes.Buffer
1096 expectedBody := "access denied"
1097 s.writeFastError(&buf, StatusForbidden, expectedBody)
1098
1099 br := bufio.NewReader(&buf)
1100 var resp Response
1101 if err := resp.Read(br); err != nil {
1102 t.Fatalf("unexpected error: %v", err)
1103 }
1104 if resp.StatusCode() != StatusForbidden {
1105 t.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode(), StatusForbidden)
1106 }
1107 body := resp.Body()
1108 if string(body) != expectedBody {
1109 t.Fatalf("unexpected body: %q. Expecting %q", body, expectedBody)
1110 }
1111 server := string(resp.Header.Server())
1112 if server != s.Name {
1113 t.Fatalf("unexpected server: %q. Expecting %q", server, s.Name)
1114 }
1115 contentType := string(resp.Header.ContentType())
1116 if contentType != "text/plain" {
1117 t.Fatalf("unexpected content-type: %q. Expecting %q", contentType, "text/plain")
1118 }
1119 if !resp.Header.ConnectionClose() {
1120 t.Fatal("expecting 'Connection: close' response header")
1121 }
1122}
1123
1124func TestServerTLS(t *testing.T) {
1125 t.Parallel()

Callers

nothing calls this directly

Calls 8

writeFastErrorMethod · 0.95
ReadMethod · 0.95
StatusCodeMethod · 0.95
BodyMethod · 0.95
NewReaderMethod · 0.80
ServerMethod · 0.80
ContentTypeMethod · 0.45
ConnectionCloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…