http

package
v2.1.66+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2018 License: GPL-3.0 Imports: 20 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGenericErrorPage

func GetGenericErrorPage() string

This returns the HTML for generic errors

func GetMultipleChoicesErrorPage

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

func GetNotFoundErrorPage() string

This returns the HTML for a 404 Not Found error

func ShowError

func ShowError(w http.ResponseWriter, r *http.Request, msg string, code int)

ShowError is used to show an HTML error 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

func ShowMultipleChoices(w http.ResponseWriter, r *http.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 StartHttpServer

func StartHttpServer(api *api.Api, config *ServerConfig)

starts up http server

Types

type ErrorParams

type ErrorParams struct {
	Msg       string
	Code      int
	Timestamp string

	Details template.HTML
	// contains filtered or unexported fields
}

parameters needed for formatting the correct HTML page

type Request

type Request struct {
	http.Request
	// contains filtered or unexported fields
}

Request wraps http.Request and also includes the parsed bzz URI

type RoundTripper

type RoundTripper struct {
	Host string
	Port string
}

func (*RoundTripper) RoundTrip

func (rt *RoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err error)

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(api *api.Api) *Server

func (*Server) BadRequest

func (s *Server) BadRequest(w http.ResponseWriter, r *Request, reason string)

func (*Server) Error

func (s *Server) Error(w http.ResponseWriter, r *Request, err error)

func (*Server) HandleDelete

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

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

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) HandleGetFiles

func (s *Server) HandleGetFiles(w http.ResponseWriter, r *Request)

HandleGetFiles handles a GET request to bzz:/<manifest> with an Accept header of "application/x-tar" and returns a tar stream of all files contained in the manifest

func (*Server) HandleGetList

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) HandlePostFiles

func (s *Server) HandlePostFiles(w http.ResponseWriter, r *Request)

HandlePostFiles handles a POST request (or deprecated PUT 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 *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 (*Server) NotFound

func (s *Server) NotFound(w http.ResponseWriter, r *Request, err error)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerConfig

type ServerConfig struct {
	Addr       string
	CorsString string
}

ServerConfig is the basic configuration needed for the HTTP server and also includes CORS settings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL