Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: golang/net
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.35.0
Choose a base ref
...
head repository: golang/net
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.36.0
Choose a head ref
  • 17 commits
  • 38 files changed
  • 5 contributors

Commits on Feb 10, 2025

  1. route: fix RTM_GET netmask parsing on Darwin

    On Darwin, the AF_FAMILY byte of a sockaddr for a netmask or genmask
    can be ignored if unreasonable. In such cases, it is the family of the
    DST address that should instead be used.
    
    Additionally, fixing faulty test data. 192.168.86.0 is a Class C network
    address, that should have a subnet mask of 255.255.255.0. What's more is
    the data can also be flag as incorrect considering structure padding
    rules alone.
    
    Further more, you can validate that `route get` will never actually return a
    netmask for a host query, even though it should be  255.255.255.255.
    
    You can run the following to check:
    route -n get -host 127.0.0.1
    
    You will note the reply has no mention of netmask.
    
    Depends on CL 646556 - https://go.dev/cl/646556
    Fixes golang/go#71578.
    
    Change-Id: Id95669b649a416a380d26c5cdba0e3d1c4bc1ffb
    GitHub-Last-Rev: 20064b2
    GitHub-Pull-Request: #232
    Reviewed-on: https://go-review.googlesource.com/c/net/+/647176
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Ian Lance Taylor <[email protected]>
    Auto-Submit: Ian Lance Taylor <[email protected]>
    Commit-Queue: Ian Lance Taylor <[email protected]>
    Reviewed-by: Damien Neil <[email protected]>
    hurricanehrndz authored and gopherbot committed Feb 10, 2025
    Copy the full SHA
    cd9d661 View commit details

Commits on Feb 13, 2025

  1. internal/httpcommon: don't depend on net/http

    When the http2 package is bundled into net/http, it imports httpcommon,
    so httpcommon must not depend on net/http.
    
    Change-Id: I2aa34e913a0df757fa83deb56f650394a924933e
    Reviewed-on: https://go-review.googlesource.com/c/net/+/649415
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    neild committed Feb 13, 2025
    Copy the full SHA
    8844327 View commit details

Commits on Feb 14, 2025

  1. all: upgrade go directive to at least 1.23.0 [generated]

    By now Go 1.24.0 has been released, and Go 1.22 is no longer supported
    per the Go Release Policy (https://go.dev/doc/devel/release#policy).
    
    For golang/go#69095.
    
    [git-generate]
    (cd . && go get [email protected] && go mod tidy && go mod edit -toolchain=none)
    
    Change-Id: I7e0b4b38a9838b5489cb674cd20ae60233a304e6
    Reviewed-on: https://go-review.googlesource.com/c/net/+/649775
    Reviewed-by: Cherry Mui <[email protected]>
    Reviewed-by: Dmitri Shuralyov <[email protected]>
    Auto-Submit: Gopher Robot <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    gopherbot committed Feb 14, 2025
    Copy the full SHA
    5095d0c View commit details

Commits on Feb 18, 2025

  1. context: delete dead code, sync docs with upstream context package

    The go directive is now at 1.23.0, so the go1.7 and go1.9 build
    constraints are guaranteed to always be satisfied, and their inverse
    will never be satisfied. Delete all the dead code and merge everything
    that's left in a single context.go file. Also update docs to match the
    upstream context package.
    
    For golang/go#49506.
    
    Change-Id: I317550767838a93af2c2d3dbc7b61f2e37e6fe1c
    Reviewed-on: https://go-review.googlesource.com/c/net/+/650155
    Reviewed-by: Ian Lance Taylor <[email protected]>
    Reviewed-by: Damien Neil <[email protected]>
    Auto-Submit: Dmitri Shuralyov <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Dmitri Shuralyov <[email protected]>
    dmitshur authored and gopherbot committed Feb 18, 2025
    Copy the full SHA
    918d64e View commit details
  2. context: delete lone example

    This is motivated by a few reasons. One, the upstream package has more
    examples, and no one should be looking at this old package to learn how
    to use it. Seeing an example might make it seem like the scope of the
    documentation here is to provide examples, and that there aren't many
    of them. Instead of trying to add more examples or maintain the current
    one by porting the de-flake enhancement from CL 460999, delete the only
    example here.
    
    Second, running 'go fix ./...' causes the 'context' fix to rewrite the
    import path of the example from "golang.org/x/net/context" to "context".
    That is a false positive in the fix, and I would've liked it fix the
    fix, but it only has the AST information at this time, not type info,
    so the import path isn't currently available to the check. That means
    it can't know when it's running on the golang.org/x/net/context package,
    which is the one place it should skip the rewrite.
    
    It seems simpler to just delete the example, and then it becomes
    possible to use 'go fix ./...' safely on the entire x/net module.
    
    For golang/go#49506.
    
    Change-Id: I97eba33ca2e1f2960aef8340d8b561639a26ee48
    Reviewed-on: https://go-review.googlesource.com/c/net/+/650156
    Reviewed-by: Ian Lance Taylor <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Dmitri Shuralyov <[email protected]>
    Reviewed-by: Damien Neil <[email protected]>
    Auto-Submit: Dmitri Shuralyov <[email protected]>
    dmitshur authored and gopherbot committed Feb 18, 2025
    Copy the full SHA
    447f458 View commit details
  3. internal/http3: add Server

    Add the general structure of an HTTP/3 server.
    The server currently accepts QUIC connections and establishes a
    control stream on them, but does not handle requests.
    
    For golang/go#70914
    
    Change-Id: I28193ddacef028233248601979b0b45ad844205a
    Reviewed-on: https://go-review.googlesource.com/c/net/+/646617
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    neild committed Feb 18, 2025
    Copy the full SHA
    163d836 View commit details

Commits on Feb 20, 2025

  1. http2: avoid extended CONNECT hang when connection breaks during startup

    Fixes golang/go#70658
    
    Change-Id: Iaac5c7730a10afc8a8bb2e725746fa7387970582
    Reviewed-on: https://go-review.googlesource.com/c/net/+/633277
    Auto-Submit: Damien Neil <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Antonio Ojea <[email protected]>
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    neild authored and gopherbot committed Feb 20, 2025
    Copy the full SHA
    b4c8655 View commit details

Commits on Feb 25, 2025

  1. quic: add Conn.ConnectionState

    Add a method that returns the tls.ConnectionState for a connection.
    Generally useful, and also required to let HTTP/3 expose the
    ConnectionState in Requests.
    
    Change-Id: Iba725e0f40c68020fc6ee45d49f5c609a2b6b493
    Reviewed-on: https://go-review.googlesource.com/c/net/+/647075
    Auto-Submit: Damien Neil <[email protected]>
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    neild authored and gopherbot committed Feb 25, 2025
    Copy the full SHA
    0d7dc54 View commit details
  2. http2, internal/httpcommon: factor out server header logic for h2/h3

    Move common elements of constructing a http.Request for
    a server handler into internal/httpcommon.
    
    For golang/go#70914
    
    Change-Id: I5dcd902e189a0bb8daf47c0a815045d274346923
    Reviewed-on: https://go-review.googlesource.com/c/net/+/652455
    Auto-Submit: Damien Neil <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    neild authored and gopherbot committed Feb 25, 2025
    Copy the full SHA
    1d78a08 View commit details

Commits on Feb 26, 2025

  1. http2, internal/httpcommon: reject userinfo in :authority

    RFC 9113, section 8.3.1: The :authority (host) in an HTTP
    request must not include a userinfo (e.g., user@host).
    
    Change-Id: I459a3da40b825c9662467778f582050c7358f8bb
    Reviewed-on: https://go-review.googlesource.com/c/net/+/652456
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    Auto-Submit: Damien Neil <[email protected]>
    neild authored and gopherbot committed Feb 26, 2025
    Copy the full SHA
    43c2540 View commit details

Commits on Feb 27, 2025

  1. internal/http3: make read-data tests usable for server handlers

    A reading a transport response body behaves much the same as a
    server handler reading a request body. Move the transport test into
    body_test.go and rearrange it a bit so we can reuse it as a server
    test.
    
    For golang/go#70914
    
    Change-Id: I24e10dd078ffab867c9b678e1d0b99172763b069
    Reviewed-on: https://go-review.googlesource.com/c/net/+/652457
    Auto-Submit: Damien Neil <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    neild authored and gopherbot committed Feb 27, 2025
    Copy the full SHA
    5f45c77 View commit details

Commits on Feb 28, 2025

  1. http2: don't log expected errors from writing invalid trailers

    Change-Id: I1c8af5a1f7539a25d5602a7bc8e15756d3cafa56
    Reviewed-on: https://go-review.googlesource.com/c/net/+/653695
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Auto-Submit: Damien Neil <[email protected]>
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    neild authored and gopherbot committed Feb 28, 2025
    Copy the full SHA
    b73e574 View commit details
  2. http2: fix flakiness from t.Log when GOOS=js

    The http2 package uses a precursor to the experimental
    testing/synctest package, parsing runtime.Stack output
    to determine when goroutines are idle.
    
    When GOOS=js, some tests which use t.Log are flaky.
    t.Log blocks in the syscall package writing to stdout.
    The GOOS=js implementation of the syscall leaves the goroutine
    blocked on a channel operation, which synctest interprets
    as the goroutine being "durably blocked".
    
    Fix the http2 synctest to treat any goroutine blocked in the
    syscall package as not being durably blocked.
    
    Making this fix reveals another bug when GOOS=js: Looping
    while calling runtime.Gosched does not appear to permit
    syscalls to make progress. Add a few time.Sleep(1) calls
    while waiting for idleness to work around the problem.
    
    While changing things in here, change http2's synctest
    to not treat goroutines blocked on mutex operations as
    durably blocked. This matches the behavior of testing/synctest.
    
    (This would all be simpler if we just used testing/synctest,
    but we don't want to make the http2 package depend on an
    experimental API.)
    
    Fixes golang/go#67693
    
    Change-Id: I889834e97e4a33f4ef232278b1a78af00d52d261
    Reviewed-on: https://go-review.googlesource.com/c/net/+/653696
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Auto-Submit: Damien Neil <[email protected]>
    neild authored and gopherbot committed Feb 28, 2025
    Copy the full SHA
    aad0180 View commit details
  3. internal/http3: move more common stream processing to genericConn

    Move the server stream-accept loop into genericConn.
    (Overlooked in a previous CL.)
    
    Be more consistent about having genericConn handle errors.
    
    For golang/go#70914
    
    Change-Id: I872673482f16539e95a1a1381ada7d3e22affb82
    Reviewed-on: https://go-review.googlesource.com/c/net/+/653395
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Auto-Submit: Damien Neil <[email protected]>
    Reviewed-by: Jonathan Amsterdam <[email protected]>
    neild authored and gopherbot committed Feb 28, 2025
    Copy the full SHA
    459513d View commit details
  4. publicsuffix: spruce up code gen and speed up PublicSuffix

    Rely on functions from the slices package where convenient. Drop custom max functions in favor of max builtin. Remove unused non-exported functions.
    
    Reduce the number of bounds checks. Replace calls to strings.LastIndex by calls to strings.LastIndexByte.
    
    goos: darwin
    goarch: amd64
    pkg: golang.org/x/net/publicsuffix
    cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
                   │     old     │                new                 │
                   │   sec/op    │   sec/op     vs base               │
    PublicSuffix-8   13.46µ ± 0%   13.23µ ± 0%  -1.67% (p=0.000 n=20)
    
                   │    old     │              new               │
                   │    B/op    │    B/op     vs base            │
    PublicSuffix-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=20) ¹
    ¹ all samples are equal
    
                   │    old     │              new               │
                   │ allocs/op  │ allocs/op   vs base            │
    PublicSuffix-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=20) ¹
    ¹ all samples are equal
    
    Change-Id: Id72967560884d98a5c0791ccea73dbb27d120c2c
    GitHub-Last-Rev: 87567e7
    GitHub-Pull-Request: #233
    Reviewed-on: https://go-review.googlesource.com/c/net/+/652236
    Reviewed-by: Damien Neil <[email protected]>
    Commit-Queue: Ian Lance Taylor <[email protected]>
    Auto-Submit: Ian Lance Taylor <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Michael Pratt <[email protected]>
    Julien Cretel authored and gopherbot committed Feb 28, 2025
    Copy the full SHA
    fe7f039 View commit details

Commits on Mar 4, 2025

  1. proxy, http/httpproxy: do not mismatch IPv6 zone ids against hosts

    When matching against a host "example.com",
    don't match an IPv6 address like "[1000::1%25.example.com]:80".
    
    Thanks to Juho Forsén of Mattermost for reporting this issue.
    
    Fixes CVE-2025-22870
    For #71984
    
    Change-Id: I0c4fdf18765decc27e6ddf220ebe3a9bf4a6454d
    Reviewed-on: https://go-review.googlesource.com/c/net/+/654697
    Auto-Submit: Roland Shoemaker <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Commit-Queue: Roland Shoemaker <[email protected]>
    Reviewed-by: Roland Shoemaker <[email protected]>
    Reviewed-by: Damien Neil <[email protected]>
    neild authored and gopherbot committed Mar 4, 2025
    Copy the full SHA
    cde1dda View commit details
  2. go.mod: update golang.org/x dependencies

    Update golang.org/x dependencies to their latest tagged versions.
    
    Change-Id: Id043663bf74d33d77fcea718ff308fa9461f242b
    Reviewed-on: https://go-review.googlesource.com/c/net/+/654320
    Reviewed-by: Roland Shoemaker <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Auto-Submit: Gopher Robot <[email protected]>
    Auto-Submit: Junyang Shao <[email protected]>
    Reviewed-by: Michael Pratt <[email protected]>
    gopherbot committed Mar 4, 2025
    Copy the full SHA
    85d1d54 View commit details
112 changes: 100 additions & 12 deletions context/context.go
Original file line number Diff line number Diff line change
@@ -3,29 +3,31 @@
// license that can be found in the LICENSE file.

// Package context defines the Context type, which carries deadlines,
// cancelation signals, and other request-scoped values across API boundaries
// cancellation signals, and other request-scoped values across API boundaries
// and between processes.
// As of Go 1.7 this package is available in the standard library under the
// name context. https://golang.org/pkg/context.
// name [context], and migrating to it can be done automatically with [go fix].
//
// Incoming requests to a server should create a Context, and outgoing calls to
// servers should accept a Context. The chain of function calls between must
// propagate the Context, optionally replacing it with a modified copy created
// using WithDeadline, WithTimeout, WithCancel, or WithValue.
// Incoming requests to a server should create a [Context], and outgoing
// calls to servers should accept a Context. The chain of function
// calls between them must propagate the Context, optionally replacing
// it with a derived Context created using [WithCancel], [WithDeadline],
// [WithTimeout], or [WithValue].
//
// Programs that use Contexts should follow these rules to keep interfaces
// consistent across packages and enable static analysis tools to check context
// propagation:
//
// Do not store Contexts inside a struct type; instead, pass a Context
// explicitly to each function that needs it. The Context should be the first
// explicitly to each function that needs it. This is discussed further in
// https://go.dev/blog/context-and-structs. The Context should be the first
// parameter, typically named ctx:
//
// func DoSomething(ctx context.Context, arg Arg) error {
// // ... use ctx ...
// }
//
// Do not pass a nil Context, even if a function permits it. Pass context.TODO
// Do not pass a nil [Context], even if a function permits it. Pass [context.TODO]
// if you are unsure about which Context to use.
//
// Use context Values only for request-scoped data that transits processes and
@@ -34,9 +36,30 @@
// The same Context may be passed to functions running in different goroutines;
// Contexts are safe for simultaneous use by multiple goroutines.
//
// See http://blog.golang.org/context for example code for a server that uses
// See https://go.dev/blog/context for example code for a server that uses
// Contexts.
package context // import "golang.org/x/net/context"
//
// [go fix]: https://go.dev/cmd/go#hdr-Update_packages_to_use_new_APIs
package context

import (
"context" // standard library's context, as of Go 1.7
"time"
)

// A Context carries a deadline, a cancellation signal, and other values across
// API boundaries.
//
// Context's methods may be called by multiple goroutines simultaneously.
type Context = context.Context

// Canceled is the error returned by [Context.Err] when the context is canceled
// for some reason other than its deadline passing.
var Canceled = context.Canceled

// DeadlineExceeded is the error returned by [Context.Err] when the context is canceled
// due to its deadline passing.
var DeadlineExceeded = context.DeadlineExceeded

// Background returns a non-nil, empty Context. It is never canceled, has no
// values, and has no deadline. It is typically used by the main function,
@@ -49,8 +72,73 @@ func Background() Context {
// TODO returns a non-nil, empty Context. Code should use context.TODO when
// it's unclear which Context to use or it is not yet available (because the
// surrounding function has not yet been extended to accept a Context
// parameter). TODO is recognized by static analysis tools that determine
// whether Contexts are propagated correctly in a program.
// parameter).
func TODO() Context {
return todo
}

var (
background = context.Background()
todo = context.TODO()
)

// A CancelFunc tells an operation to abandon its work.
// A CancelFunc does not wait for the work to stop.
// A CancelFunc may be called by multiple goroutines simultaneously.
// After the first call, subsequent calls to a CancelFunc do nothing.
type CancelFunc = context.CancelFunc

// WithCancel returns a derived context that points to the parent context
// but has a new Done channel. The returned context's Done channel is closed
// when the returned cancel function is called or when the parent context's
// Done channel is closed, whichever happens first.
//
// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this [Context] complete.
func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
return context.WithCancel(parent)
}

// WithDeadline returns a derived context that points to the parent context
// but has the deadline adjusted to be no later than d. If the parent's
// deadline is already earlier than d, WithDeadline(parent, d) is semantically
// equivalent to parent. The returned [Context.Done] channel is closed when
// the deadline expires, when the returned cancel function is called,
// or when the parent context's Done channel is closed, whichever happens first.
//
// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this [Context] complete.
func WithDeadline(parent Context, d time.Time) (Context, CancelFunc) {
return context.WithDeadline(parent, d)
}

// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
//
// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this [Context] complete:
//
// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
// defer cancel() // releases resources if slowOperation completes before timeout elapses
// return slowOperation(ctx)
// }
func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
return context.WithTimeout(parent, timeout)
}

// WithValue returns a derived context that points to the parent Context.
// In the derived context, the value associated with key is val.
//
// Use context Values only for request-scoped data that transits processes and
// APIs, not for passing optional parameters to functions.
//
// The provided key must be comparable and should not be of type
// string or any other built-in type to avoid collisions between
// packages using context. Users of WithValue should define their own
// types for keys. To avoid allocating when assigning to an
// interface{}, context keys often have concrete type
// struct{}. Alternatively, exported context key variables' static
// type should be a pointer or interface.
func WithValue(parent Context, key, val interface{}) Context {
return context.WithValue(parent, key, val)
}
Loading