Skip to content

Commit

Permalink
Use request context in p2p stream http proxy
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Ian Preston <ianopolous@protonmail.com>
  • Loading branch information
ianopolous committed Oct 3, 2018
1 parent fe6ba82 commit 199d25e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,10 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error
defaultMux("/debug/pprof/"),
corehttp.MetricsScrapingOption("/debug/metrics/prometheus"),
corehttp.LogOption(),
corehttp.ProxyOption(),
}

if cfg.Experimental.Libp2pHttpProxy {
opts = append(opts, corehttp.ProxyOption())
}

if len(cfg.Gateway.RootRedirect) > 0 {
Expand Down
6 changes: 3 additions & 3 deletions core/corehttp/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package corehttp
import (
"bufio"
"fmt"
"net"
"io"
"net"
"net/http"
"net/http/httputil"
"strings"
Expand All @@ -28,7 +28,7 @@ func ProxyOption() ServeOption {
}

// open connect to peer
stream, err := ipfsNode.P2P.PeerHost.NewStream(ipfsNode.Context(), parsedRequest.target, protocol.ID("/x/"+parsedRequest.name))
stream, err := ipfsNode.P2P.PeerHost.NewStream(request.Context(), parsedRequest.target, protocol.ID("/x/"+parsedRequest.name))
if err != nil {
msg := fmt.Sprintf("Failed to open stream '%v' to target peer '%v'", parsedRequest.name, parsedRequest.target)
handleError(w, msg, err, 500)
Expand Down Expand Up @@ -121,7 +121,7 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {

resp.Body = &respBody{
ReadCloser: resp.Body,
stream: rt.stream,
stream: rt.stream,
}

return resp, nil
Expand Down

0 comments on commit 199d25e

Please sign in to comment.