Skip to content

Commit

Permalink
fix Bucket to have http.Header and Body
Browse files Browse the repository at this point in the history
  • Loading branch information
Jxck committed Jul 14, 2015
1 parent 48bbbbe commit f7445be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
12 changes: 1 addition & 11 deletions server.go
Expand Up @@ -75,6 +75,7 @@ func HandleTLSConnection(conn net.Conn, handler http.Handler) {
func HandlerCallBack(handler http.Handler) CallBack {
return func(stream *Stream) {
header := stream.Bucket.Headers
body := stream.Bucket.Body

authority := header.Get(":authority")
method := header.Get(":method")
Expand All @@ -92,17 +93,6 @@ func HandlerCallBack(handler http.Handler) CallBack {
Fatal("%v", err)
}

// request body がある場合
body := new(Body)
if len(stream.Bucket.Data) != 0 {
for _, data := range stream.Bucket.Data {
_, err := body.Write(data.Data)
if err != nil {
Fatal("%v", err)
}
}
}

req := &http.Request{
Method: method,
URL: url,
Expand Down
10 changes: 7 additions & 3 deletions stream.go
Expand Up @@ -28,13 +28,13 @@ type Stream struct {

type Bucket struct {
Headers http.Header
Data []*DataFrame
Body *Body
}

func NewBucket() *Bucket {
return &Bucket{
Headers: make(http.Header),
Data: make([]*DataFrame, 0),
Body: new(Body),
}
}

Expand Down Expand Up @@ -79,7 +79,11 @@ func (stream *Stream) Read(f Frame) {
case *DataFrame:
length := int32(frame.Header().Length)
stream.WindowUpdate(length)
stream.Bucket.Data = append(stream.Bucket.Data, frame)

_, err := stream.Bucket.Body.Write(frame.Data)
if err != nil {
Fatal("%v", err)
}

if frame.Header().Flags&END_STREAM == END_STREAM {
stream.CallBack(stream)
Expand Down
9 changes: 1 addition & 8 deletions transport.go
@@ -1,7 +1,6 @@
package http2

import (
"bytes"
"crypto/tls"
"fmt"
. "github.com/Jxck/color"
Expand Down Expand Up @@ -121,13 +120,7 @@ func TransportCallBack(req *http.Request) (CallBack, chan *http.Response) {
response := make(chan *http.Response)
return func(stream *Stream) {

var data bytes.Buffer
for _, dataFrame := range stream.Bucket.Data {
data.Write(dataFrame.Data)
}

body := &Body{data}

body := stream.Bucket.Body
headers := stream.Bucket.Headers

status, _ := strconv.Atoi(headers.Get(":status")) // err
Expand Down

0 comments on commit f7445be

Please sign in to comment.