mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-03-21 17:44:58 -05:00
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package nhttp
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
_http "net/http"
|
|
)
|
|
|
|
// unsupportedTEError reports unsupported transfer-encodings.
|
|
type unsupportedTEError struct {
|
|
err string
|
|
}
|
|
|
|
func (uste *unsupportedTEError) Error() string {
|
|
return uste.err
|
|
}
|
|
|
|
// isUnsupportedTEError checks if the error is of type
|
|
// unsupportedTEError. It is usually invoked with a non-nil err.
|
|
func isUnsupportedTEError(err error) bool {
|
|
_, ok := err.(*unsupportedTEError)
|
|
return ok
|
|
}
|
|
|
|
// isCommonNetReadError reports whether err is a common error
|
|
// encountered during reading a request off the network when the
|
|
// client has gone away or had its read fail somehow. This is used to
|
|
// determine which logs are interesting enough to log about.
|
|
func isCommonNetReadError(err error) bool {
|
|
if err == io.EOF {
|
|
return true
|
|
}
|
|
if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
|
|
return true
|
|
}
|
|
if oe, ok := err.(*net.OpError); ok && oe.Op == "read" {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// statusError is an error used to respond to a request with an HTTP status.
|
|
// The text should be plain text without user info or other embedded errors.
|
|
type statusError struct {
|
|
code int
|
|
text string
|
|
}
|
|
|
|
func (e statusError) Error() string { return _http.StatusText(e.code) + ": " + e.text }
|