requestid

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 7 Imported by: 1

README

Caddy Request ID

Caddy v2 Module that sets unique request ID placeholders.

Usage

Caddyfile
request_id [<length>] {
  [<key> <length>]
  ...
}
  • length - length of ID to generate, defaults to 21
  • key, length - additional keys to generate independent IDs for

If you wish to use the directive in a top level block, you must explicitly define the order.

{
  order request_id before header
}
JSON Config
{
  "handler": "request_id",
  "length": 21, // optional
  "additional": { // optional
    "header": 21,
  }
}
Placeholders

The top level request ID will be set in the {http.request_id} placeholder. Any additional IDs will be set in the {http.request_id.<key>} placeholder.

Example

The following example Caddyfile sets a different request ID for response bodies and headers.

{
  order request_id before header
}

localhost {
  request_id {
    body 10
    header 21
  }

  header * x-request-id "{http.request_id.header}"
  respond * "{http.request_id.body}" 200
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RequestID

type RequestID struct {
	// Length of standalone ID
	Length int `json:"length"`

	// Map of additional IDs to set
	Additional map[string]int `json:"additional,omitempty"`
}

RequestID implements an HTTP handler that writes a unique request ID to response headers.

func (RequestID) CaddyModule

func (RequestID) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*RequestID) Provision

func (m *RequestID) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (RequestID) ServeHTTP

func (m RequestID) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*RequestID) UnmarshalCaddyfile

func (m *RequestID) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile - this is a no-op

Jump to

Keyboard shortcuts

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