Documentation ¶
Overview ¶
A simple http server interface to Swarm
Index ¶
- Constants
- Variables
- func Adapt(h http.Handler, adapters ...Adapter) http.Handler
- func GetRUID(ctx context.Context) string
- func GetURI(ctx context.Context) *api.URI
- func InitLoggingResponseWriter(h http.Handler) http.Handler
- func InitUploadTag(h http.Handler, tags *chunk.Tags) http.Handler
- func InstrumentOpenTracing(h http.Handler) http.Handler
- func ParseURI(h http.Handler) http.Handler
- func PinningEnabledPassthrough(h http.Handler, api *pin.API, checkHeader bool) http.Handler
- func RecoverPanic(h http.Handler) http.Handler
- func SetRUID(ctx context.Context, ruid string) context.Context
- func SetRequestHost(h http.Handler) http.Handler
- func SetRequestID(h http.Handler) http.Handler
- func SetURI(ctx context.Context, uri *api.URI) context.Context
- func ShowMultipleChoices(w http.ResponseWriter, r *http.Request, list api.ManifestList)
- type Adapter
- type ResponseParams
- type RoundTripper
- type Server
- func (s *Server) HandleBzzGet(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleDelete(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleGet(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleGetFeed(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleGetFeedRaw(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleGetFile(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleGetList(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleGetPins(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleGetTag(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlePin(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlePostFeed(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlePostFiles(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlePostRaw(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleRootPaths(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleUnpin(w http.ResponseWriter, r *http.Request)
- func (s *Server) ListenAndServe(addr string) error
- type TestServer
- type TestSwarmServer
Constants ¶
const ( TagHeaderName = "x-swarm-tag" // Presence of this in header indicates the tag AnonymousHeaderName = "x-swarm-anonymous" // Presence of this in header indicates only pull sync should be used for upload PinHeaderName = "x-swarm-pin" // Presence of this in header indicates pinning required )
Variables ¶
var TemplatesMap = make(map[string]*template.Template)
Functions ¶
func Adapt ¶
Adapt chains h (main request handler) main handler to adapters (middleware handlers) Please note that the order of execution for `adapters` is FIFO (adapters[0] will be executed first)
func InitLoggingResponseWriter ¶
InitLoggingResponseWriter is a wrapper around the WriteHeader call that allows saving the response code for local context
func InitUploadTag ¶
InitUploadTag creates a new tag for an upload to the local HTTP proxy if a tag is not named using the TagHeaderName, a fallback name will be used when the Content-Length header is set, an ETA on chunking will be available since the number of chunks to be split is known in advance (not including enclosing manifest chunks) the tag can later be accessed using the appropriate identifier in the request context
func InstrumentOpenTracing ¶
InstrumentOpenTracing instruments an HTTP request with an OpenTracing span
func ParseURI ¶
ParseURI is a middleware that parses the request URI to a Swarm URI object that dissects the content presented after the HTTP URI's first slash
func PinningEnabledPassthrough ¶ added in v0.5.0
PinningEnabledPassthrough allows a request through the middleware in the following cases: 1. checkHeader = true; api != nil; header PinHeaderName = true (x-swarm-pin: true) // header is set (hence api use is needed) and api not nil 2. checkHeader = false; api != nil // api not nil (don't care about header)
func RecoverPanic ¶
RecoverPanic is a middleware intended to catch possible panic in the call stack and log them when they occur, failing gracefully to the client
func SetRequestHost ¶
SetRequestHost is a middleware that injects the request Host into the request context
func SetRequestID ¶
SetRequestID is a middleware that sets a random UUID as a unique identifier and injects it into the request context
func ShowMultipleChoices ¶
func ShowMultipleChoices(w http.ResponseWriter, r *http.Request, list api.ManifestList)
ShowMultipleChoices 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
Types ¶
type ResponseParams ¶
type RoundTripper ¶
type Server ¶
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) HandleBzzGet ¶
func (s *Server) HandleBzzGet(w http.ResponseWriter, r *http.Request)
func (*Server) HandleDelete ¶
func (s *Server) HandleDelete(w http.ResponseWriter, r *http.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 ¶
func (s *Server) HandleGet(w http.ResponseWriter, r *http.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) HandleGetFeed ¶
func (s *Server) HandleGetFeed(w http.ResponseWriter, r *http.Request)
HandleGetFeed retrieves Swarm feeds updates: bzz-feed://<manifest address or ENS name> - get latest feed update, given a manifest address - or - specify user + topic (optional), subtopic name (optional) directly, without manifest: bzz-feed://?user=0x...&topic=0x...&name=subtopic name topic defaults to 0x000... if not specified. name defaults to empty string if not specified. thus, empty name and topic refers to the user's default feed.
Optional parameters: time=xx - get the latest update before time (in epoch seconds) hint.time=xx - hint the lookup algorithm looking for updates at around that time hint.level=xx - hint the lookup algorithm looking for updates at around this frequency level meta=1 - get feed metadata and status information instead of performing a feed query NOTE: meta=1 will be deprecated in the near future
func (*Server) HandleGetFeedRaw ¶ added in v0.5.3
func (s *Server) HandleGetFeedRaw(w http.ResponseWriter, r *http.Request)
func (*Server) HandleGetFile ¶
func (s *Server) HandleGetFile(w http.ResponseWriter, r *http.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 ¶
func (s *Server) HandleGetList(w http.ResponseWriter, r *http.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) HandleGetPins ¶ added in v0.5.0
func (s *Server) HandleGetPins(w http.ResponseWriter, r *http.Request)
HandleGetPins return information about all the hashes pinned at this moment
func (*Server) HandleGetTag ¶ added in v0.5.0
func (s *Server) HandleGetTag(w http.ResponseWriter, r *http.Request)
HandleGetTag responds to the following request
- bzz-tag:/<manifest> and
- bzz-tag:/?tagId=<tagId>
Clients should use root hash or the tagID to get the tag counters
func (*Server) HandlePin ¶ added in v0.5.0
func (s *Server) HandlePin(w http.ResponseWriter, r *http.Request)
HandlePin takes a root hash as argument and pins a given file or collection in the local Swarm DB
func (*Server) HandlePostFeed ¶
func (s *Server) HandlePostFeed(w http.ResponseWriter, r *http.Request)
Handles feed manifest creation and feed updates The POST request admits a JSON structure as defined in the feeds package: `feed.updateRequestJSON` The requests can be to a) create a feed manifest, b) update a feed or c) both a+b: create a feed manifest and publish a first update
func (*Server) HandlePostFiles ¶
func (s *Server) HandlePostFiles(w http.ResponseWriter, r *http.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 ¶
func (s *Server) HandlePostRaw(w http.ResponseWriter, r *http.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) HandleRootPaths ¶
func (s *Server) HandleRootPaths(w http.ResponseWriter, r *http.Request)
func (*Server) HandleUnpin ¶ added in v0.5.0
func (s *Server) HandleUnpin(w http.ResponseWriter, r *http.Request)
HandleUnpin takes a root hash as argument and unpins the file or collection from the local Swarm DB
func (*Server) ListenAndServe ¶
type TestServer ¶
type TestServer interface {
ServeHTTP(http.ResponseWriter, *http.Request)
}
type TestSwarmServer ¶
type TestSwarmServer struct { *httptest.Server Hasher storage.SwarmHash FileStore *storage.FileStore Tags *chunk.Tags CurrentTime uint64 // contains filtered or unexported fields }
func NewTestSwarmServer ¶
func NewTestSwarmServer(t *testing.T, serverFunc func(*api.API, *pin.API) TestServer, resolver api.Resolver, o *localstore.Options) *TestSwarmServer
func (*TestSwarmServer) Close ¶
func (t *TestSwarmServer) Close()
func (*TestSwarmServer) Now ¶
func (t *TestSwarmServer) Now() feed.Timestamp