Skip to content

Commit cbb82b5

Browse files
committed
lex/httplex, http/httpguts: merge the httplex package into httpguts
httplex was the original package name for shared code between net/http and x/net/http2, but its name was too specific, and http/httpguts was added later for other shared code. We discussed merging httplex into httpguts at the time, but it didn't happen earlier. This finishes the move. Updates golang/go#23908 Change-Id: Ic7d6f39e584ca579d34b5ef5ec6a0c002a38a83c Reviewed-on: https://go-review.googlesource.com/111875 Reviewed-by: Andrew Bonventre <andybons@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
1 parent 403019b commit cbb82b5

File tree

6 files changed

+15
-20
lines changed

6 files changed

+15
-20
lines changed

lex/httplex/httplex.go http/httpguts/httplex.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// Package httplex contains rules around lexical matters of various
6-
// HTTP-related specifications.
7-
//
8-
// This package is shared by the standard library (which vendors it)
9-
// and x/net/http2. It comes with no API stability promise.
10-
package httplex
5+
package httpguts
116

127
import (
138
"net"

lex/httplex/httplex_test.go http/httpguts/httplex_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package httplex
5+
package httpguts
66

77
import (
88
"testing"

http2/frame.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"strings"
1515
"sync"
1616

17+
"golang.org/x/net/http/httpguts"
1718
"golang.org/x/net/http2/hpack"
18-
"golang.org/x/net/lex/httplex"
1919
)
2020

2121
const frameHeaderLen = 9
@@ -1462,7 +1462,7 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
14621462
if VerboseLogs && fr.logReads {
14631463
fr.debugReadLoggerf("http2: decoded hpack field %+v", hf)
14641464
}
1465-
if !httplex.ValidHeaderFieldValue(hf.Value) {
1465+
if !httpguts.ValidHeaderFieldValue(hf.Value) {
14661466
invalid = headerFieldValueError(hf.Value)
14671467
}
14681468
isPseudo := strings.HasPrefix(hf.Name, ":")

http2/http2.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"strings"
3030
"sync"
3131

32-
"golang.org/x/net/lex/httplex"
32+
"golang.org/x/net/http/httpguts"
3333
)
3434

3535
var (
@@ -179,7 +179,7 @@ var (
179179
)
180180

181181
// validWireHeaderFieldName reports whether v is a valid header field
182-
// name (key). See httplex.ValidHeaderName for the base rules.
182+
// name (key). See httpguts.ValidHeaderName for the base rules.
183183
//
184184
// Further, http2 says:
185185
// "Just as in HTTP/1.x, header field names are strings of ASCII
@@ -191,7 +191,7 @@ func validWireHeaderFieldName(v string) bool {
191191
return false
192192
}
193193
for _, r := range v {
194-
if !httplex.IsTokenRune(r) {
194+
if !httpguts.IsTokenRune(r) {
195195
return false
196196
}
197197
if 'A' <= r && r <= 'Z' {

http2/transport.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727
"sync"
2828
"time"
2929

30+
"golang.org/x/net/http/httpguts"
3031
"golang.org/x/net/http2/hpack"
3132
"golang.org/x/net/idna"
32-
"golang.org/x/net/lex/httplex"
3333
)
3434

3535
const (
@@ -1181,7 +1181,7 @@ func (cc *ClientConn) encodeHeaders(req *http.Request, addGzipHeader bool, trail
11811181
if host == "" {
11821182
host = req.URL.Host
11831183
}
1184-
host, err := httplex.PunycodeHostPort(host)
1184+
host, err := httpguts.PunycodeHostPort(host)
11851185
if err != nil {
11861186
return nil, err
11871187
}
@@ -1206,11 +1206,11 @@ func (cc *ClientConn) encodeHeaders(req *http.Request, addGzipHeader bool, trail
12061206
// potentially pollute our hpack state. (We want to be able to
12071207
// continue to reuse the hpack encoder for future requests)
12081208
for k, vv := range req.Header {
1209-
if !httplex.ValidHeaderFieldName(k) {
1209+
if !httpguts.ValidHeaderFieldName(k) {
12101210
return nil, fmt.Errorf("invalid HTTP header name %q", k)
12111211
}
12121212
for _, v := range vv {
1213-
if !httplex.ValidHeaderFieldValue(v) {
1213+
if !httpguts.ValidHeaderFieldValue(v) {
12141214
return nil, fmt.Errorf("invalid HTTP header value %q for header %q", v, k)
12151215
}
12161216
}
@@ -2251,7 +2251,7 @@ func (t *Transport) getBodyWriterState(cs *clientStream, body io.Reader) (s body
22512251
}
22522252
s.delay = t.expectContinueTimeout()
22532253
if s.delay == 0 ||
2254-
!httplex.HeaderValuesContainsToken(
2254+
!httpguts.HeaderValuesContainsToken(
22552255
cs.req.Header["Expect"],
22562256
"100-continue") {
22572257
return
@@ -2306,5 +2306,5 @@ func (s bodyWriterState) scheduleBodyWrite() {
23062306
// isConnectionCloseRequest reports whether req should use its own
23072307
// connection for a single request and then close the connection.
23082308
func isConnectionCloseRequest(req *http.Request) bool {
2309-
return req.Close || httplex.HeaderValuesContainsToken(req.Header["Connection"], "close")
2309+
return req.Close || httpguts.HeaderValuesContainsToken(req.Header["Connection"], "close")
23102310
}

http2/write.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"net/http"
1212
"net/url"
1313

14+
"golang.org/x/net/http/httpguts"
1415
"golang.org/x/net/http2/hpack"
15-
"golang.org/x/net/lex/httplex"
1616
)
1717

1818
// writeFramer is implemented by any type that is used to write frames.
@@ -350,7 +350,7 @@ func encodeHeaders(enc *hpack.Encoder, h http.Header, keys []string) {
350350
}
351351
isTE := k == "transfer-encoding"
352352
for _, v := range vv {
353-
if !httplex.ValidHeaderFieldValue(v) {
353+
if !httpguts.ValidHeaderFieldValue(v) {
354354
// TODO: return an error? golang.org/issue/14048
355355
// For now just omit it.
356356
continue

0 commit comments

Comments
 (0)