transport: set Response.Status[Code]
diff --git a/transport.go b/transport.go
index 708bcd5..2dd7848 100644
--- a/transport.go
+++ b/transport.go
@@ -15,6 +15,7 @@
"log"
"net"
"net/http"
+ "strconv"
"strings"
"sync"
@@ -44,7 +45,7 @@
hdec *hpack.Decoder
- nextRes http.Header
+ nextRes *http.Response
// Settings from peer:
maxFrameSize uint32
@@ -276,7 +277,13 @@
}
switch f := f.(type) {
case *HeadersFrame:
- cc.nextRes = make(http.Header)
+ cc.nextRes = &http.Response{
+ Proto: "HTTP/2.0",
+ ProtoMajor: 2,
+ Header: make(http.Header),
+ Request: nil, // TODO: set this
+ TLS: nil, // TODO: set this
+ }
cs.pr, cs.pw = io.Pipe()
cc.hdec.Write(f.HeaderBlockFragment())
headersEnded = f.HeadersEnded()
@@ -296,15 +303,29 @@
if cs == nil {
panic("couldn't find stream") // TODO be graceful
}
- cs.resc <- &http.Response{
- Header: cc.nextRes,
- Body: cs.pr,
- }
+ cc.nextRes.Body = cs.pr
+ cs.resc <- cc.nextRes
}
}
}
func (cc *clientConn) onNewHeaderField(f hpack.HeaderField) {
+ // TODO: verifiy pseudo headers come before non-pseudo headers
+ // TODO: verifiy the status is set
log.Printf("Header field: %+v", f)
- cc.nextRes.Add(http.CanonicalHeaderKey(f.Name), f.Value)
+ if f.Name == ":status" {
+ code, err := strconv.Atoi(f.Value)
+ if err != nil {
+ panic("TODO: be graceful")
+ }
+ cc.nextRes.Status = f.Value + " " + http.StatusText(code)
+ cc.nextRes.StatusCode = code
+ return
+ }
+ if strings.HasPrefix(f.Name, ":") {
+ // "Endpoints MUST NOT generate pseudo-header fields other than those defined in this document."
+ // TODO: treat as invalid?
+ return
+ }
+ cc.nextRes.Header.Add(http.CanonicalHeaderKey(f.Name), f.Value)
}
diff --git a/transport_test.go b/transport_test.go
index f3de64f..67168f9 100644
--- a/transport_test.go
+++ b/transport_test.go
@@ -36,11 +36,7 @@
}
func TestTransport(t *testing.T) {
- condSkipFailingTest(t)
-
- VerboseLogs = true
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
- println("in handler")
io.WriteString(w, "sup")
})
defer st.Close()