Skip to content

Commit

Permalink
Merge pull request #42 from ipni/remove-unneeded-code
Browse files Browse the repository at this point in the history
Remove unneeded code
  • Loading branch information
gammazero authored Jul 19, 2023
2 parents e965cdd + 8daf26e commit 6618c07
Showing 1 changed file with 0 additions and 16 deletions.
16 changes: 0 additions & 16 deletions caskadht.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package caskadht
import (
"context"
"errors"
"io"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -124,10 +123,8 @@ func (c *Caskadht) serveMux() *http.ServeMux {
func (c *Caskadht) handleMh(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodOptions:
discardBody(r)
c.handleLookupOptions(w)
default:
discardBody(r)
http.Error(w, "", http.StatusNotFound)
}
}
Expand Down Expand Up @@ -161,10 +158,8 @@ func (c *Caskadht) handleMhSubtree(w http.ResponseWriter, r *http.Request) {
}
c.handleLookup(rwriter.NewProviderResponseWriter(rspWriter), r)
case http.MethodOptions:
discardBody(r)
c.handleLookupOptions(w)
default:
discardBody(r)
http.Error(w, "", http.StatusNotFound)
}
}
Expand All @@ -185,13 +180,10 @@ func (c *Caskadht) handleRoutingV1ProvidersSubtree(w http.ResponseWriter, r *htt
}
c.handleDrLookup(drWriter, r)
case http.MethodOptions:
discardBody(r)
c.handleLookupOptions(w)
case http.MethodPut:
discardBody(r)
http.Error(w, "", http.StatusNotImplemented)
default:
discardBody(r)
http.Error(w, "", http.StatusNotFound)
}
}
Expand Down Expand Up @@ -385,7 +377,6 @@ func (c *Caskadht) handleLookupOptions(w http.ResponseWriter) {
}

func (c *Caskadht) handleReady(w http.ResponseWriter, r *http.Request) {
discardBody(r)
switch r.Method {
case http.MethodGet:
w.WriteHeader(http.StatusOK)
Expand All @@ -395,12 +386,10 @@ func (c *Caskadht) handleReady(w http.ResponseWriter, r *http.Request) {
}

func (c *Caskadht) handleCatchAll(w http.ResponseWriter, r *http.Request) {
discardBody(r)
http.Error(w, "", http.StatusNotFound)
}

func (c *Caskadht) Shutdown(ctx context.Context) error {

sErr := c.s.Shutdown(ctx)
_ = c.std.Close()
if c.acc != nil {
Expand All @@ -415,8 +404,3 @@ func (c *Caskadht) Shutdown(ctx context.Context) error {
return hErr
}
}

func discardBody(r *http.Request) {
_, _ = io.Copy(io.Discard, r.Body)
_ = r.Body.Close()
}

0 comments on commit 6618c07

Please sign in to comment.