aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/request.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2020-04-30 09:03:55 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2020-05-01 05:30:49 +0000
commitb8fd3cab3944d5dd5f2a50f3cc131b1048897ee1 (patch)
tree048d5c6acfed8c3a7204540fc9ad225c079ea0e5 /src/net/http/request.go
parente1d16843bdbf85c99bc963b7a343cbffa047e378 (diff)
downloadgo-b8fd3cab3944d5dd5f2a50f3cc131b1048897ee1.tar.gz
go-b8fd3cab3944d5dd5f2a50f3cc131b1048897ee1.zip
net/http: remove badStringError, make some unexported structs non-comparable
Reduces binary size by 4K, not counting the http2 changes (in CL 231119) that'll be bundled into this package in the future. Updates golang/go#38782 Change-Id: Id360348707e076b8310a8f409e412d68dd2394b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/231118 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/http/request.go')
-rw-r--r--src/net/http/request.go13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/net/http/request.go b/src/net/http/request.go
index 88fa0939f2..e386f13a37 100644
--- a/src/net/http/request.go
+++ b/src/net/http/request.go
@@ -83,12 +83,7 @@ var (
ErrMissingContentLength = &ProtocolError{"missing ContentLength in HEAD response"}
)
-type badStringError struct {
- what string
- str string
-}
-
-func (e *badStringError) Error() string { return fmt.Sprintf("%s %q", e.what, e.str) }
+func badStringError(what, val string) error { return fmt.Errorf("%s %q", what, val) }
// Headers that Request.Write handles itself and should be skipped.
var reqWriteExcludeHeader = map[string]bool{
@@ -1025,14 +1020,14 @@ func readRequest(b *bufio.Reader, deleteHostHeader bool) (req *Request, err erro
var ok bool
req.Method, req.RequestURI, req.Proto, ok = parseRequestLine(s)
if !ok {
- return nil, &badStringError{"malformed HTTP request", s}
+ return nil, badStringError("malformed HTTP request", s)
}
if !validMethod(req.Method) {
- return nil, &badStringError{"invalid method", req.Method}
+ return nil, badStringError("invalid method", req.Method)
}
rawurl := req.RequestURI
if req.ProtoMajor, req.ProtoMinor, ok = ParseHTTPVersion(req.Proto); !ok {
- return nil, &badStringError{"malformed HTTP version", req.Proto}
+ return nil, badStringError("malformed HTTP version", req.Proto)
}
// CONNECT requests are used two different ways, and neither uses a full URL: