Skip to content

proposal: add a Size field to http.Request #19644

Closed
@joshi4

Description

@joshi4

I'm trying to add a metric that measures the total size of the request in bytes on the wire as received by the server(headers + body + trailer). This does not seem possible at the moment.

I propose we add a Size field to http.Request that behaves similar to the Trailer field.

type Request struct {
  // Size is the total bytes of the Request including headers, body and
  // trailers. 
  // 
  // For server requests Size is initially zero. While the handler is 
  // reading from Body, it must not reference Size. After reading from Body 
  // returns EOF, Size can be read and will contain the total bytes of the
  // Request including headers, body and trailers. 
  //
  // For client requests Size is always set to zero. 
  Size int64 
}

Activity

added this to the Proposal milestone on Mar 21, 2017
bradfitz

bradfitz commented on Mar 21, 2017

@bradfitz
Contributor

Sorry, I'm going to decline this.

I've had to deal with implementing this for logging several times. Everybody means something different in how exactly you calculate this and anything we add is going to be insufficient for somebody else. Do you count http2 frame sizes? Or only the payload size? Before or after compression? Before or after whitespace normalization? Before or after header folding? etc.

If anything, this can be addressed in the httptrace package. Currently httptrace only has ClientTrace, but in #18997 people are discussing ServerTrace hooks. That's the right place for low-level disgusting detail where we don't care about godoc pollution. And we could add numbers and hooks for all the possible things you might care about.

locked and limited conversation to collaborators on Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bradfitz@joshi4@gopherbot

        Issue actions

          proposal: add a Size field to http.Request · Issue #19644 · golang/go