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
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
|||
// * <scheme>://<addr>/<path>
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ func TestParseURI(t *testing.T) {
|
|||
expectRaw bool
|
||||
expectImmutable bool
|
||||
expectList bool
|
||||
expectDeprecatedRaw bool
|
||||
expectDeprecatedImmutable 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue