Skip to content

Commit

Permalink
merge upstream net/http: 2024-09-10(ad6ee2)
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Sep 11, 2024
1 parent 551b96d commit 5c12b05
Show file tree
Hide file tree
Showing 3 changed files with 349 additions and 257 deletions.
10 changes: 8 additions & 2 deletions internal/transport/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package transport
import (
"context"
"crypto/tls"
"github.com/imroc/req/v3/internal/dump"
"net"
"net/http"
"net/url"
"time"

"github.com/imroc/req/v3/internal/dump"
)

// Options is transport's options.
Expand All @@ -17,8 +18,13 @@ type Options struct {
// request is aborted with the provided error.
//
// The proxy type is determined by the URL scheme. "http",
// "https", and "socks5" are supported. If the scheme is empty,
// "https", "socks5", and "socks5h" are supported. If the scheme is empty,
// "http" is assumed.
// "socks5" is treated the same as "socks5h".
//
// If the proxy URL contains a userinfo subcomponent,
// the proxy request will pass the username and password
// in a Proxy-Authorization header.
//
// If Proxy is nil or returns a nil *URL, no proxy is used.
Proxy func(*http.Request) (*url.URL, error)
Expand Down
10 changes: 5 additions & 5 deletions transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"net/http"
"net/textproto"
"reflect"
"sort"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -281,7 +281,7 @@ func (t *transferWriter) writeHeader(writeHeader func(key string, values ...stri
keys = append(keys, k)
}
if len(keys) > 0 {
sort.Strings(keys)
slices.Sort(keys)
// TODO: could do better allocation-wise here, but trailers are rare,
// so being lazy for now.
err := writeHeader("Trailer", strings.Join(keys, ","))
Expand Down Expand Up @@ -973,7 +973,7 @@ func (bl bodyLocked) Read(p []byte) (n int, err error) {
return bl.b.readLocked(p)
}

var laxContentLength = godebug.New("httplaxcontentlength")
var httplaxContentLength = godebug.New("httplaxcontentlength")

// parseContentLength checks that the header is valid and then trims
// whitespace. It returns -1 if no value is set otherwise the value
Expand All @@ -987,8 +987,8 @@ func parseContentLength(clHeaders []string) (int64, error) {
// The Content-Length must be a valid numeric value.
// See: https://datatracker.ietf.org/doc/html/rfc2616/#section-14.13
if cl == "" {
if laxContentLength.Value() == "1" {
laxContentLength.IncNonDefault()
if httplaxContentLength.Value() == "1" {
httplaxContentLength.IncNonDefault()
return -1, nil
}
return 0, badStringError("invalid empty Content-Length", cl)
Expand Down
Loading

0 comments on commit 5c12b05

Please sign in to comment.