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

Method writeFastError

server.go:3082–3103  ·  view source on GitHub ↗
(w io.Writer, statusCode int, msg string)

Source from the content-addressed store, hash-verified

3080}
3081
3082func (s *Server) writeFastError(w io.Writer, statusCode int, msg string) {
3083 w.Write(formatStatusLine(nil, strHTTP11, statusCode, s2b(StatusMessage(statusCode)))) //nolint:errcheck
3084
3085 server := s.getServerName()
3086 if server != "" {
3087 server = fmt.Sprintf("Server: %s\r\n", server)
3088 }
3089 date := ""
3090 if !s.NoDefaultDate {
3091 serverDateOnce.Do(updateServerDate)
3092 date = fmt.Sprintf("Date: %s\r\n", serverDate.Load())
3093 }
3094
3095 fmt.Fprintf(w, "Connection: close\r\n"+
3096 server+
3097 date+
3098 "Content-Type: text/plain\r\n"+
3099 "Content-Length: %d\r\n"+
3100 "\r\n"+
3101 "%s",
3102 len(msg), msg)
3103}
3104
3105func defaultErrorHandler(ctx *RequestCtx, err error) {
3106 if _, ok := err.(*ErrSmallBuffer); ok {

Callers 4

ServeMethod · 0.95
ServeConnMethod · 0.95
TestServerWriteFastErrorFunction · 0.95
wrapPerIPConnFunction · 0.80

Calls 6

getServerNameMethod · 0.95
formatStatusLineFunction · 0.85
StatusMessageFunction · 0.85
s2bFunction · 0.70
WriteMethod · 0.65
DoMethod · 0.65

Tested by 1

TestServerWriteFastErrorFunction · 0.76