Go API Documentation

github.com/caddyserver/caddy/v2/modules/caddyhttp/intercept

No package summary is available.

Package

Files: 1. Third party imports: 2. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

Vars

Types

Intercept

Intercept is a middleware that intercepts then replaces or modifies the original response. It can, for instance, be used to implement X-Sendfile/X-Accel-Redirect-like features when using modules like FrankenPHP or Caddy Snake.

EXPERIMENTAL: Subject to change or removal.

Field name Field type Comment
HandleResponse

[]caddyhttp.ResponseHandler

List of handlers and their associated matchers to evaluate after successful response generation. The first handler that matches the original response will be invoked. The original response body will not be written to the client; it is up to the handler to finish handling the response.

Three new placeholders are available in this handler chain:

  • {http.intercept.status_code} The status code from the response
  • {http.intercept.header.*} The headers from the response
responseMatchers

map[string]caddyhttp.ResponseMatcher

Holds the named response matchers from the Caddyfile while adapting

handleResponseSegments

[]*caddyfile.Dispenser

Holds the handle_response Caddyfile tokens while adapting

logger

*zap.Logger

No comment on field.

interceptedResponseHandler

TODO: handle status code replacement

EXPERIMENTAL: Subject to change or removal.

Field name Field type Comment

caddyhttp.ResponseRecorder

No comment on field.
replacer

*caddy.Replacer

No comment on field.
handler

caddyhttp.ResponseHandler

No comment on field.
handlerIndex

int

No comment on field.
statusCode

int

No comment on field.

Functions

func (*Intercept) FinalizeUnmarshalCaddyfile

FinalizeUnmarshalCaddyfile finalizes the Caddyfile parsing which requires having an httpcaddyfile.Helper to function, to parse subroutes.

EXPERIMENTAL: Subject to change or removal.

Uses: caddyhttp.ResponseHandler, caddyhttp.ResponseMatcher, caddyhttp.Subroute, httpcaddyfile.ParseSegmentAsSubroute, strings.HasPrefix.

func (*Intercept) Provision

Provision ensures that i is set up properly before use.

EXPERIMENTAL: Subject to change or removal.

Uses: fmt.Errorf.

func (*Intercept) UnmarshalCaddyfile

UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:

intercept [<matcher>] {
    # intercept original responses
    @name {
        status <code...>
        header <field> [<value>]
    }
    replace_status [<matcher>] <status_code>
    handle_response [<matcher>] {
        <directives...>
    }
}

The FinalizeUnmarshalCaddyfile method should be called after this to finalize parsing of "handle_response" blocks, if possible.

EXPERIMENTAL: Subject to change or removal.

Uses: caddyhttp.ParseNamedResponseMatcher, caddyhttp.ResponseHandler, caddyhttp.ResponseMatcher, caddyhttp.WeakString, strings.HasPrefix.

func (Intercept) CaddyModule

CaddyModule returns the Caddy module information.

EXPERIMENTAL: Subject to change or removal.

func (Intercept) ServeHTTP

EXPERIMENTAL: Subject to change or removal.

Uses: bytes.Buffer, caddyhttp.NewResponseRecorder, http.Header, http.StatusInternalServerError, strconv.Atoi, strings.Join, zap.Int, zapcore.DebugLevel.

func (interceptedResponseHandler) Unwrap

EXPERIMENTAL: Subject to change or removal.

func (interceptedResponseHandler) WriteHeader

EXPERIMENTAL: Subject to change or removal.

Private functions

func init

References: httpcaddyfile.RegisterHandlerDirective.

func parseCaddyfile