http

package
v1.58.1-0...-47970fe Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package http provides a registration interface for http services

Index

Constants

This section is empty.

Variables

View Source
var DefaultOpt = Options{
	ListenAddr:         "127.0.0.1:8080",
	ServerReadTimeout:  1 * time.Hour,
	ServerWriteTimeout: 1 * time.Hour,
	MaxHeaderBytes:     4096,
}

DefaultOpt is the default values used for Options

View Source
var Help = `
### Server options

Use ` + "`--addr`" + ` to specify which IP address and port the server should
listen on, eg ` + "`--addr 1.2.3.4:8000` or `--addr :8080`" + ` to listen to all
IPs.  By default it only listens on localhost.  You can use port
:0 to let the OS choose an available port.

If you set ` + "`--addr`" + ` to listen on a public or LAN accessible IP address
then using Authentication is advised - see the next section for info.

` + "`--server-read-timeout` and `--server-write-timeout`" + ` can be used to
control the timeouts on the server.  Note that this is the total time
for a transfer.

` + "`--max-header-bytes`" + ` controls the maximum number of bytes the server will
accept in the HTTP header.

` + "`--baseurl`" + ` controls the URL prefix that rclone serves from.  By default
rclone will serve from the root.  If you used ` + "`--baseurl \"/rclone\"`" + ` then
rclone would serve from a URL starting with "/rclone/".  This is
useful if you wish to proxy rclone serve.  Rclone automatically
inserts leading and trailing "/" on ` + "`--baseurl`" + `, so ` + "`--baseurl \"rclone\"`" + `,
` + "`--baseurl \"/rclone\"` and `--baseurl \"/rclone/\"`" + ` are all treated
identically.

#### SSL/TLS

By default this will serve over http.  If you want you can serve over
https.  You will need to supply the ` + "`--cert` and `--key`" + ` flags.
If you wish to do client side certificate validation then you will need to
supply ` + "`--client-ca`" + ` also.

` + "`--cert`" + ` should be a either a PEM encoded certificate or a concatenation
of that with the CA certificate.  ` + "`--key`" + ` should be the PEM encoded
private key and ` + "`--client-ca`" + ` should be the PEM encoded client
certificate authority certificate.
`

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

Functions

func AddFlags

func AddFlags(flagSet *pflag.FlagSet)

AddFlags adds flags for the httplib

func AddFlagsPrefix

func AddFlagsPrefix(flagSet *pflag.FlagSet, prefix string, Opt *Options)

AddFlagsPrefix adds flags for the httplib

func Mount

func Mount(pattern string, h http.Handler) error

Mount attaches another http.Handler along ./pattern/*

func Restart

func Restart() error

Restart or start the default http server using the default options and no handlers

func Route

func Route(pattern string, fn func(r chi.Router)) (chi.Router, error)

Route mounts a sub-Router along a `pattern` string.

func Router

func Router() (chi.Router, error)

Router returns the server base router

func SetOptions

func SetOptions(opt Options)

SetOptions thread safe setter for the default server options

func Shutdown

func Shutdown() error

Shutdown gracefully shuts down the default http server

func URL

func URL() string

URL of default http server

func Wait

func Wait()

Wait blocks while the default http server is serving requests

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware function signature required by chi.Router.Use()

type Options

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        // Path to SSL PEM key (concatenation of certificate and CA certificate)
	SslKey             string        // Path to SSL PEM Private key
	SslCertBody        []byte        // SSL PEM key (concatenation of certificate and CA certificate) body, ignores SslCert
	SslKeyBody         []byte        // SSL PEM Private key body, ignores SslKey
	ClientCA           string        // Client certificate authority to verify clients with
}

Options contains options for the http Server

func GetOptions

func GetOptions() Options

GetOptions thread safe getter for the default server options

type Server

type Server interface {
	Router() chi.Router
	Route(pattern string, fn func(r chi.Router)) chi.Router
	Mount(pattern string, h http.Handler)
	Shutdown() error
}

Server interface of http server

func NewServer

func NewServer(listeners, tlsListeners []net.Listener, opt Options) (Server, error)

NewServer instantiates a new http server using provided listeners and options This function is provided if the default http server does not meet a services requirements and should not generally be used A http server can listen using multiple listeners. For example, a listener for port 80, and a listener for port 443. tlsListeners are ignored if opt.SslKey is not provided

Directories

Path Synopsis
Package serve deals with serving objects over HTTP
Package serve deals with serving objects over HTTP

Jump to

Keyboard shortcuts

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