mirror of
https://github.com/tinygo-org/net.git
synced 2026-08-18 19:43:57 +00:00
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:
+17
-19
@@ -1,6 +1,4 @@
|
||||
// TINYGO: The following is copied from Go 1.21.5 official implementation.
|
||||
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// TINYGO: The following is copied from Go 1.26.2 official implementation.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
@@ -35,7 +33,7 @@ var errClosed = errors.New("i/o operation on closed connection")
|
||||
// It is low-level, old, and unused by Go's current HTTP stack.
|
||||
// We should have deleted it before Go 1.
|
||||
//
|
||||
// Deprecated: Use the Server in package net/http instead.
|
||||
// Deprecated: Use the Server in package [net/http] instead.
|
||||
type ServerConn struct {
|
||||
mu sync.Mutex // read-write protects the following fields
|
||||
c net.Conn
|
||||
@@ -52,7 +50,7 @@ type ServerConn struct {
|
||||
// It is low-level, old, and unused by Go's current HTTP stack.
|
||||
// We should have deleted it before Go 1.
|
||||
//
|
||||
// Deprecated: Use the Server in package net/http instead.
|
||||
// Deprecated: Use the Server in package [net/http] instead.
|
||||
func NewServerConn(c net.Conn, r *bufio.Reader) *ServerConn {
|
||||
if r == nil {
|
||||
r = bufio.NewReader(c)
|
||||
@@ -60,10 +58,10 @@ func NewServerConn(c net.Conn, r *bufio.Reader) *ServerConn {
|
||||
return &ServerConn{c: c, r: r, pipereq: make(map[*http.Request]uint)}
|
||||
}
|
||||
|
||||
// Hijack detaches the ServerConn and returns the underlying connection as well
|
||||
// Hijack detaches the [ServerConn] and returns the underlying connection as well
|
||||
// as the read-side bufio which may have some left over data. Hijack may be
|
||||
// called before Read has signaled the end of the keep-alive logic. The user
|
||||
// should not call Hijack while Read or Write is in progress.
|
||||
// should not call Hijack while [ServerConn.Read] or [ServerConn.Write] is in progress.
|
||||
func (sc *ServerConn) Hijack() (net.Conn, *bufio.Reader) {
|
||||
sc.mu.Lock()
|
||||
defer sc.mu.Unlock()
|
||||
@@ -74,7 +72,7 @@ func (sc *ServerConn) Hijack() (net.Conn, *bufio.Reader) {
|
||||
return c, r
|
||||
}
|
||||
|
||||
// Close calls Hijack and then also closes the underlying connection.
|
||||
// Close calls [ServerConn.Hijack] and then also closes the underlying connection.
|
||||
func (sc *ServerConn) Close() error {
|
||||
c, _ := sc.Hijack()
|
||||
if c != nil {
|
||||
@@ -83,7 +81,7 @@ func (sc *ServerConn) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Read returns the next request on the wire. An ErrPersistEOF is returned if
|
||||
// Read returns the next request on the wire. An [ErrPersistEOF] is returned if
|
||||
// it is gracefully determined that there are no more requests (e.g. after the
|
||||
// first request on an HTTP/1.0 connection, or after a Connection:close on a
|
||||
// HTTP/1.1 connection).
|
||||
@@ -173,7 +171,7 @@ func (sc *ServerConn) Pending() int {
|
||||
|
||||
// Write writes resp in response to req. To close the connection gracefully, set the
|
||||
// Response.Close field to true. Write should be considered operational until
|
||||
// it returns an error, regardless of any errors returned on the Read side.
|
||||
// it returns an error, regardless of any errors returned on the [ServerConn.Read] side.
|
||||
func (sc *ServerConn) Write(req *http.Request, resp *http.Response) error {
|
||||
|
||||
// Retrieve the pipeline ID of this request/response pair
|
||||
@@ -228,7 +226,7 @@ func (sc *ServerConn) Write(req *http.Request, resp *http.Response) error {
|
||||
// It is low-level, old, and unused by Go's current HTTP stack.
|
||||
// We should have deleted it before Go 1.
|
||||
//
|
||||
// Deprecated: Use Client or Transport in package net/http instead.
|
||||
// Deprecated: Use Client or Transport in package [net/http] instead.
|
||||
type ClientConn struct {
|
||||
mu sync.Mutex // read-write protects the following fields
|
||||
c net.Conn
|
||||
@@ -246,7 +244,7 @@ type ClientConn struct {
|
||||
// It is low-level, old, and unused by Go's current HTTP stack.
|
||||
// We should have deleted it before Go 1.
|
||||
//
|
||||
// Deprecated: Use the Client or Transport in package net/http instead.
|
||||
// Deprecated: Use the Client or Transport in package [net/http] instead.
|
||||
func NewClientConn(c net.Conn, r *bufio.Reader) *ClientConn {
|
||||
if r == nil {
|
||||
r = bufio.NewReader(c)
|
||||
@@ -263,17 +261,17 @@ func NewClientConn(c net.Conn, r *bufio.Reader) *ClientConn {
|
||||
// It is low-level, old, and unused by Go's current HTTP stack.
|
||||
// We should have deleted it before Go 1.
|
||||
//
|
||||
// Deprecated: Use the Client or Transport in package net/http instead.
|
||||
// Deprecated: Use the Client or Transport in package [net/http] instead.
|
||||
func NewProxyClientConn(c net.Conn, r *bufio.Reader) *ClientConn {
|
||||
cc := NewClientConn(c, r)
|
||||
cc.writeReq = (*http.Request).WriteProxy
|
||||
return cc
|
||||
}
|
||||
|
||||
// Hijack detaches the ClientConn and returns the underlying connection as well
|
||||
// Hijack detaches the [ClientConn] and returns the underlying connection as well
|
||||
// as the read-side bufio which may have some left over data. Hijack may be
|
||||
// called before the user or Read have signaled the end of the keep-alive
|
||||
// logic. The user should not call Hijack while Read or Write is in progress.
|
||||
// logic. The user should not call Hijack while [ClientConn.Read] or ClientConn.Write is in progress.
|
||||
func (cc *ClientConn) Hijack() (c net.Conn, r *bufio.Reader) {
|
||||
cc.mu.Lock()
|
||||
defer cc.mu.Unlock()
|
||||
@@ -284,7 +282,7 @@ func (cc *ClientConn) Hijack() (c net.Conn, r *bufio.Reader) {
|
||||
return
|
||||
}
|
||||
|
||||
// Close calls Hijack and then also closes the underlying connection.
|
||||
// Close calls [ClientConn.Hijack] and then also closes the underlying connection.
|
||||
func (cc *ClientConn) Close() error {
|
||||
c, _ := cc.Hijack()
|
||||
if c != nil {
|
||||
@@ -293,7 +291,7 @@ func (cc *ClientConn) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write writes a request. An ErrPersistEOF error is returned if the connection
|
||||
// Write writes a request. An [ErrPersistEOF] error is returned if the connection
|
||||
// has been closed in an HTTP keep-alive sense. If req.Close equals true, the
|
||||
// keep-alive connection is logically closed after this request and the opposing
|
||||
// server is informed. An ErrUnexpectedEOF indicates the remote closed the
|
||||
@@ -359,9 +357,9 @@ func (cc *ClientConn) Pending() int {
|
||||
}
|
||||
|
||||
// Read reads the next response from the wire. A valid response might be
|
||||
// returned together with an ErrPersistEOF, which means that the remote
|
||||
// returned together with an [ErrPersistEOF], which means that the remote
|
||||
// requested that this be the last request serviced. Read can be called
|
||||
// concurrently with Write, but not with another Read.
|
||||
// concurrently with [ClientConn.Write], but not with another Read.
|
||||
func (cc *ClientConn) Read(req *http.Request) (resp *http.Response, err error) {
|
||||
// Retrieve the pipeline ID of this request/response pair
|
||||
cc.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user