Skip to content

[tailscale] net/http: add SetResponseWriteEnforcer - #138

Merged
bradfitz merged 1 commit into
tailscale.go1.25from
icio/httprwenf
Oct 17, 2025
Merged

[tailscale] net/http: add SetResponseWriteEnforcer#138
bradfitz merged 1 commit into
tailscale.go1.25from
icio/httprwenf

Conversation

@icio

@icio icio commented Oct 14, 2025

Copy link
Copy Markdown

The idea with this change is to inject the Tracker into the Request context with http.Server.BaseContext so that it is accessible in the SetResponseWriteEnforcer callback. Close the injected Tracker in a defer at the first layer of handle.

This is only adding enforcement at the time of WriteHeader, which is often implicitly called during the first Write. But this enforcement wouldn't catch the following pattern:

w.WriteHeader(200)
tx := db.Tx(ctx)
defer tx.Rollback()
w.Write(blob)

Updates tailscale/corp#7821
Updates #55

@icio
icio requested a review from bradfitz October 14, 2025 15:54
@@ -0,0 +1,100 @@
package http_test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@bradfitz

Copy link
Copy Markdown
Member

oh, but put [tailscale] in your git title first

Comment thread src/net/http/tailscale.go
@icio icio changed the title net/http: add SetResponseWriteEnforcer [tailscale] net/http: add SetResponseWriteEnforcer Oct 14, 2025
@icio
icio force-pushed the icio/httprwenf branch 2 times, most recently from 2907351 to fd907a2 Compare October 14, 2025 20:30

@bradfitz bradfitz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it

To use with Trackers, inject the Tracker into the Request context with
http.Server.BaseContext so that it is accessible in the
SetResponseWriteEnforcer callback. Close the injected Tracker in a defer at the
first layer of handle.

Updates tailscale/corp#7821
Updates #55
@bradfitz
bradfitz merged commit 02dc1d8 into tailscale.go1.25 Oct 17, 2025
4 checks passed
@bradfitz
bradfitz deleted the icio/httprwenf branch October 17, 2025 14:58
bradfitz added a commit to tailscale/tailscale that referenced this pull request Oct 17, 2025
Updates tailscale/go#140
Updates tailscale/go#142
Updates tailscale/go#138

Change-Id: Id25b6fa4e31eee243fec17667f14cdc48243c59e
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
bradfitz added a commit to tailscale/tailscale that referenced this pull request Oct 17, 2025
Updates tailscale/go#140
Updates tailscale/go#142
Updates tailscale/go#138

Change-Id: Id25b6fa4e31eee243fec17667f14cdc48243c59e
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
bradfitz added a commit to tailscale/tailscale that referenced this pull request Oct 17, 2025
Updates tailscale/go#140
Updates tailscale/go#142
Updates tailscale/go#138

Change-Id: Id25b6fa4e31eee243fec17667f14cdc48243c59e
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
kingcanfish pushed a commit to kingcanfish/tailscale that referenced this pull request Nov 15, 2025
Updates tailscale/go#140
Updates tailscale/go#142
Updates tailscale/go#138

Change-Id: Id25b6fa4e31eee243fec17667f14cdc48243c59e
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants