MCPcopy Index your code
hub / github.com/tailscale/tailscale / ServeHTTP

Method ServeHTTP

tsweb/tsweb.go:751–779  ·  view source on GitHub ↗

ServeHTTP implements the http.Handler interface.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

749
750// ServeHTTP implements the http.Handler interface.
751func (h errorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
752 // Keep track of whether a response gets written.
753 lw, ok := w.(*loggingResponseWriter)
754 if !ok {
755 lw = newLogResponseWriter(h.opts.Logf, w, r)
756 }
757
758 var err error
759 defer func() {
760 // In case the handler panics, we want to recover and continue logging
761 // the error before logging it (or re-panicking if we couldn't log).
762 rec := recover()
763 if rec != nil {
764 err = panic2err(rec)
765 }
766 if err == nil {
767 return
768 }
769 if h.handleError(w, r, lw, err) {
770 return
771 }
772 if rec != nil {
773 // If we weren't able to log the panic somewhere, throw it up the
774 // stack to someone who can.
775 panic(rec)
776 }
777 }()
778 err = h.rh.ServeHTTPReturn(lw, r)
779}
780
781func (h errorHandler) handleError(w http.ResponseWriter, r *http.Request, lw *loggingResponseWriter, err error) bool {
782 var logged bool

Callers

nothing calls this directly

Calls 4

handleErrorMethod · 0.95
newLogResponseWriterFunction · 0.85
panic2errFunction · 0.85
ServeHTTPReturnMethod · 0.65

Tested by

no test coverage detected