Skip to content

ResponseWriter optional interfaces #216

Description

@phillebaba

The current implementation of the standard lib implementation uses a wrapper of the response writer to capture status and other information. While it does conform to the interfaces required function it does not implement optional interfaces which are useful. As the this is run as a middleware before any handlers it means that all handlers will receive the wrapped response writer which as well.

This has the most noticeable impact when using io copy to write from a reader, as a zero copy system call will not be used. Instead Go will fallback to using an in memory buffer instead.

It is not the most logical side effect, and it is pretty easy to miss as the response writer is hidden and itself does not do a good job documenting the additional optional interfaces.

Here is a good blog post that explains the issue well.
https://avtok.com/2014/11/05/interface-upgrades.html

My suggestion is that we implement the ReadFrom function on the response writer so that io copy will work more efficiently for all users who may not be aware of the issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions