rclone: github.com/ncw/rclone/cmd/serve/httplib Index | Files | Directories

package httplib

import "github.com/ncw/rclone/cmd/serve/httplib"

Package httplib provides common functionality for http servers


Package Files



var ContextAuthKey = &contextAuthType{}

ContextAuthKey is a simple context key for storing info returned by AuthFn

var ContextUserKey = &contextUserType{}

ContextUserKey is a simple context key for storing the username of the request

var DefaultOpt = Options{
    ListenAddr:         "localhost:8080",
    Realm:              "rclone",
    ServerReadTimeout:  1 * time.Hour,
    ServerWriteTimeout: 1 * time.Hour,
    MaxHeaderBytes:     4096,

DefaultOpt is the default values used for Options

var Help = "" /* 3370 byte string literal not displayed */

Help contains text describing the http server to add to the command help.

type AuthFn Uses

type AuthFn func(user, pass string) (value interface{}, err error)

AuthFn if used will be used to authenticate user, pass. If an error is returned then the user is not authenticated.

If a non nil value is returned then it is added to the context under the key

type Options Uses

type Options struct {
    ListenAddr         string        // Port to listen on
    BaseURL            string        // prefix to strip from URLs
    ServerReadTimeout  time.Duration // Timeout for server reading data
    ServerWriteTimeout time.Duration // Timeout for server writing data
    MaxHeaderBytes     int           // Maximum size of request header
    SslCert            string        // SSL PEM key (concatenation of certificate and CA certificate)
    SslKey             string        // SSL PEM Private key
    ClientCA           string        // Client certificate authority to verify clients with
    HtPasswd           string        // htpasswd file - if not provided no authentication is done
    Realm              string        // realm for authentication
    BasicUser          string        // single username for basic auth if not using Htpasswd
    BasicPass          string        // password for BasicUser
    Auth               AuthFn        `json:"-"` // custom Auth (not set by command line flags)
    Template           string        // User specified template

Options contains options for the http Server

type Server Uses

type Server struct {
    Opt Options

    HTMLTemplate *template.Template // HTML template for web interface
    // contains filtered or unexported fields

Server contains info about the running http server

func NewServer Uses

func NewServer(handler http.Handler, opt *Options) *Server

NewServer creates an http server. The opt can be nil in which case the default options will be used.

func (*Server) Close Uses

func (s *Server) Close()

Close shuts the running server down

func (*Server) Path Uses

func (s *Server) Path(w http.ResponseWriter, r *http.Request) (Path string, ok bool)

Path returns the current path with the Prefix stripped

If it returns false, then the path was invalid and the handler should exit as the error response has already been sent

func (*Server) Serve Uses

func (s *Server) Serve() error

Serve runs the server - returns an error only if the listener was not started; does not block, so use s.Wait() to block on the listener indefinitely.

func (*Server) URL Uses

func (s *Server) URL() string

URL returns the serving address of this server

func (*Server) UsingAuth Uses

func (s *Server) UsingAuth() bool

UsingAuth returns true if authentication is required

func (*Server) Wait Uses

func (s *Server) Wait()

Wait blocks while the listener is open.


servePackage serve deals with serving objects over HTTP

Package httplib imports 16 packages (graph) and is imported by 21 packages. Updated 2020-08-03. Refresh now. Tools for package owners.