mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
Revert bzzh related commits
Revert "swarm/api: add tests for bzzh get path" Revert "swarm/api: url scheme bzzh for getting hashes of swarm content (#15238)"
This commit is contained in:
parent
745e593028
commit
d82ecbac22
4 changed files with 15 additions and 76 deletions
|
|
@ -290,12 +290,9 @@ func (s *Server) HandleDelete(w http.ResponseWriter, r *Request) {
|
||||||
fmt.Fprint(w, newKey)
|
fmt.Fprint(w, newKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleGet handles a GET request to
|
// HandleGetRaw handles a GET request to bzzr://<key> and responds with
|
||||||
// - bzzr://<key> and responds with the raw content stored at the
|
// the raw content stored at the given storage key
|
||||||
// given storage key
|
func (s *Server) HandleGetRaw(w http.ResponseWriter, r *Request) {
|
||||||
// - bzzh://<key> and responds with the hash of the content stored
|
|
||||||
// at the given storage key as a text/plain response
|
|
||||||
func (s *Server) HandleGet(w http.ResponseWriter, r *Request) {
|
|
||||||
key, err := s.api.Resolve(r.uri)
|
key, err := s.api.Resolve(r.uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Error(w, r, fmt.Errorf("error resolving %s: %s", r.uri.Addr, err))
|
s.Error(w, r, fmt.Errorf("error resolving %s: %s", r.uri.Addr, err))
|
||||||
|
|
@ -348,8 +345,6 @@ func (s *Server) HandleGet(w http.ResponseWriter, r *Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
|
||||||
case r.uri.Raw():
|
|
||||||
// allow the request to overwrite the content type using a query
|
// allow the request to overwrite the content type using a query
|
||||||
// parameter
|
// parameter
|
||||||
contentType := "application/octet-stream"
|
contentType := "application/octet-stream"
|
||||||
|
|
@ -359,11 +354,6 @@ func (s *Server) HandleGet(w http.ResponseWriter, r *Request) {
|
||||||
w.Header().Set("Content-Type", contentType)
|
w.Header().Set("Content-Type", contentType)
|
||||||
|
|
||||||
http.ServeContent(w, &r.Request, "", time.Now(), reader)
|
http.ServeContent(w, &r.Request, "", time.Now(), reader)
|
||||||
case r.uri.Hash():
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
fmt.Fprint(w, key)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleGetFiles handles a GET request to bzz:/<manifest> with an Accept
|
// HandleGetFiles handles a GET request to bzz:/<manifest> with an Accept
|
||||||
|
|
@ -626,8 +616,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
s.HandleDelete(w, req)
|
s.HandleDelete(w, req)
|
||||||
|
|
||||||
case "GET":
|
case "GET":
|
||||||
if uri.Raw() || uri.Hash() {
|
if uri.Raw() {
|
||||||
s.HandleGet(w, req)
|
s.HandleGetRaw(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/swarm/testutil"
|
"github.com/ethereum/go-ethereum/swarm/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBzzGetPath(t *testing.T) {
|
func TestBzzrGetPath(t *testing.T) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
@ -104,47 +104,16 @@ func TestBzzGetPath(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range testrequests {
|
|
||||||
var resp *http.Response
|
|
||||||
var respbody []byte
|
|
||||||
|
|
||||||
url := srv.URL + "/bzzh:/"
|
|
||||||
if k[:] != "" {
|
|
||||||
url += common.ToHex(key[0])[2:] + "/" + k[1:]
|
|
||||||
}
|
|
||||||
resp, err = http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Request failed: %v", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
respbody, err = ioutil.ReadAll(resp.Body)
|
|
||||||
|
|
||||||
if string(respbody) != key[v].String() {
|
|
||||||
isexpectedfailrequest := false
|
|
||||||
|
|
||||||
for _, r := range expectedfailrequests {
|
|
||||||
if k[:] == r {
|
|
||||||
isexpectedfailrequest = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !isexpectedfailrequest {
|
|
||||||
t.Fatalf("Response body does not match, expected: %v, got %v", key[v], string(respbody))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nonhashtests := []string{
|
nonhashtests := []string{
|
||||||
srv.URL + "/bzz:/name",
|
srv.URL + "/bzz:/name",
|
||||||
srv.URL + "/bzzi:/nonhash",
|
srv.URL + "/bzzi:/nonhash",
|
||||||
srv.URL + "/bzzr:/nonhash",
|
srv.URL + "/bzzr:/nonhash",
|
||||||
srv.URL + "/bzzh:/nonhash",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nonhashresponses := []string{
|
nonhashresponses := []string{
|
||||||
"error resolving name: no DNS to resolve name: "name"",
|
"error resolving name: no DNS to resolve name: "name"",
|
||||||
"error resolving nonhash: immutable address not a content hash: "nonhash"",
|
"error resolving nonhash: immutable address not a content hash: "nonhash"",
|
||||||
"error resolving nonhash: no DNS to resolve name: "nonhash"",
|
"error resolving nonhash: no DNS to resolve name: "nonhash"",
|
||||||
"error resolving nonhash: no DNS to resolve name: "nonhash"",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, url := range nonhashtests {
|
for i, url := range nonhashtests {
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,6 @@ type URI struct {
|
||||||
// * bzzr - raw swarm content
|
// * bzzr - raw swarm content
|
||||||
// * bzzi - immutable URI of an entry in a swarm manifest
|
// * bzzi - immutable URI of an entry in a swarm manifest
|
||||||
// (address is not resolved)
|
// (address is not resolved)
|
||||||
// * bzzh - hash of swarm content
|
|
||||||
//
|
|
||||||
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
|
||||||
|
|
@ -62,7 +60,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", "bzzi", "bzzr", "bzzh":
|
case "bzz", "bzzi", "bzzr":
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown scheme %q", u.Scheme)
|
return nil, fmt.Errorf("unknown scheme %q", u.Scheme)
|
||||||
}
|
}
|
||||||
|
|
@ -93,10 +91,6 @@ func (u *URI) Immutable() bool {
|
||||||
return u.Scheme == "bzzi"
|
return u.Scheme == "bzzi"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *URI) Hash() bool {
|
|
||||||
return u.Scheme == "bzzh"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *URI) String() string {
|
func (u *URI) String() string {
|
||||||
return u.Scheme + ":/" + u.Addr + "/" + u.Path
|
return u.Scheme + ":/" + u.Addr + "/" + u.Path
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ func TestParseURI(t *testing.T) {
|
||||||
expectErr bool
|
expectErr bool
|
||||||
expectRaw bool
|
expectRaw bool
|
||||||
expectImmutable bool
|
expectImmutable bool
|
||||||
expectHash bool
|
|
||||||
}
|
}
|
||||||
tests := []test{
|
tests := []test{
|
||||||
{
|
{
|
||||||
|
|
@ -96,16 +95,6 @@ func TestParseURI(t *testing.T) {
|
||||||
uri: "bzz://abc123/path/to/entry",
|
uri: "bzz://abc123/path/to/entry",
|
||||||
expectURI: &URI{Scheme: "bzz", Addr: "abc123", Path: "path/to/entry"},
|
expectURI: &URI{Scheme: "bzz", Addr: "abc123", Path: "path/to/entry"},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
uri: "bzzh:",
|
|
||||||
expectURI: &URI{Scheme: "bzzh"},
|
|
||||||
expectHash: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
uri: "bzzh:/",
|
|
||||||
expectURI: &URI{Scheme: "bzzh"},
|
|
||||||
expectHash: true,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, x := range tests {
|
for _, x := range tests {
|
||||||
actual, err := Parse(x.uri)
|
actual, err := Parse(x.uri)
|
||||||
|
|
@ -127,8 +116,5 @@ func TestParseURI(t *testing.T) {
|
||||||
if actual.Immutable() != x.expectImmutable {
|
if actual.Immutable() != x.expectImmutable {
|
||||||
t.Fatalf("expected %s immutable to be %t, got %t", x.uri, x.expectImmutable, actual.Immutable())
|
t.Fatalf("expected %s immutable to be %t, got %t", x.uri, x.expectImmutable, actual.Immutable())
|
||||||
}
|
}
|
||||||
if actual.Hash() != x.expectHash {
|
|
||||||
t.Fatalf("expected %s hash to be %t, got %t", x.uri, x.expectHash, actual.Hash())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue