Skip to content

http.ReverseProxy should sometimes flush eagerly #2012

@gopherbot

Description

@gopherbot

by trevor.strohman:

http.ReverseProxy buffers writes (because
of NewReadWriter in http/server.go).  This can break server-push
applications where the client is expected to read pieces of the
response as they arrive.

Currently ReverseProxy.ServeHTTP does this:
  if res.Body != nil {
    io.Copy(rw, res.Body)
  }
the buffering is built into the rw.  To add flushing you'd need something like:
  for {
    nr, err := res.Body.Read(buf)
    if err != nil { return err }
    rw.Write(buf[0:nr])
    rw.(http.Flusher).Flush()
  }

Brad remarks that buffering is usually good so this hurts the common case, and perhaps
this should be an parameter setting, or perhaps the Copy function itself could be a
parameter.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions