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

Function TestRequestCtxSendFileNotModified

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

Source from the content-addressed store, hash-verified

3038}
3039
3040func TestRequestCtxSendFileNotModified(t *testing.T) {
3041 t.Parallel()
3042
3043 var ctx RequestCtx
3044 var req Request
3045 ctx.Init(&req, nil, defaultLogger)
3046
3047 filePath := "./server_test.go"
3048 lastModified, err := FileLastModified(filePath)
3049 if err != nil {
3050 t.Fatalf("unexpected error: %v", err)
3051 }
3052 ctx.Request.Header.Set("If-Modified-Since", string(AppendHTTPDate(nil, lastModified)))
3053
3054 ctx.SendFile(filePath)
3055
3056 s := ctx.Response.String()
3057
3058 var resp Response
3059 br := bufio.NewReader(bytes.NewBufferString(s))
3060 if err := resp.Read(br); err != nil {
3061 t.Fatalf("error when reading response: %v", err)
3062 }
3063 if resp.StatusCode() != StatusNotModified {
3064 t.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode(), StatusNotModified)
3065 }
3066 if len(resp.Body()) > 0 {
3067 t.Fatalf("unexpected non-zero response body: %q", resp.Body())
3068 }
3069}
3070
3071func TestRequestCtxSendFileModified(t *testing.T) {
3072 t.Parallel()

Callers

nothing calls this directly

Calls 10

InitMethod · 0.95
SendFileMethod · 0.95
ReadMethod · 0.95
StatusCodeMethod · 0.95
BodyMethod · 0.95
FileLastModifiedFunction · 0.85
AppendHTTPDateFunction · 0.85
NewReaderMethod · 0.80
SetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…