Skip to content

Commit

Permalink
swarm/api/http: removed deprecated PUT apis (ethereum#443)
Browse files Browse the repository at this point in the history
- removed deprecated PUT apis
  • Loading branch information
acud authored Apr 29, 2018
1 parent 5f78ba2 commit 876134d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 59 deletions.
2 changes: 1 addition & 1 deletion swarm/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (self *Api) Resolve(uri *URI) (storage.Key, error) {

// if the URI is immutable, check if the address is a hash
isHash := hashMatcher.MatchString(uri.Addr)
if uri.Immutable() || uri.DeprecatedImmutable() {
if uri.Immutable() {
if !isHash {
return nil, fmt.Errorf("immutable address not a content hash: %q", uri.Addr)
}
Expand Down
23 changes: 7 additions & 16 deletions swarm/api/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *Server) HandlePostRaw(w http.ResponseWriter, r *Request) {
fmt.Fprint(w, key)
}

// HandlePostFiles handles a POST request (or deprecated PUT request) to
// HandlePostFiles handles a POST request to
// bzz:/<hash>/<path> which contains either a single file or multiple files
// (either a tar archive or multipart form), adds those files either to an
// existing manifest or to a new manifest under <path> and returns the
Expand Down Expand Up @@ -593,7 +593,7 @@ func (s *Server) HandleGet(w http.ResponseWriter, r *Request) {
w.Header().Set("X-Decrypted", fmt.Sprintf("%v", isEncrypted))

switch {
case r.uri.Raw() || r.uri.DeprecatedRaw():
case r.uri.Raw():
// allow the request to overwrite the content type using a query
// parameter
contentType := "application/octet-stream"
Expand Down Expand Up @@ -902,7 +902,7 @@ func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request) {

switch r.Method {
case "POST":
if uri.Raw() || uri.DeprecatedRaw() {
if uri.Raw() {
log.Debug("handlePostRaw")
s.HandlePostRaw(w, req)
} else if uri.Resource() {
Expand All @@ -914,20 +914,11 @@ func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
}

case "PUT":
// DEPRECATED:
// clients should send a POST request (the request creates a
// new manifest leaving the existing one intact, so it isn't
// strictly a traditional PUT request which replaces content
// at a URI, and POST is more ubiquitous)
if uri.Raw() || uri.DeprecatedRaw() {
Respond(w, req, fmt.Sprintf("PUT method to %s not allowed", uri), http.StatusBadRequest)
return
} else {
s.HandlePostFiles(w, req)
}
Respond(w, req, fmt.Sprintf("PUT method to %s not allowed", uri), http.StatusBadRequest)
return

case "DELETE":
if uri.Raw() || uri.DeprecatedRaw() {
if uri.Raw() {
Respond(w, req, fmt.Sprintf("DELETE method to %s not allowed", uri), http.StatusBadRequest)
return
}
Expand All @@ -940,7 +931,7 @@ func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
return
}

if uri.Raw() || uri.Hash() || uri.DeprecatedRaw() {
if uri.Raw() || uri.Hash() {
s.HandleGet(w, req)
return
}
Expand Down
17 changes: 1 addition & 16 deletions swarm/api/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ type URI struct {
// (address is not resolved)
// * bzz-list - list of all files contained in a swarm manifest
//
// Deprecated Schemes:
// * bzzr - raw swarm content
// * bzzi - immutable URI of an entry in a swarm manifest
// (address is not resolved)
// * bzz-hash - hash of swarm content
//
Scheme string

// Addr is either a hexadecimal storage key or it an address which
Expand All @@ -59,7 +53,6 @@ type URI struct {
// * <scheme>://<addr>/<path>
//
// with scheme one of bzz, bzz-raw, bzz-immutable, bzz-list or bzz-hash
// or deprecated ones bzzr and bzzi
func Parse(rawuri string) (*URI, error) {
u, err := url.Parse(rawuri)
if err != nil {
Expand All @@ -69,7 +62,7 @@ func Parse(rawuri string) (*URI, error) {

// check the scheme is valid
switch uri.Scheme {
case "bzz", "bzz-raw", "bzz-immutable", "bzz-list", "bzz-hash", "bzzr", "bzzi", "bzz-resource":
case "bzz", "bzz-raw", "bzz-immutable", "bzz-list", "bzz-hash", "bzz-resource":
default:
return nil, fmt.Errorf("unknown scheme %q", u.Scheme)
}
Expand Down Expand Up @@ -108,14 +101,6 @@ func (u *URI) List() bool {
return u.Scheme == "bzz-list"
}

func (u *URI) DeprecatedRaw() bool {
return u.Scheme == "bzzr"
}

func (u *URI) DeprecatedImmutable() bool {
return u.Scheme == "bzzi"
}

func (u *URI) Hash() bool {
return u.Scheme == "bzz-hash"
}
Expand Down
26 changes: 0 additions & 26 deletions swarm/api/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,6 @@ func TestParseURI(t *testing.T) {
expectURI: &URI{Scheme: "bzz-list"},
expectList: true,
},
{
uri: "bzzr:",
expectURI: &URI{Scheme: "bzzr"},
expectDeprecatedRaw: true,
},
{
uri: "bzzr:/",
expectURI: &URI{Scheme: "bzzr"},
expectDeprecatedRaw: true,
},
{
uri: "bzzi:",
expectURI: &URI{Scheme: "bzzi"},
expectDeprecatedImmutable: true,
},
{
uri: "bzzi:/",
expectURI: &URI{Scheme: "bzzi"},
expectDeprecatedImmutable: true,
},
}
for _, x := range tests {
actual, err := Parse(x.uri)
Expand Down Expand Up @@ -166,11 +146,5 @@ func TestParseURI(t *testing.T) {
if actual.Hash() != x.expectHash {
t.Fatalf("expected %s hash to be %t, got %t", x.uri, x.expectHash, actual.Hash())
}
if actual.DeprecatedRaw() != x.expectDeprecatedRaw {
t.Fatalf("expected %s deprecated raw to be %t, got %t", x.uri, x.expectDeprecatedRaw, actual.DeprecatedRaw())
}
if actual.DeprecatedImmutable() != x.expectDeprecatedImmutable {
t.Fatalf("expected %s deprecated immutable to be %t, got %t", x.uri, x.expectDeprecatedImmutable, actual.DeprecatedImmutable())
}
}
}

0 comments on commit 876134d

Please sign in to comment.