Skip to content

Commit

Permalink
Use PUT as method to insert provider records
Browse files Browse the repository at this point in the history
Change the implementation of HTTP delegated routing provider records to
match the IPIP-337 specification. The specification was changed to use
`PUT`.

Close request body after decoding when handling provide.
  • Loading branch information
masih committed Jan 27, 2023
1 parent 38b7ae8 commit cc954f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion routing/http/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (c *client) provideSignedBitswapRecord(ctx context.Context, bswp *types.Wri
return 0, err
}

httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(b))
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPut, url, bytes.NewBuffer(b))
if err != nil {
return 0, err
}
Expand Down
5 changes: 3 additions & 2 deletions routing/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func Handler(svc ContentRouter, opts ...serverOption) http.Handler {
}

r := mux.NewRouter()
r.HandleFunc(ProvidePath, server.provide).Methods("POST")
r.HandleFunc(FindProvidersPath, server.findProviders).Methods("GET")
r.HandleFunc(ProvidePath, server.provide).Methods(http.MethodPut)
r.HandleFunc(FindProvidersPath, server.findProviders).Methods(http.MethodGet)

return r
}
Expand All @@ -70,6 +70,7 @@ type server struct {
func (s *server) provide(w http.ResponseWriter, httpReq *http.Request) {
req := types.WriteProvidersRequest{}
err := json.NewDecoder(httpReq.Body).Decode(&req)
_ = httpReq.Body.Close()
if err != nil {
writeErr(w, "Provide", http.StatusBadRequest, fmt.Errorf("invalid request: %w", err))
return
Expand Down

0 comments on commit cc954f1

Please sign in to comment.