Upgrade net package from Go 1.21.4 to Go 1.26.2

Backport upstream Go standard library changes to TinyGo's net package.

Unmodified files (18) replaced directly from Go 1.26.2 source.
Modified files (22) merged via 3-way diff, preserving all TinyGo
netdev adaptations, TINYGO markers, and embedded-device constraints.

Notable upstream changes included:
- net/http: cookie handling improvements, fs enhancements,
  reverse proxy updates, chunked encoding fixes
- net/http: ServeMux routing and pattern matching updates
- net: IP parsing and MAC address handling improvements
- Various doc link syntax modernization (e.g. [Dial], [Buffers])

TinyGo-only files (netdev.go, tlssock.go) unchanged.
All TINYGO comment markers preserved.
This commit is contained in:
deadprogram
2026-04-13 17:36:35 +02:00
committed by Ron Evans
parent a3417d034f
commit 35e809e0e5
46 changed files with 1580 additions and 779 deletions
+16 -6
View File
@@ -8,13 +8,19 @@ package httptest
import (
"bufio"
"bytes"
"context"
"io"
"net/http"
"strings"
)
// NewRequest returns a new incoming server Request, suitable
// for passing to an http.Handler for testing.
// NewRequest wraps NewRequestWithContext using context.Background.
func NewRequest(method, target string, body io.Reader) *http.Request {
return NewRequestWithContext(context.Background(), method, target, body)
}
// NewRequestWithContext returns a new incoming server Request, suitable
// for passing to an [http.Handler] for testing.
//
// The target is the RFC 7230 "request-target": it may be either a
// path or an absolute URL. If target is an absolute URL, the host name
@@ -27,16 +33,16 @@ import (
//
// An empty method means "GET".
//
// The provided body may be nil. If the body is of type *bytes.Reader,
// *strings.Reader, or *bytes.Buffer, the Request.ContentLength is
// set.
// The provided body may be nil. If the body is of type [bytes.Reader],
// [strings.Reader], [bytes.Buffer], or the value [http.NoBody],
// the Request.ContentLength is set.
//
// NewRequest panics on error for ease of use in testing, where a
// panic is acceptable.
//
// To generate a client HTTP request instead of a server request, see
// the NewRequest function in the net/http package.
func NewRequest(method, target string, body io.Reader) *http.Request {
func NewRequestWithContext(ctx context.Context, method, target string, body io.Reader) *http.Request {
if method == "" {
method = "GET"
}
@@ -44,6 +50,7 @@ func NewRequest(method, target string, body io.Reader) *http.Request {
if err != nil {
panic("invalid NewRequest arguments; " + err.Error())
}
req = req.WithContext(ctx)
// HTTP/1.0 was used above to avoid needing a Host field. Change it to 1.1 here.
req.Proto = "HTTP/1.1"
@@ -61,6 +68,9 @@ func NewRequest(method, target string, body io.Reader) *http.Request {
default:
req.ContentLength = -1
}
if body == http.NoBody {
req.ContentLength = 0
}
if rc, ok := body.(io.ReadCloser); ok {
req.Body = rc
} else {