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

Function TestServerHeadRequest

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

Source from the content-addressed store, hash-verified

1990}
1991
1992func TestServerHeadRequest(t *testing.T) {
1993 t.Parallel()
1994
1995 s := &Server{
1996 Handler: func(ctx *RequestCtx) {
1997 fmt.Fprintf(ctx, "Request method is %q", ctx.Method())
1998 ctx.SetContentType("aaa/bbb")
1999 },
2000 }
2001
2002 rw := &readWriter{}
2003 rw.r.WriteString("HEAD /foobar HTTP/1.1\r\nHost: aaa.com\r\n\r\n")
2004
2005 if err := s.ServeConn(rw); err != nil {
2006 t.Fatalf("Unexpected error from serveConn: %v", err)
2007 }
2008
2009 br := bufio.NewReader(&rw.w)
2010 var resp Response
2011 resp.SkipBody = true
2012 if err := resp.Read(br); err != nil {
2013 t.Fatalf("Unexpected error when parsing response: %v", err)
2014 }
2015 if resp.Header.StatusCode() != StatusOK {
2016 t.Fatalf("unexpected status code: %d. Expecting %d", resp.Header.StatusCode(), StatusOK)
2017 }
2018 if len(resp.Body()) > 0 {
2019 t.Fatalf("Unexpected non-zero body %q", resp.Body())
2020 }
2021 if resp.Header.ContentLength() != 24 {
2022 t.Fatalf("unexpected content-length %d. Expecting %d", resp.Header.ContentLength(), 24)
2023 }
2024 if string(resp.Header.ContentType()) != "aaa/bbb" {
2025 t.Fatalf("unexpected content-type %q. Expecting %q", resp.Header.ContentType(), "aaa/bbb")
2026 }
2027
2028 data, err := io.ReadAll(br)
2029 if err != nil {
2030 t.Fatalf("Unexpected error when reading remaining data: %v", err)
2031 }
2032 if len(data) > 0 {
2033 t.Fatalf("unexpected remaining data %q", data)
2034 }
2035}
2036
2037func TestServerRejectsBackslashInAbsoluteURI(t *testing.T) {
2038 t.Parallel()

Callers

nothing calls this directly

Calls 10

ServeConnMethod · 0.95
ReadMethod · 0.95
BodyMethod · 0.95
NewReaderMethod · 0.80
ContentLengthMethod · 0.65
MethodMethod · 0.45
SetContentTypeMethod · 0.45
WriteStringMethod · 0.45
StatusCodeMethod · 0.45
ContentTypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…