[go] net/http: remove Content-Encoding in writeNotModified

36 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Jan 29, 2022, 9:38:39 AM1/29/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

net/http: remove Content-Encoding in writeNotModified

Additional header to remove if set before calling `http.ServeContent`.

Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
GitHub-Last-Rev: 6dff7edd4f18a32144f4a14be11213b512a56b5b
GitHub-Pull-Request: golang/go#50903
---
M src/net/http/fs.go
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/net/http/fs.go b/src/net/http/fs.go
index 6caee9e..2f83358 100644
--- a/src/net/http/fs.go
+++ b/src/net/http/fs.go
@@ -541,6 +541,7 @@
h := w.Header()
delete(h, "Content-Type")
delete(h, "Content-Length")
+ delete(h, "Content-Encoding")
if h.Get("Etag") != "" {
delete(h, "Last-Modified")
}

To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
Gerrit-Change-Number: 381955
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newchange

Damien Neil (Gerrit)

unread,
Apr 1, 2022, 2:50:12 PM4/1/22
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Damien Neil.

Damien Neil uploaded patch set #2 to the change originally created by Gerrit Bot.

View Change

net/http: remove Content-Encoding in writeNotModified

Additional header to remove if set before calling http.ServeContent.


Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
GitHub-Last-Rev: 6dff7edd4f18a32144f4a14be11213b512a56b5b
GitHub-Pull-Request: golang/go#50903
---
M src/net/http/fs.go
1 file changed, 14 insertions(+), 0 deletions(-)

To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
Gerrit-Change-Number: 381955
Gerrit-PatchSet: 2
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Russ Cox <r...@golang.org>
Gerrit-Attention: Damien Neil <dn...@google.com>
Gerrit-MessageType: newpatchset

Damien Neil (Gerrit)

unread,
Apr 1, 2022, 2:50:50 PM4/1/22
to Gerrit Bot, goph...@pubsubhelper.golang.org, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

Patch set 2:Run-TryBot +1Code-Review +2Trust +1

View Change

    To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    Gerrit-Change-Number: 381955
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Comment-Date: Fri, 01 Apr 2022 18:50:47 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Gerrit Bot (Gerrit)

    unread,
    Apr 1, 2022, 2:54:16 PM4/1/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick.

    Gerrit Bot uploaded patch set #3 to this change.

    View Change

    net/http: remove Content-Encoding in writeNotModified

    Additional header to remove if set before calling `http.ServeContent`.


    Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    GitHub-Last-Rev: 6dff7edd4f18a32144f4a14be11213b512a56b5b
    GitHub-Pull-Request: golang/go#50903
    ---
    M src/net/http/fs.go
    1 file changed, 14 insertions(+), 0 deletions(-)

    To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    Gerrit-Change-Number: 381955
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-MessageType: newpatchset

    Brad Fitzpatrick (Gerrit)

    unread,
    Apr 1, 2022, 9:36:37 PM4/1/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick.

    View Change

    1 comment:

    • Patchset:

      • Patch Set #3:

        Sure? I'm missing some context, like a bug or discussion.

        A test might be nice too if this matters.

    To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    Gerrit-Change-Number: 381955
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Comment-Date: Sat, 02 Apr 2022 01:36:34 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Mitar (Gerrit)

    unread,
    Apr 2, 2022, 7:47:07 AM4/2/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick.

    View Change

    1 comment:

    • Patchset:

      • Patch Set #3:

        Sure? I'm missing some context, like a bug or discussion. […]

        RFC is context. The comment at the beginning of `writeNotModified` function refers to RFC which states:

        ```
        The server generating a 304 response MUST generate any of the
        following header fields that would have been sent in a 200 (OK)
        response to the same request: Cache-Control, Content-Location, Date,
        ETag, Expires, and Vary.
           Since the goal of a 304 response is to minimize information transfer
        when the recipient already has one or more cached representations, a
        sender SHOULD NOT generate representation metadata other than the
        above listed fields unless said metadata exists for the purpose of
        guiding cache updates (e.g., Last-Modified might be useful if the
        response does not have an ETag field).
        ```

        So, one more header to remove because it is unnecessary, but the API of `ServeContent` is that one should set `Content-Encoding` before calling it, if the content is encoded (e.g., compressed). But then, if content was not modified, that header should be removed.

    To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    Gerrit-Change-Number: 381955
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mitar <mmi...@gmail.com>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Comment-Date: Sat, 02 Apr 2022 11:47:02 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-MessageType: comment

    Cherry Mui (Gerrit)

    unread,
    Apr 4, 2022, 12:22:05 PM4/4/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Mitar, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Mitar, Brad Fitzpatrick.

    Patch set 3:Trust +1

    View Change

    1 comment:

    • Patchset:

      • Patch Set #3:

        RFC is context. […]

        Probably add this information to the CL description. Thanks.

    To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    Gerrit-Change-Number: 381955
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mitar <mmi...@gmail.com>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: Mitar <mmi...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Comment-Date: Mon, 04 Apr 2022 16:22:00 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Mitar <mmi...@gmail.com>

    Gerrit Bot (Gerrit)

    unread,
    Apr 6, 2022, 5:37:26 PM4/6/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Mitar, Brad Fitzpatrick.

    Gerrit Bot uploaded patch set #4 to this change.

    View Change

    net/http: remove Content-Encoding in writeNotModified

    Additional header to remove if set before calling http.ServeContent.

    The API of ServeContent is that one should set Content-Encoding before calling it, if the content is encoded (e.g., compressed). But then, if content has not been modified, that header should be removed, according to RFC 7232 section 4.1.


    Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    GitHub-Last-Rev: 6dff7edd4f18a32144f4a14be11213b512a56b5b
    GitHub-Pull-Request: golang/go#50903
    ---
    M src/net/http/fs.go
    1 file changed, 16 insertions(+), 0 deletions(-)

    To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    Gerrit-Change-Number: 381955
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mitar <mmi...@gmail.com>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: Mitar <mmi...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-MessageType: newpatchset

    Mitar (Gerrit)

    unread,
    Apr 6, 2022, 5:39:09 PM4/6/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Cherry Mui, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Cherry Mui.

    View Change

    2 comments:

      • Probably add this information to the CL description. Thanks.

    To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    Gerrit-Change-Number: 381955
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mitar <mmi...@gmail.com>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-Comment-Date: Wed, 06 Apr 2022 21:39:04 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Mitar <mmi...@gmail.com>
    Comment-In-Reply-To: Brad Fitzpatrick <brad...@golang.org>
    Comment-In-Reply-To: Cherry Mui <cher...@google.com>
    Gerrit-MessageType: comment

    Gerrit Bot (Gerrit)

    unread,
    Apr 6, 2022, 5:44:45 PM4/6/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Cherry Mui.

    Gerrit Bot uploaded patch set #5 to this change.

    View Change

    net/http: remove Content-Encoding in writeNotModified

    Additional header to remove if set before calling http.ServeContent.

    The API of ServeContent is that one should set Content-Encoding before calling it, if the content is encoded (e.g., compressed). But then, if content has not been modified, that header should be removed, according to RFC 7232 section 4.1.

    Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    GitHub-Last-Rev: 3a97b6089c586ee8ed1913b8cfd03ffaaa29fa16

    GitHub-Pull-Request: golang/go#50903
    ---
    M src/net/http/fs.go
    1 file changed, 16 insertions(+), 0 deletions(-)

    To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    Gerrit-Change-Number: 381955
    Gerrit-PatchSet: 5
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mitar <mmi...@gmail.com>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-MessageType: newpatchset

    Gerrit Bot (Gerrit)

    unread,
    Apr 7, 2022, 4:49:10 AM4/7/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Cherry Mui.

    Gerrit Bot uploaded patch set #6 to this change.

    View Change

    net/http: remove Content-Encoding in writeNotModified

    Additional header to remove if set before calling http.ServeContent.

    The API of ServeContent is that one should set Content-Encoding before calling it, if the content is encoded (e.g., compressed). But then, if content has not been modified, that header should be removed, according to RFC 7232 section 4.1.

    Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    GitHub-Last-Rev: 6730b02bc7407e1d4bc024e280dd54e8dc372b6b

    GitHub-Pull-Request: golang/go#50903
    ---
    M src/net/http/fs.go
    M src/net/http/fs_test.go
    2 files changed, 59 insertions(+), 0 deletions(-)

    To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
    Gerrit-Change-Number: 381955
    Gerrit-PatchSet: 6

    Gopher Robot (Gerrit)

    unread,
    Apr 7, 2022, 4:49:31 AM4/7/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Cherry Mui, Mitar, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Cherry Mui.

    Congratulations on opening your first change. Thank you for your contribution!

    Next steps:
    A maintainer will review your change and provide feedback. See
    https://go.dev/doc/contribute#review for more info and tips to get your
    patch through code review.

    Most changes in the Go project go through a few rounds of revision. This can be
    surprising to people new to the project. The careful, iterative review process
    is our way of helping mentor contributors and ensuring that their contributions
    have a lasting impact.

    During May-July and Nov-Jan the Go project is in a code freeze, during which
    little code gets reviewed or merged. If a reviewer responds with a comment like
    R=go1.11 or adds a tag like "wait-release", it means that this CL will be
    reviewed as part of the next development cycle. See https://go.dev/s/release
    for more details.

    View Change

      To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      Gerrit-Change-Number: 381955
      Gerrit-PatchSet: 6
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Mitar <mmi...@gmail.com>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Comment-Date: Thu, 07 Apr 2022 08:49:28 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: No
      Gerrit-MessageType: comment

      Mitar (Gerrit)

      unread,
      Apr 7, 2022, 4:50:53 AM4/7/22
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Cherry Mui, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Cherry Mui.

      View Change

      1 comment:

      • Patchset:

        • Patch Set #5:

          I have also added tests. But they are failing because there is difference between HTTP1 and HTTP2: it looks like on HTTP1 content-length header is added to "not modified" response, but it should not. Not sure why is that. That was a bug from before the test I added discovered. (There was no test for this before I could find.)

          Not sure how to fix this, if somebody could point me to the place. I can also remove content-length check from tests I added and somebody else can fix it in a followup PR.

      To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      Gerrit-Change-Number: 381955
      Gerrit-PatchSet: 5
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Mitar <mmi...@gmail.com>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Comment-Date: Thu, 07 Apr 2022 08:50:48 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Gerrit-MessageType: comment

      Gerrit Bot (Gerrit)

      unread,
      Apr 7, 2022, 4:56:40 AM4/7/22
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Cherry Mui.

      Gerrit Bot uploaded patch set #7 to this change.

      View Change

      net/http: remove Content-Encoding in writeNotModified

      Additional header to remove if set before calling http.ServeContent.

      The API of ServeContent is that one should set Content-Encoding before calling it, if the content is encoded (e.g., compressed). But then, if content has not been modified, that header should be removed, according to RFC 7232 section 4.1.

      Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      GitHub-Last-Rev: 03812c410b4d2be36ad3e88148111858ba34d64c

      GitHub-Pull-Request: golang/go#50903
      ---
      M src/net/http/fs.go
      M src/net/http/fs_test.go
      2 files changed, 62 insertions(+), 0 deletions(-)

      To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      Gerrit-Change-Number: 381955
      Gerrit-PatchSet: 7
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Mitar <mmi...@gmail.com>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-MessageType: newpatchset

      Gerrit Bot (Gerrit)

      unread,
      Apr 7, 2022, 5:13:07 AM4/7/22
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Cherry Mui.

      Gerrit Bot uploaded patch set #8 to this change.

      View Change

      net/http: remove Content-Encoding in writeNotModified

      Additional header to remove if set before calling http.ServeContent.

      The API of ServeContent is that one should set Content-Encoding before calling it, if the content is encoded (e.g., compressed). But then, if content has not been modified, that header should be removed, according to RFC 7232 section 4.1.

      Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      GitHub-Last-Rev: d10036ae6e89c3125198b37056a57ca6c61a3d0a

      GitHub-Pull-Request: golang/go#50903
      ---
      M src/net/http/fs.go
      M src/net/http/fs_test.go
      2 files changed, 69 insertions(+), 0 deletions(-)

      To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      Gerrit-Change-Number: 381955
      Gerrit-PatchSet: 8

      hopehook (Gerrit)

      unread,
      May 18, 2022, 9:07:43 AM5/18/22
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Cherry Mui, Mitar, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Brad Fitzpatrick, Cherry Mui, Mitar.

      View Change

      1 comment:

      • Patchset:

        • Patch Set #5:

          I have also added tests. […]

          Hey, guys. I see the "Content-Length" of HTTP1 is 0 when status code is 304.

          Where: `net/http/transfer.go:fixLength()`
          Code:
          ```
          if status/100 == 1 {
          return 0, nil
          }
          switch status {
          case 204, 304:
          return 0, nil
          }
          ```
          RFC:
          https://mirrors.nju.edu.cn/rfc/rfc7230.html#section-3.3
          ```
          All 1xx (Informational), 204 (No Content), and 304 (Not Modified)
          responses do not include a message body. All other responses do
          include a message body, although the body might be of zero length.
          ```


          In my personal opinion, 0 or -1 has little effect.
          I think you can pass the tests and add some comments for that.

      To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      Gerrit-Change-Number: 381955
      Gerrit-PatchSet: 8
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Mitar <mmi...@gmail.com>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-CC: hopehook <hope...@qq.com>
      Gerrit-Attention: Mitar <mmi...@gmail.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Comment-Date: Wed, 18 May 2022 13:07:36 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Mitar <mmi...@gmail.com>
      Gerrit-MessageType: comment

      Gerrit Bot (Gerrit)

      unread,
      Jul 10, 2022, 7:49:24 AM7/10/22
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Brad Fitzpatrick, Cherry Mui, Damien Neil, Mitar.

      Gerrit Bot uploaded patch set #9 to this change.

      View Change

      The following approvals got outdated and were removed: Trust+1 by Cherry Mui, Trust+1 by Damien Neil

      net/http: remove Content-Encoding in writeNotModified

      Additional header to remove if set before calling http.ServeContent.

      The API of ServeContent is that one should set Content-Encoding before calling it, if the content is encoded (e.g., compressed). But then, if content has not been modified, that header should be removed, according to RFC 7232 section 4.1.

      Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      GitHub-Last-Rev: 21744b96bd9534f0ab1792cd877fcd3b113bb92c

      GitHub-Pull-Request: golang/go#50903
      ---
      M src/net/http/fs.go
      M src/net/http/fs_test.go
      2 files changed, 69 insertions(+), 0 deletions(-)

      To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      Gerrit-Change-Number: 381955
      Gerrit-PatchSet: 9
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Mitar <mmi...@gmail.com>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-CC: hopehook <hope...@qq.com>
      Gerrit-Attention: Damien Neil <dn...@google.com>
      Gerrit-Attention: Mitar <mmi...@gmail.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-MessageType: newpatchset

      Mitar (Gerrit)

      unread,
      Jul 10, 2022, 10:06:10 AM7/10/22
      to Gerrit Bot, goph...@pubsubhelper.golang.org, hopehook, Cherry Mui, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Brad Fitzpatrick, Cherry Mui, Damien Neil, hopehook.

      View Change

      2 comments:

      • Patchset:

        • Patch Set #5:

          Hey, guys. I see the "Content-Length" of HTTP1 is 0 when status code is 304. […]

          Tests now pass.

      • Patchset:

        • Patch Set #9:

          Please do another pass of reviews. There are tests now.

      To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      Gerrit-Change-Number: 381955
      Gerrit-PatchSet: 9
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Mitar <mmi...@gmail.com>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-CC: hopehook <hope...@qq.com>
      Gerrit-Attention: hopehook <hope...@qq.com>
      Gerrit-Attention: Damien Neil <dn...@google.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Comment-Date: Sun, 10 Jul 2022 14:06:03 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: hopehook <hope...@qq.com>

      Gerrit Bot (Gerrit)

      unread,
      Jul 10, 2022, 10:06:17 AM7/10/22
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Brad Fitzpatrick, Cherry Mui, Damien Neil, hopehook.

      Gerrit Bot uploaded patch set #10 to this change.

      View Change

      net/http: remove Content-Encoding in writeNotModified


      Additional header to remove if set before calling http.ServeContent.

      The API of ServeContent is that one should set Content-Encoding before calling it, if the content is encoded (e.g., compressed). But then, if content has not been modified, that header should be removed, according to RFC 7232 section 4.1.

      Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      GitHub-Last-Rev: 53df6e73c44b63f351f7aeeb45cab82d706311eb

      GitHub-Pull-Request: golang/go#50903
      ---
      M src/net/http/fs.go
      M src/net/http/fs_test.go
      2 files changed, 70 insertions(+), 0 deletions(-)

      To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      Gerrit-Change-Number: 381955
      Gerrit-PatchSet: 10
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Mitar <mmi...@gmail.com>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-CC: hopehook <hope...@qq.com>
      Gerrit-Attention: hopehook <hope...@qq.com>
      Gerrit-Attention: Damien Neil <dn...@google.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-MessageType: newpatchset

      hopehook (Gerrit)

      unread,
      Jul 10, 2022, 8:40:56 PM7/10/22
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Cherry Mui, Mitar, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Brad Fitzpatrick, Cherry Mui, Damien Neil.

      Patch set 10:Run-TryBot +1

      View Change

      1 comment:

      To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
      Gerrit-Change-Number: 381955
      Gerrit-PatchSet: 10
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-Reviewer: hopehook <hope...@qq.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Mitar <mmi...@gmail.com>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-Attention: Damien Neil <dn...@google.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Comment-Date: Mon, 11 Jul 2022 00:40:50 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Gopher Robot <go...@golang.org>
      Gerrit-MessageType: comment

      Benny Siegert (Gerrit)

      unread,
      Jul 11, 2022, 4:23:07 AM7/11/22
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Benny Siegert, Gopher Robot, hopehook, Cherry Mui, Mitar, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Brad Fitzpatrick, Cherry Mui, Damien Neil.

      Patch set 10:Code-Review +1

      View Change

        To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
        Gerrit-Change-Number: 381955
        Gerrit-PatchSet: 10
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Benny Siegert <bsie...@gmail.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Damien Neil <dn...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: hopehook <hope...@qq.com>
        Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-CC: Mitar <mmi...@gmail.com>
        Gerrit-CC: Russ Cox <r...@golang.org>
        Gerrit-Attention: Damien Neil <dn...@google.com>
        Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Attention: Brad Fitzpatrick <brad...@tailscale.com>
        Gerrit-Attention: Cherry Mui <cher...@google.com>
        Gerrit-Comment-Date: Mon, 11 Jul 2022 08:22:59 +0000

        Benny Siegert (Gerrit)

        unread,
        Jul 11, 2022, 4:24:07 AM7/11/22
        to Gerrit Bot, Benny Siegert, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Gopher Robot, hopehook, Cherry Mui, Mitar, Brad Fitzpatrick, Brad Fitzpatrick, Damien Neil, Russ Cox, golang-co...@googlegroups.com

        Benny Siegert submitted this change.

        View Change



        2 is the latest approved patch-set.
        The change was submitted with unreviewed changes in the following files:

        ```
        The name of the file: src/net/http/fs_test.go
        Insertions: 54, Deletions: 0.

        The diff is too large to show. Please review the diff.
        ```

        Approvals: Gopher Robot: TryBots succeeded hopehook: Run TryBots Damien Neil: Looks good to me, approved Benny Siegert: Looks good to me, but someone else must approve
        net/http: remove Content-Encoding in writeNotModified

        Additional header to remove if set before calling http.ServeContent.

        The API of ServeContent is that one should set Content-Encoding before calling it, if the content is encoded (e.g., compressed). But then, if content has not been modified, that header should be removed, according to RFC 7232 section 4.1.

        Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
        GitHub-Last-Rev: 53df6e73c44b63f351f7aeeb45cab82d706311eb
        GitHub-Pull-Request: golang/go#50903
        Reviewed-on: https://go-review.googlesource.com/c/go/+/381955
        Run-TryBot: hopehook <hope...@qq.com>
        Reviewed-by: Damien Neil <dn...@google.com>
        TryBot-Result: Gopher Robot <go...@golang.org>
        Reviewed-by: Benny Siegert <bsie...@gmail.com>

        ---
        M src/net/http/fs.go
        M src/net/http/fs_test.go
        2 files changed, 75 insertions(+), 0 deletions(-)

        diff --git a/src/net/http/fs.go b/src/net/http/fs.go
        index 7a1d5f4..4f144eb 100644

        --- a/src/net/http/fs.go
        +++ b/src/net/http/fs.go
        @@ -541,6 +541,7 @@
        h := w.Header()
        delete(h, "Content-Type")
        delete(h, "Content-Length")
        + delete(h, "Content-Encoding")
        if h.Get("Etag") != "" {
        delete(h, "Last-Modified")
        }
        diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go
        index d627dfd..4be561c 100644
        --- a/src/net/http/fs_test.go
        +++ b/src/net/http/fs_test.go
        @@ -564,6 +564,60 @@
        }
        }

        +// Tests that ServeFile does not generate representation metadata when
        +// file has not been modified, as per RFC 7232 section 4.1.
        +func TestServeFileNotModified_h1(t *testing.T) { testServeFileNotModified(t, h1Mode) }
        +func TestServeFileNotModified_h2(t *testing.T) { testServeFileNotModified(t, h2Mode) }
        +func testServeFileNotModified(t *testing.T, h2 bool) {
        + defer afterTest(t)
        + cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
        + w.Header().Set("Content-Type", "application/json")
        + w.Header().Set("Content-Encoding", "foo")
        + w.Header().Set("Etag", `"123"`)
        + ServeFile(w, r, "testdata/file")
        +
        + // Because the testdata is so small, it would fit in
        + // both the h1 and h2 Server's write buffers. For h1,
        + // sendfile is used, though, forcing a header flush at
        + // the io.Copy. http2 doesn't do a header flush so
        + // buffers all 11 bytes and then adds its own
        + // Content-Length. To prevent the Server's
        + // Content-Length and test ServeFile only, flush here.
        + w.(Flusher).Flush()
        + }))
        + defer cst.close()
        + req, err := NewRequest("GET", cst.ts.URL, nil)
        + if err != nil {
        + t.Fatal(err)
        + }
        + req.Header.Set("If-None-Match", `"123"`)
        + resp, err := cst.c.Do(req)
        + if err != nil {
        + t.Fatal(err)
        + }
        + b, err := io.ReadAll(resp.Body)
        + resp.Body.Close()
        + if err != nil {
        + t.Fatal("reading Body:", err)
        + }
        + if len(b) != 0 {
        + t.Errorf("non-empty body")
        + }
        + if g, e := resp.StatusCode, StatusNotModified; g != e {
        + t.Errorf("status mismatch: got %d, want %d", g, e)
        + }
        + // HTTP1 transport sets ContentLength to 0.
        + if g, e1, e2 := resp.ContentLength, int64(-1), int64(0); g != e1 && g != e2 {
        + t.Errorf("Content-Length mismatch: got %d, want %d or %d", g, e1, e2)
        + }
        + if resp.Header.Get("Content-Type") != "" {
        + t.Errorf("Content-Type present, but it should not be")
        + }
        + if resp.Header.Get("Content-Encoding") != "" {
        + t.Errorf("Content-Encoding present, but it should not be")
        + }
        +}
        +
        func TestServeIndexHtml(t *testing.T) {
        defer afterTest(t)


        To view, visit change 381955. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: If51b35b7811a4dbb19de2ddb73f40c5e68fcec7e
        Gerrit-Change-Number: 381955
        Gerrit-PatchSet: 11
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Benny Siegert <bsie...@gmail.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@tailscale.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Damien Neil <dn...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: hopehook <hope...@qq.com>
        Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-CC: Mitar <mmi...@gmail.com>
        Gerrit-CC: Russ Cox <r...@golang.org>
        Gerrit-MessageType: merged
        Reply all
        Reply to author
        Forward
        0 new messages