Skip to content

Commit cc954f1

Browse files
committed
Use PUT as method to insert provider records
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.
1 parent 38b7ae8 commit cc954f1

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

routing/http/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (c *client) provideSignedBitswapRecord(ctx context.Context, bswp *types.Wri
211211
return 0, err
212212
}
213213

214-
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(b))
214+
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPut, url, bytes.NewBuffer(b))
215215
if err != nil {
216216
return 0, err
217217
}

routing/http/server/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func Handler(svc ContentRouter, opts ...serverOption) http.Handler {
5757
}
5858

5959
r := mux.NewRouter()
60-
r.HandleFunc(ProvidePath, server.provide).Methods("POST")
61-
r.HandleFunc(FindProvidersPath, server.findProviders).Methods("GET")
60+
r.HandleFunc(ProvidePath, server.provide).Methods(http.MethodPut)
61+
r.HandleFunc(FindProvidersPath, server.findProviders).Methods(http.MethodGet)
6262

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

0 commit comments

Comments
 (0)