(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler)
| 74 | } |
| 75 | |
| 76 | func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error { |
| 77 | pusher, ok := w.(http.Pusher) |
| 78 | if !ok { |
| 79 | return next.ServeHTTP(w, r) |
| 80 | } |
| 81 | |
| 82 | // short-circuit recursive pushes |
| 83 | if _, ok := r.Header[pushHeader]; ok { |
| 84 | return next.ServeHTTP(w, r) |
| 85 | } |
| 86 | |
| 87 | repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer) |
| 88 | server := r.Context().Value(caddyhttp.ServerCtxKey).(*caddyhttp.Server) |
| 89 | shouldLogCredentials := server.Logs != nil && server.Logs.ShouldLogCredentials |
| 90 | |
| 91 | // create header for push requests |
| 92 | hdr := h.initializePushHeaders(r, repl) |
| 93 | |
| 94 | // push first! |
| 95 | for _, resource := range h.Resources { |
| 96 | if c := h.logger.Check(zapcore.DebugLevel, "pushing resource"); c != nil { |
| 97 | c.Write( |
| 98 | zap.String("uri", r.RequestURI), |
| 99 | zap.String("push_method", resource.Method), |
| 100 | zap.String("push_target", resource.Target), |
| 101 | zap.Object("push_headers", caddyhttp.LoggableHTTPHeader{ |
| 102 | Header: hdr, |
| 103 | ShouldLogCredentials: shouldLogCredentials, |
| 104 | }), |
| 105 | ) |
| 106 | } |
| 107 | err := pusher.Push(repl.ReplaceAll(resource.Target, "."), &http.PushOptions{ |
| 108 | Method: resource.Method, |
| 109 | Header: hdr, |
| 110 | }) |
| 111 | if err != nil { |
| 112 | // usually this means either that push is not |
| 113 | // supported or concurrent streams are full |
| 114 | break |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // wrap the response writer so that we can initiate push of any resources |
| 119 | // described in Link header fields before the response is written |
| 120 | lp := linkPusher{ |
| 121 | ResponseWriterWrapper: &caddyhttp.ResponseWriterWrapper{ResponseWriter: w}, |
| 122 | handler: h, |
| 123 | pusher: pusher, |
| 124 | header: hdr, |
| 125 | request: r, |
| 126 | } |
| 127 | |
| 128 | // serve only after pushing! |
| 129 | if err := next.ServeHTTP(lp, r); err != nil { |
| 130 | return err |
| 131 | } |
| 132 | |
| 133 | return nil |
nothing calls this directly
no test coverage detected