Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bitswap/network/httpnet/httpnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ func New(host host.Host, opts ...Option) network.BitSwapNetwork {

c := &http.Client{
Transport: t,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
// we do not follow redirects. Providers should keep
// announcements up to
// date. https://github.com/boxo/issues/862.
return http.ErrUseLastResponse
},
}
htnet.client = c

Expand Down
8 changes: 7 additions & 1 deletion bitswap/network/httpnet/msg_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm

return nil, serr
}
defer resp.Body.Close()

// Record request size
var buf bytes.Buffer
Expand Down Expand Up @@ -302,7 +303,12 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm
case http.StatusNotFound,
http.StatusGone,
http.StatusForbidden,
http.StatusUnavailableForLegalReasons:
http.StatusUnavailableForLegalReasons,
http.StatusMovedPermanently,
http.StatusFound,
http.StatusSeeOther,
http.StatusTemporaryRedirect,
http.StatusPermanentRedirect:

err := fmt.Errorf("%s %q -> %d: %q", req.Method, req.URL, statusCode, string(body))
log.Debug(err)
Expand Down
Loading