From d1509d7e839265bd36747fd4d85955f8ffcfa28e Mon Sep 17 00:00:00 2001 From: Janos Guljas Date: Wed, 13 Dec 2017 14:01:00 +0100 Subject: [PATCH] swarm/api: completely remove bzzr and bzzi schemes Remove old schemes in favour of bzz-raw and bzz-immutable. --- swarm/api/api.go | 2 +- swarm/api/http/server.go | 8 ++++---- swarm/api/uri.go | 16 +--------------- swarm/api/uri_test.go | 40 ++++++---------------------------------- 4 files changed, 12 insertions(+), 54 deletions(-) diff --git a/swarm/api/api.go b/swarm/api/api.go index 8c4bca2ec0..79de29a1cf 100644 --- a/swarm/api/api.go +++ b/swarm/api/api.go @@ -83,7 +83,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) } diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go index 3872cbc4f0..3a689b9bf8 100644 --- a/swarm/api/http/server.go +++ b/swarm/api/http/server.go @@ -592,7 +592,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { switch r.Method { case "POST": - if uri.Raw() || uri.DeprecatedRaw() { + if uri.Raw() { s.HandlePostRaw(w, req) } else { s.HandlePostFiles(w, req) @@ -604,7 +604,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // 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() { + if uri.Raw() { ShowError(w, r, fmt.Sprintf("No PUT to %s allowed.", uri), http.StatusBadRequest) return } else { @@ -612,14 +612,14 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } case "DELETE": - if uri.Raw() || uri.DeprecatedRaw() { + if uri.Raw() { ShowError(w, r, fmt.Sprintf("No DELETE to %s allowed.", uri), http.StatusBadRequest) return } s.HandleDelete(w, req) case "GET": - if uri.Raw() || uri.DeprecatedRaw() { + if uri.Raw() { s.HandleGetRaw(w, req) return } diff --git a/swarm/api/uri.go b/swarm/api/uri.go index af1dc74453..ce64ef0882 100644 --- a/swarm/api/uri.go +++ b/swarm/api/uri.go @@ -31,11 +31,6 @@ type URI struct { // * bzz-immutable - immutable URI of an entry in a swarm manifest // (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) Scheme string // Addr is either a hexadecimal storage key or it an address which @@ -57,7 +52,6 @@ type URI struct { // * :/// // // with scheme one of bzz, bzz-raw, bzz-immutable or bzz-list -// or deprecated ones bzzr and bzzi func Parse(rawuri string) (*URI, error) { u, err := url.Parse(rawuri) if err != nil { @@ -67,7 +61,7 @@ func Parse(rawuri string) (*URI, error) { // check the scheme is valid switch uri.Scheme { - case "bzz", "bzz-raw", "bzz-immutable", "bzz-list", "bzzr", "bzzi": + case "bzz", "bzz-raw", "bzz-immutable", "bzz-list": default: return nil, fmt.Errorf("unknown scheme %q", u.Scheme) } @@ -102,14 +96,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) String() string { return u.Scheme + ":/" + u.Addr + "/" + u.Path } diff --git a/swarm/api/uri_test.go b/swarm/api/uri_test.go index babb2834e9..b4211a28f3 100644 --- a/swarm/api/uri_test.go +++ b/swarm/api/uri_test.go @@ -23,14 +23,12 @@ import ( func TestParseURI(t *testing.T) { type test struct { - uri string - expectURI *URI - expectErr bool - expectRaw bool - expectImmutable bool - expectList bool - expectDeprecatedRaw bool - expectDeprecatedImmutable bool + uri string + expectURI *URI + expectErr bool + expectRaw bool + expectImmutable bool + expectList bool } tests := []test{ { @@ -108,26 +106,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) @@ -152,11 +130,5 @@ func TestParseURI(t *testing.T) { if actual.List() != x.expectList { t.Fatalf("expected %s list to be %t, got %t", x.uri, x.expectList, actual.List()) } - 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()) - } } }