swarm: bzz-list, bzz-raw and bzz-immutable schemes (#15667)
* swarm/api: url scheme bzz-list for getting list of files from manifest Replace query parameter list=true for listing all files contained in a swarm manifest with a new URL scheme bzz-list. * swarm: replaace bzzr and bzzi schemes with bzz-raw and bzz-immutable New URI Shemes are added and old ones are deprecated, but not removed. Old Schemes bzzr and bzzi are functional for backward compatibility. * swarm/api: completely remove bzzr and bzzi schemes Remove old schemes in favour of bzz-raw and bzz-immutable. * swarm/api: revert "completely remove bzzr and bzzi schemes" Keep bzzr and bzzi schemes for backward compatibility. At least until 0.3 swarm release.
This commit is contained in:
committed by
Péter Szilágyi
parent
7f9d94fe9a
commit
c786f75389
@ -86,7 +86,7 @@ type Request struct {
|
||||
uri *api.URI
|
||||
}
|
||||
|
||||
// HandlePostRaw handles a POST request to a raw bzzr:/ URI, stores the request
|
||||
// HandlePostRaw handles a POST request to a raw bzz-raw:/ URI, stores the request
|
||||
// body in swarm and returns the resulting storage key as a text/plain response
|
||||
func (s *Server) HandlePostRaw(w http.ResponseWriter, r *Request) {
|
||||
if r.uri.Path != "" {
|
||||
@ -290,7 +290,7 @@ func (s *Server) HandleDelete(w http.ResponseWriter, r *Request) {
|
||||
fmt.Fprint(w, newKey)
|
||||
}
|
||||
|
||||
// HandleGetRaw handles a GET request to bzzr://<key> and responds with
|
||||
// HandleGetRaw handles a GET request to bzz-raw://<key> and responds with
|
||||
// the raw content stored at the given storage key
|
||||
func (s *Server) HandleGetRaw(w http.ResponseWriter, r *Request) {
|
||||
key, err := s.api.Resolve(r.uri)
|
||||
@ -424,14 +424,13 @@ func (s *Server) HandleGetFiles(w http.ResponseWriter, r *Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// HandleGetList handles a GET request to bzz:/<manifest>/<path> which has
|
||||
// the "list" query parameter set to "true" and returns a list of all files
|
||||
// contained in <manifest> under <path> grouped into common prefixes using
|
||||
// "/" as a delimiter
|
||||
// HandleGetList handles a GET request to bzz-list:/<manifest>/<path> and returns
|
||||
// a list of all files contained in <manifest> under <path> grouped into
|
||||
// common prefixes using "/" as a delimiter
|
||||
func (s *Server) HandleGetList(w http.ResponseWriter, r *Request) {
|
||||
// ensure the root path has a trailing slash so that relative URLs work
|
||||
if r.uri.Path == "" && !strings.HasSuffix(r.URL.Path, "/") {
|
||||
http.Redirect(w, &r.Request, r.URL.Path+"/?list=true", http.StatusMovedPermanently)
|
||||
http.Redirect(w, &r.Request, r.URL.Path+"/", http.StatusMovedPermanently)
|
||||
return
|
||||
}
|
||||
|
||||
@ -453,7 +452,11 @@ func (s *Server) HandleGetList(w http.ResponseWriter, r *Request) {
|
||||
if strings.Contains(r.Header.Get("Accept"), "text/html") {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
err := htmlListTemplate.Execute(w, &htmlListData{
|
||||
URI: r.uri,
|
||||
URI: &api.URI{
|
||||
Scheme: "bzz",
|
||||
Addr: r.uri.Addr,
|
||||
Path: r.uri.Path,
|
||||
},
|
||||
List: &list,
|
||||
})
|
||||
if err != nil {
|
||||
@ -589,7 +592,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
switch r.Method {
|
||||
case "POST":
|
||||
if uri.Raw() {
|
||||
if uri.Raw() || uri.DeprecatedRaw() {
|
||||
s.HandlePostRaw(w, req)
|
||||
} else {
|
||||
s.HandlePostFiles(w, req)
|
||||
@ -601,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() {
|
||||
if uri.Raw() || uri.DeprecatedRaw() {
|
||||
ShowError(w, r, fmt.Sprintf("No PUT to %s allowed.", uri), http.StatusBadRequest)
|
||||
return
|
||||
} else {
|
||||
@ -609,28 +612,28 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
case "DELETE":
|
||||
if uri.Raw() {
|
||||
if uri.Raw() || uri.DeprecatedRaw() {
|
||||
ShowError(w, r, fmt.Sprintf("No DELETE to %s allowed.", uri), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
s.HandleDelete(w, req)
|
||||
|
||||
case "GET":
|
||||
if uri.Raw() {
|
||||
if uri.Raw() || uri.DeprecatedRaw() {
|
||||
s.HandleGetRaw(w, req)
|
||||
return
|
||||
}
|
||||
|
||||
if uri.List() {
|
||||
s.HandleGetList(w, req)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Header.Get("Accept") == "application/x-tar" {
|
||||
s.HandleGetFiles(w, req)
|
||||
return
|
||||
}
|
||||
|
||||
if r.URL.Query().Get("list") == "true" {
|
||||
s.HandleGetList(w, req)
|
||||
return
|
||||
}
|
||||
|
||||
s.HandleGetFile(w, req)
|
||||
|
||||
default:
|
||||
|
Reference in New Issue
Block a user