Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailer support #11

Closed
cstrahan opened this issue Jul 7, 2016 · 4 comments
Closed

Trailer support #11

cstrahan opened this issue Jul 7, 2016 · 4 comments

Comments

@cstrahan
Copy link

cstrahan commented Jul 7, 2016

After a cursory study of the API, I'm not sure how to send Trailers (assuming there currently is support). I'd like to implement a gRPC library for Haskell, and the protocol requires support for reading and sending trailers. In Go, this might look something like (from the docs):

package main

import (
    "io"
    "net/http"
)

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/sendstrailers", func(w http.ResponseWriter, req *http.Request) {
        // Before any call to WriteHeader or Write, declare
        // the trailers you will set during the HTTP
        // response. These three headers are actually sent in
        // the trailer.
        w.Header().Set("Trailer", "AtEnd1, AtEnd2")
        w.Header().Add("Trailer", "AtEnd3")

        w.Header().Set("Content-Type", "text/plain; charset=utf-8") // normal header
        w.WriteHeader(http.StatusOK)

        w.Header().Set("AtEnd1", "value 1")
        io.WriteString(w, "This HTTP response has both headers before this text and trailers at the end.\n")
        w.Header().Set("AtEnd2", "value 2")
        w.Header().Set("AtEnd3", "value 3") // These will appear as trailers.
    })
}

There's also a TrailerPrefix constant:

const TrailerPrefix = "Trailer:"

TrailerPrefix is a magic prefix for ResponseWriter.Header map keys that, if present, signals that the map entry is actually for the response trailers, and not the response headers. The prefix is stripped after the ServeHTTP call finishes and the values are sent in the trailers.

This mechanism is intended only for trailers that are not known prior to the headers being written. If the set of trailers is fixed or known before the header is written, the normal Go trailers mechanism is preferred:

Does this library support sending Trailers, and if so, would you mind pointing me in the right direction, please?

@cstrahan
Copy link
Author

cstrahan commented Jul 7, 2016

Oh, I realize now that I probably want to be looking in wai...

@cstrahan
Copy link
Author

cstrahan commented Jul 7, 2016

Yep, wasn't looking hard enough -- my apologies!

https://hackage.haskell.org/package/wai-3.0.5.0/docs/Network-Wai-HTTP2.html

@cstrahan cstrahan closed this as completed Jul 7, 2016
@kazu-yamamoto
Copy link
Owner

Yes, it's Warp's job. Unfortunately, however, you are looking at obsoleted Wai/Warp code.

Currently, trailers are not supported. Please open an issue here: https://github.com/yesodweb/wai/issues
And let's discuss what kind of APIs are necessary.

Also, please give a look at this article: http://www.yesodweb.com/blog/2016/07/http2-server-push

It's nice if we can extend HTTP2Data to support trailers.

@cstrahan
Copy link
Author

cstrahan commented Jul 7, 2016

@kazu-yamamoto Thanks - I've opened an issue here: yesodweb/wai#566

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

No branches or pull requests

2 participants