mirror of
https://github.com/tailscale/tailscale.git
synced 2025-11-16 10:52:58 +00:00
tsweb: add a Server, which serves HTTP/HTTPS with various good defaults.
Updates #3797 Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
@@ -280,6 +280,7 @@ func (h retHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// response code that gets sent, if any.
|
||||
type loggingResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
ctx context.Context
|
||||
code int
|
||||
bytes int
|
||||
hijacked bool
|
||||
@@ -330,6 +331,20 @@ func (l loggingResponseWriter) Flush() {
|
||||
f.Flush()
|
||||
}
|
||||
|
||||
func (l *loggingResponseWriter) httpCode() int {
|
||||
switch {
|
||||
case l.code != 0:
|
||||
return l.code
|
||||
case l.hijacked:
|
||||
return http.StatusSwitchingProtocols
|
||||
case l.ctx.Err() == context.Canceled:
|
||||
return 499 // nginx convention: Client Closed Request
|
||||
default:
|
||||
// Handler didn't write a body or send a header, that means 200.
|
||||
return 200
|
||||
}
|
||||
}
|
||||
|
||||
// HTTPError is an error with embedded HTTP response information.
|
||||
//
|
||||
// It is the error type to be (optionally) used by Handler.ServeHTTPReturn.
|
||||
|
||||
Reference in New Issue
Block a user