Documentation
¶
Overview ¶
Package handlers implements extra HTTP middlewares.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GemlogToFeed ¶
type GemlogToFeed struct { // Format to output the feed as, either `rss`, `atom`, or `json`. Defaults // to `atom`. Format string `json:"format"` // Optional name to provide in the output feed under author metadata. AuthorName string `json:"author_name"` // Optional email to provide in the output feed under author metadata. AuthorEmail string `json:"author_email"` // Optional URL in format `[scheme://host[:port]]/path` to use as the // absolute URL all links in the feed will be relative to. If not given then // it will be inferred from the request. BaseURL string `json:"base_url"` // contains filtered or unexported fields }
GemlogToFeed is an HTTP middleware module which will convert a gemtext response document into an RSS, Atom, or JSON feed, by first intepreting the gemtext document as a gemlog and making an appropriate conversion from there.
func (GemlogToFeed) CaddyModule ¶
func (GemlogToFeed) CaddyModule() caddy.ModuleInfo
func (*GemlogToFeed) Provision ¶
func (g *GemlogToFeed) Provision(ctx caddy.Context) error
func (*GemlogToFeed) ServeHTTP ¶
func (g *GemlogToFeed) ServeHTTP( rw http.ResponseWriter, r *http.Request, next caddyhttp.Handler, ) error
func (*GemlogToFeed) Validate ¶
func (g *GemlogToFeed) Validate() error
type Gemtext ¶
type Gemtext struct { // Path to the template which will be used to render the HTML page, relative // to the `file_root`. // // The template will be rendered with these extra data fields: // // ##### `.Title` // // The Title of the gemini document, determined based on the first primary // header (single `#` prefix) found. This will be an empty string if no // primary header is found. // // ##### `.Body` // // A string containing all rendered HTML DOM elements. // TemplatePath string `json:"template"` // Path to a template which will be used for rendering headings. If not // given then headings will be rendered with appropriate HTML header tags. // // The template will be rendered with these extra data fields: // // ##### `.Level` // // Which level of heading is being rendered, 1, 2, or 3. // // ##### `.Text` // // The text of the heading. HeadingTemplatePath string `json:"heading_template"` // Path to a template which will be used for rendering links. If not given // then links will be rendered using an anchor tag wrapped in a paragraph // tag. // // The template will be rendered with these extra data fields: // // ##### `.URL` // // The URL the link points to. // // ##### `.Label` // // The label attached to the link. If the original link had no label then // this will be equivalent to `.URL`. LinkTemplatePath string `json:"link_template"` // The root path from which to load files. Default is `{http.vars.root}` if // set, or current working directory otherwise. FileRoot string `json:"file_root,omitempty"` // The template action delimiters. If set, must be precisely two elements: // the opening and closing delimiters. Default: `["{{", "}}"]` Delimiters []string `json:"delimiters,omitempty"` // contains filtered or unexported fields }
Gemtext is an HTTP middleware module which will render gemtext documents as HTML documents, using user-provided templates to do so.
Only responses with a Content-Type of `text/gemini` will be modified by this module.
func (*Gemtext) ServeHTTP ¶
type GitRemoteRepo ¶
type GitRemoteRepo struct { // The path of the git repo's directory. This directory will be created if // it doesn't already exist. Default is `{http.vars.root}` if set, or // current working directory otherwise. Path string `json:"path,omitempty"` }
GitRemoteRepo is an HTTP middleware module which will serve a git repo using either the [dumb or smart]git_transport HTTP protocols, allowing clients to push to or pull from the repo.
This module does _not_ deal with authentication or any other kind of access control, take care not to leave your private repos publicly exposed.
func (GitRemoteRepo) CaddyModule ¶
func (GitRemoteRepo) CaddyModule() caddy.ModuleInfo
func (*GitRemoteRepo) Provision ¶
func (g *GitRemoteRepo) Provision(ctx caddy.Context) error
func (*GitRemoteRepo) ServeHTTP ¶
func (g *GitRemoteRepo) ServeHTTP( rw http.ResponseWriter, r *http.Request, next caddyhttp.Handler, ) error
func (*GitRemoteRepo) Validate ¶
func (g *GitRemoteRepo) Validate() error
type ProofOfWork ¶
type ProofOfWork struct { // Secret is used to validate a PoW challenge seed. This string should never // be shared with clients, but _must_ be shared amongst all Caddy servers // which are serving the same domain. // // If not given then one will be generated on startup. Note that in this // case restarting Caddy will result in all clients requiring a new PoW // solution. Secret string `json:"secret,omitempty"` // Target is a uint32 indicating how difficult each challenge will be to // solve. A _lower_ Target value is more difficult than a higher one. // // Defaults to 0x000FFFFF Target uint32 `json:"target,omitempty"` // ChallengeTimeout indicates how long before Challenges are considered // expired and cannot be solved. Any solutions are also expired, and // browsers will be redirected back to the challenge page to solve a new // challenge. // // Defaults to 12h. ChallengeTimeout time.Duration `json:"challenge_timeout,omitempty"` // ChallengeSeedCookie indicates the name of the cookie which should be used // to store the challenge seed once a challenge has been solved. // // Defaults to "__pow_challenge_seed". ChallengeSeedCookie string `json:"challenge_seed_cookie,omitempty"` // ChallengeSolutionCookie indicates the name of the cookie which should be // used to store the challenge solution once a challenge has been solved. // // Defaults to "__pow_challenge_solution". ChallengeSolutionCookie string `json:"challenge_solution_cookie,omitempty"` // Path to HTML template to render in the browser when it is being // challenged. If not given then a simple default is shown. // // The template file should include the line // `<script>{{ template "pow.js" . }}</script>` at the end of the `body` // tag. This script will solve a challenge, set the solution to a cookie, // and reload the page. TemplatePath string `json:"template"` // contains filtered or unexported fields }
ProofOfWork is an HTTP middleware module which will intercept all requests and check that they were made by a browser which has performed a proof-of-work (PoW) challenge in the recent past.
Any requests which lack a PoW solution will be redirected to a page where a challenge will be automatically solved. The challenge and solution will be stored in cookies, and then the browser will be redirected back to the page it was originally trying to get to.
The objective of this middleware is to allow normal users to continue using a website, while trying to prevent search engine crawlers, denial-of-service attacks, and AI scrapers from getting through.
func (ProofOfWork) CaddyModule ¶
func (ProofOfWork) CaddyModule() caddy.ModuleInfo
func (*ProofOfWork) Cleanup ¶
func (p *ProofOfWork) Cleanup() error
func (*ProofOfWork) Provision ¶
func (p *ProofOfWork) Provision(ctx caddy.Context) error
func (*ProofOfWork) ServeHTTP ¶
func (p *ProofOfWork) ServeHTTP( rw http.ResponseWriter, r *http.Request, next caddyhttp.Handler, ) error
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
templates
|
|
functions
Package functions makes available extra functions within templates being processed by the `http.handlers.templates` directive.
|
Package functions makes available extra functions within templates being processed by the `http.handlers.templates` directive. |