knut

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: BSD-3-Clause Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   = "dev-build"
	GitHash   = ""
	BuildDate = ""
)

Functions

func AddServerIDHandler

func AddServerIDHandler(next http.Handler, serverID string) http.Handler

addServerIDHandler adds "Server: <serverID>" to the response header

func BasicAuthHandler

func BasicAuthHandler(next http.Handler, username, password string) http.Handler

basicAuthHandler checks the submited username and password against predefined values.

func CgitHandler

func CgitHandler(path, uri string) http.Handler

cgitHandler will call "cgit" via /uri:cgit://path/to/dir. "cgit" uses a configuration file given via the environment variable CGIT_CONFIG. if that file is not given, a simple one is created for the user. that created file is deleted when **knut** shuts down. it's main purpose is to set the scan-path directive to "." which makes cgit scan the directory given via the uri. if the user places a "cgitrc" file into the .git folder of a scanned git-repo, the "repo.*" options are applied there. eg,

knut.git/.git/cgitrc
                    desc=knut - throws trees out of windows

will make that directory be listed with that description.

func CompressHandler

func CompressHandler(handler http.Handler) http.Handler

compressHandler requests having Accept-Encoding 'deflate' or 'gzip' taken from https://github.com/gorilla/handlers/blob/master/compress.go

func FileOrDirHandler

func FileOrDirHandler(path, uri string) http.Handler

func GetWindowAndTree

func GetWindowAndTree(arg string) (window, tree string, err error)

getWindowAndTree splits "arg" at the ':' separator. in the context of *knut* the first part is called "window" (it is the url-endpoint, essentially), the part after the first ':' is called "the tree", it's the content that will be delivered.

func GitHandler

func GitHandler(path, uri string) http.Handler

gitHandler serves the given directory via "git http-backend". the advantage of using "git http-backend" is that it supports the more clever way of offering a git repository (opposite to the dumb http-protocol also possible)

see https://git-scm.com/docs/git-http-backend

func GzHandler

func GzHandler(next http.Handler, clevel string) http.Handler

func HasQueryParam

func HasQueryParam(key string, vals url.Values) bool

func LocalFilename

func LocalFilename(fileURL *url.URL) string

func LogRequestHandler

func LogRequestHandler(handler http.Handler, logWriter io.Writer) http.Handler

logRequestHandler returns a handler which logs all requests to 'writer'. it also captures the status-code

func MyIPHandler

func MyIPHandler() http.Handler

myIPHandler yells back the remote IP to the browser

func NoCacheHandler

func NoCacheHandler(next http.Handler) http.Handler

noCacheHandler adds a 'nocaching, please' hint to the response header

func QrHandler

func QrHandler(content string) http.Handler

func RedirectHandler

func RedirectHandler(path, location string) http.Handler

func ServeFileHandler

func ServeFileHandler(name string) http.Handler

serveFileHandler serves the file given by 'name'

func ServeStringHandler

func ServeStringHandler(str string) http.Handler

serveStringHandler writes given 'str' to the response

func SetContentType

func SetContentType(next http.Handler, contentType string) http.Handler

setContentType sets the "Content-Type" to "contentType", if not already set

func TarHandler

func TarHandler(dir, prefix string) http.Handler

tarHandler creates a tar-archive from 'dir' on the fly and writes it to 'w'

func UploadHandler

func UploadHandler(dir string) http.Handler

uploadHandler handles uploads to a given 'dir'. for method "GET" an upload-form is rendered, "POST" handles the actual upload

func ZipDirectory

func ZipDirectory(w io.Writer, dir, prefix string, store bool) error

zipDirectory creates a .zip from "dir" and writes it to "w". it also prepends "prefix" to each name.

func ZipFSHandler

func ZipFSHandler(name, prefix, index string) http.Handler

zipFSHandler provides access to the contents of the .zip file specified by "name".

if "prefix" is applied to all requests, eg: a "/foo/bar" request is tried to find as "/prefix/foo/bar" in the zip file.

if the requested path is a folder, use the "index" in that folder to to render the folder entries.

func ZipHandler

func ZipHandler(dir, prefix string, store bool) http.Handler

Types

type OnetimeTLS

type OnetimeTLS struct {
	Listener net.Listener
	// contains filtered or unexported fields
}

func (*OnetimeTLS) Create

func (ot *OnetimeTLS) Create(addr string) error

create an in-memory root-certificate, sign it with an in-memory private key (elliptic curve521), and create a tlsListener based upon that certificate. it's only purpose is to have a tls-cert with a onetime, throw-away certificate. fyi: http://safecurves.cr.yp.to/

type Opts

type Opts struct {
	BindAddr       string
	DoLog          bool
	DoAuth         string
	DoCompress     bool
	DoPrintVersion bool
	AddServerID    string
	TlsOnetime     bool
	TlsCert        string
	TlsKey         string
}

func SetupFlags

func SetupFlags(f *flag.FlagSet) *Opts

Jump to

Keyboard shortcuts

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