mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
swarm/api: completely remove bzzr and bzzi schemes
Remove old schemes in favour of bzz-raw and bzz-immutable.
This commit is contained in:
parent
52693520cc
commit
d1509d7e83
4 changed files with 12 additions and 54 deletions
|
|
@ -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
|
// if the URI is immutable, check if the address is a hash
|
||||||
isHash := hashMatcher.MatchString(uri.Addr)
|
isHash := hashMatcher.MatchString(uri.Addr)
|
||||||
if uri.Immutable() || uri.DeprecatedImmutable() {
|
if uri.Immutable() {
|
||||||
if !isHash {
|
if !isHash {
|
||||||
return nil, fmt.Errorf("immutable address not a content hash: %q", uri.Addr)
|
return nil, fmt.Errorf("immutable address not a content hash: %q", uri.Addr)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -592,7 +592,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "POST":
|
case "POST":
|
||||||
if uri.Raw() || uri.DeprecatedRaw() {
|
if uri.Raw() {
|
||||||
s.HandlePostRaw(w, req)
|
s.HandlePostRaw(w, req)
|
||||||
} else {
|
} else {
|
||||||
s.HandlePostFiles(w, req)
|
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
|
// new manifest leaving the existing one intact, so it isn't
|
||||||
// strictly a traditional PUT request which replaces content
|
// strictly a traditional PUT request which replaces content
|
||||||
// at a URI, and POST is more ubiquitous)
|
// 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)
|
ShowError(w, r, fmt.Sprintf("No PUT to %s allowed.", uri), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -612,14 +612,14 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
if uri.Raw() || uri.DeprecatedRaw() {
|
if uri.Raw() {
|
||||||
ShowError(w, r, fmt.Sprintf("No DELETE to %s allowed.", uri), http.StatusBadRequest)
|
ShowError(w, r, fmt.Sprintf("No DELETE to %s allowed.", uri), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.HandleDelete(w, req)
|
s.HandleDelete(w, req)
|
||||||
|
|
||||||
case "GET":
|
case "GET":
|
||||||
if uri.Raw() || uri.DeprecatedRaw() {
|
if uri.Raw() {
|
||||||
s.HandleGetRaw(w, req)
|
s.HandleGetRaw(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,6 @@ type URI struct {
|
||||||
// * bzz-immutable - immutable URI of an entry in a swarm manifest
|
// * bzz-immutable - immutable URI of an entry in a swarm manifest
|
||||||
// (address is not resolved)
|
// (address is not resolved)
|
||||||
// * bzz-list - list of all files contained in a swarm manifest
|
// * 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
|
Scheme string
|
||||||
|
|
||||||
// Addr is either a hexadecimal storage key or it an address which
|
// Addr is either a hexadecimal storage key or it an address which
|
||||||
|
|
@ -57,7 +52,6 @@ type URI struct {
|
||||||
// * <scheme>://<addr>/<path>
|
// * <scheme>://<addr>/<path>
|
||||||
//
|
//
|
||||||
// with scheme one of bzz, bzz-raw, bzz-immutable or bzz-list
|
// with scheme one of bzz, bzz-raw, bzz-immutable or bzz-list
|
||||||
// or deprecated ones bzzr and bzzi
|
|
||||||
func Parse(rawuri string) (*URI, error) {
|
func Parse(rawuri string) (*URI, error) {
|
||||||
u, err := url.Parse(rawuri)
|
u, err := url.Parse(rawuri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -67,7 +61,7 @@ func Parse(rawuri string) (*URI, error) {
|
||||||
|
|
||||||
// check the scheme is valid
|
// check the scheme is valid
|
||||||
switch uri.Scheme {
|
switch uri.Scheme {
|
||||||
case "bzz", "bzz-raw", "bzz-immutable", "bzz-list", "bzzr", "bzzi":
|
case "bzz", "bzz-raw", "bzz-immutable", "bzz-list":
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown scheme %q", u.Scheme)
|
return nil, fmt.Errorf("unknown scheme %q", u.Scheme)
|
||||||
}
|
}
|
||||||
|
|
@ -102,14 +96,6 @@ func (u *URI) List() bool {
|
||||||
return u.Scheme == "bzz-list"
|
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 {
|
func (u *URI) String() string {
|
||||||
return u.Scheme + ":/" + u.Addr + "/" + u.Path
|
return u.Scheme + ":/" + u.Addr + "/" + u.Path
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,12 @@ import (
|
||||||
|
|
||||||
func TestParseURI(t *testing.T) {
|
func TestParseURI(t *testing.T) {
|
||||||
type test struct {
|
type test struct {
|
||||||
uri string
|
uri string
|
||||||
expectURI *URI
|
expectURI *URI
|
||||||
expectErr bool
|
expectErr bool
|
||||||
expectRaw bool
|
expectRaw bool
|
||||||
expectImmutable bool
|
expectImmutable bool
|
||||||
expectList bool
|
expectList bool
|
||||||
expectDeprecatedRaw bool
|
|
||||||
expectDeprecatedImmutable bool
|
|
||||||
}
|
}
|
||||||
tests := []test{
|
tests := []test{
|
||||||
{
|
{
|
||||||
|
|
@ -108,26 +106,6 @@ func TestParseURI(t *testing.T) {
|
||||||
expectURI: &URI{Scheme: "bzz-list"},
|
expectURI: &URI{Scheme: "bzz-list"},
|
||||||
expectList: true,
|
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 {
|
for _, x := range tests {
|
||||||
actual, err := Parse(x.uri)
|
actual, err := Parse(x.uri)
|
||||||
|
|
@ -152,11 +130,5 @@ func TestParseURI(t *testing.T) {
|
||||||
if actual.List() != x.expectList {
|
if actual.List() != x.expectList {
|
||||||
t.Fatalf("expected %s list to be %t, got %t", x.uri, x.expectList, actual.List())
|
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())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue