Documentation ¶
Overview ¶
Show nicely (but simple) formatted HTML error pages (or respond with JSON if the appropriate `Accept` header is set)) for the http package.
We use html templates to handle simple but as informative as possible error pages.
To eliminate circular dependency in case of an error, we don't store error pages on swarm. We can't save the error pages as html files on disk, or when deploying compiled binaries they won't be found.
For this reason we resort to save the HTML error pages as strings, which then can be parsed by Go's html/template package
A simple http server interface to Swarm
Index ¶
- func GetGenericErrorPage() string
- func GetMultipleChoicesErrorPage() string
- func GetNotFoundErrorPage() string
- func Respond(w http.ResponseWriter, req *Request, msg string, code int)
- func ShowMultipleChoices(w http.ResponseWriter, req *Request, list api.ManifestList)
- func ValidateCaseErrors(r *Request) string
- type CaseError
- type Request
- type ResponseParams
- type RoundTripper
- type Server
- func (s *Server) HandleBzz(w http.ResponseWriter, r *Request)
- func (s *Server) HandleBzzHash(w http.ResponseWriter, r *Request)
- func (s *Server) HandleBzzImmutable(w http.ResponseWriter, r *Request)
- func (s *Server) HandleBzzList(w http.ResponseWriter, r *Request)
- func (s *Server) HandleBzzRaw(w http.ResponseWriter, r *Request)
- func (s *Server) HandleBzzResource(w http.ResponseWriter, r *Request)
- func (s *Server) HandleDelete(w http.ResponseWriter, r *Request)
- func (s *Server) HandleGet(w http.ResponseWriter, r *Request)
- func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request)
- func (s *Server) HandleGetList(w http.ResponseWriter, r *Request)
- func (s *Server) HandleGetResource(w http.ResponseWriter, r *Request)
- func (s *Server) HandlePostFiles(w http.ResponseWriter, r *Request)
- func (s *Server) HandlePostRaw(w http.ResponseWriter, r *Request)
- func (s *Server) HandlePostResource(w http.ResponseWriter, r *Request)
- func (s *Server) HandleRootPaths(w http.ResponseWriter, r *Request)
- func (s *Server) ListenAndServe(addr string) error
- func (s *Server) WrapHandler(parseBzzUri bool, h func(http.ResponseWriter, *Request)) http.HandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetGenericErrorPage ¶ added in v1.7.0
func GetGenericErrorPage() string
This returns the HTML for generic errors
func GetMultipleChoicesErrorPage ¶ added in v1.7.2
func GetMultipleChoicesErrorPage() string
This returns the HTML for a page listing disambiguation options i.e. if user requested bzz:/<hash>/read and the manifest contains "readme.md" and "readinglist.txt", this page is returned with a clickable list the existing disambiguation links in the manifest
func GetNotFoundErrorPage ¶ added in v1.7.0
func GetNotFoundErrorPage() string
This returns the HTML for a 404 Not Found error
func Respond ¶ added in v1.8.12
func Respond(w http.ResponseWriter, req *Request, msg string, code int)
Respond is used to show an HTML page to a client. If there is an `Accept` header of `application/json`, JSON will be returned instead The function just takes a string message which will be displayed in the error page. The code is used to evaluate which template will be displayed (and return the correct HTTP status code)
func ShowMultipleChoices ¶ added in v1.7.2
func ShowMultipleChoices(w http.ResponseWriter, req *Request, list api.ManifestList)
ShowMultipeChoices is used when a user requests a resource in a manifest which results in ambiguous results. It returns a HTML page with clickable links of each of the entry in the manifest which fits the request URI ambiguity. For example, if the user requests bzz:/<hash>/read and that manifest contains entries "readme.md" and "readinglist.txt", a HTML page is returned with this two links. This only applies if the manifest has no default entry
func ValidateCaseErrors ¶ added in v1.8.2
ValidateCaseErrors is a method that process the request object through certain validators that assert if certain conditions are met for further information to log as an error
Types ¶
type CaseError ¶ added in v1.8.2
a custom error case struct that would be used to store validators and additional error info to display with client responses.
type ResponseParams ¶ added in v1.8.12
type ResponseParams struct { Msg string Code int Timestamp string Details template.HTML // contains filtered or unexported fields }
parameters needed for formatting the correct HTML page
type RoundTripper ¶
type Server ¶ added in v1.5.6
browser API for registering bzz url scheme handlers: https://developer.mozilla.org/en/docs/Web-based_protocol_handlers electron (chromium) api for registering bzz url scheme handlers: https://github.com/atom/electron/blob/master/docs/api/protocol.md
func (*Server) HandleBzz ¶ added in v1.8.13
func (s *Server) HandleBzz(w http.ResponseWriter, r *Request)
func (*Server) HandleBzzHash ¶ added in v1.8.13
func (s *Server) HandleBzzHash(w http.ResponseWriter, r *Request)
func (*Server) HandleBzzImmutable ¶ added in v1.8.13
func (s *Server) HandleBzzImmutable(w http.ResponseWriter, r *Request)
func (*Server) HandleBzzList ¶ added in v1.8.13
func (s *Server) HandleBzzList(w http.ResponseWriter, r *Request)
func (*Server) HandleBzzRaw ¶ added in v1.8.13
func (s *Server) HandleBzzRaw(w http.ResponseWriter, r *Request)
func (*Server) HandleBzzResource ¶ added in v1.8.13
func (s *Server) HandleBzzResource(w http.ResponseWriter, r *Request)
func (*Server) HandleDelete ¶ added in v1.6.0
func (s *Server) HandleDelete(w http.ResponseWriter, r *Request)
HandleDelete handles a DELETE request to bzz:/<manifest>/<path>, removes <path> from <manifest> and returns the resulting manifest hash as a text/plain response
func (*Server) HandleGet ¶ added in v1.8.0
func (s *Server) HandleGet(w http.ResponseWriter, r *Request)
HandleGet handles a GET request to
- bzz-raw://<key> and responds with the raw content stored at the given storage key
- bzz-hash://<key> and responds with the hash of the content stored at the given storage key as a text/plain response
func (*Server) HandleGetFile ¶ added in v1.6.0
func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request)
HandleGetFile handles a GET request to bzz://<manifest>/<path> and responds with the content of the file at <path> from the given <manifest>
func (*Server) HandleGetList ¶ added in v1.6.0
func (s *Server) HandleGetList(w http.ResponseWriter, r *Request)
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 (*Server) HandleGetResource ¶ added in v1.8.12
func (s *Server) HandleGetResource(w http.ResponseWriter, r *Request)
Retrieve mutable resource updates: bzz-resource://<id> - get latest update bzz-resource://<id>/<n> - get latest update on period n bzz-resource://<id>/<n>/<m> - get update version m of period n bzz-resource://<id>/meta - get metadata and next version information <id> = ens name or hash TODO: Enable pass maxPeriod parameter
func (*Server) HandlePostFiles ¶ added in v1.6.0
func (s *Server) HandlePostFiles(w http.ResponseWriter, r *Request)
HandlePostFiles handles a POST request to bzz:/<hash>/<path> which contains either a single file or multiple files (either a tar archive or multipart form), adds those files either to an existing manifest or to a new manifest under <path> and returns the resulting manifest hash as a text/plain response
func (*Server) HandlePostRaw ¶ added in v1.6.0
func (s *Server) HandlePostRaw(w http.ResponseWriter, r *Request)
HandlePostRaw handles a POST request to a raw bzz-raw:/ URI, stores the request body in swarm and returns the resulting storage address as a text/plain response
func (*Server) HandlePostResource ¶ added in v1.8.12
func (s *Server) HandlePostResource(w http.ResponseWriter, r *Request)
Handles creation of new mutable resources and adding updates to existing mutable resources There are two types of updates available, "raw" and "multihash." If the latter is used, a subsequent bzz:// GET call to the manifest of the resource will return the page that the multihash is pointing to, as if it held a normal swarm content manifest
The POST request admits a JSON structure as defined in the mru package: `mru.updateRequestJSON` The requests can be to a) create a resource, b) update a resource or c) both a+b: create a resource and set the initial content
func (*Server) HandleRootPaths ¶ added in v1.8.13
func (s *Server) HandleRootPaths(w http.ResponseWriter, r *Request)
func (*Server) ListenAndServe ¶ added in v1.8.13
func (*Server) WrapHandler ¶ added in v1.8.13
func (s *Server) WrapHandler(parseBzzUri bool, h func(http.ResponseWriter, *Request)) http.HandlerFunc