Skip to content

Commit

Permalink
[http_proxy_over_p2p] proxy async.
Browse files Browse the repository at this point in the history
Simultaneously send request-body while reading response-body when
proxying requests.

License: MIT
Signed-off-by: Chris Boddy <chris@boddy.im>
  • Loading branch information
cboddy committed Oct 2, 2018
1 parent 72105f3 commit 9f6e044
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions core/corehttp/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ProxyOption() ServeOption {
handleError(w, msg, err, 500)
return
}

//send proxy request and response to client
newReverseHttpProxy(parsedRequest, &stream).ServeHTTP(w, request)
})
return mux, nil
Expand Down Expand Up @@ -86,7 +86,18 @@ type roundTripper struct {
}

func (self *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
req.Write(*self.stream)

sendRequest := func() {
err := req.Write(*self.stream)
if err != nil {
(*(self.stream)).Close()
}
if req.Body != nil {
req.Body.Close()
}
}
//send request while reading response
go sendRequest()
s := bufio.NewReader(*self.stream)
return http.ReadResponse(s, req)
}

0 comments on commit 9f6e044

Please sign in to comment.