inspect

package module
v0.0.0-...-96cdb1d Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 17 Imported by: 0

README

caddy-inspect

The Inspect plugin provides an easy way to inspect HTTP requests in Caddy.

The Caddyfile is already easy to write. The Inspect plugin takes it a step further by allowing you to place breakpoints in the Caddyfile and ascertain the behaviour of Caddy.

Screenshot

Features

  • Insert a breakpoint anywhere in the Caddyfile with the inspect keyword.
  • Inspecting HTTP and Caddy contexts
  • Intercepting and terminating HTTP requests and responses
  • Works in the browser, zero setup required.

Installation

xcaddy build --with github.com/abiosoft/caddy-inspect

Getting Started

Specify breakpoints in the Caddyfile

Place the inspect keyword anywhere an HTTP directive is supported in the Caddyfile. The keyword can be specified multiple times.

:8080

route /api {
    rewrite /api/* /api/v1{uri}
    inspect
    ...
}
Start Caddy

Caddy can be started with the --watch flag to autoreload the Caddyfile on each modification.

caddy run --watch
Access the Inspect console

Open http://localhost:2020 in the browser to access the console.

[!NOTE] Another port would be assigned if 2020 is not available. The URL can be confirmed in the Caddy logs.

Enjoy

Any HTTP request(s) made to a route containing the inspect keyword would pause the request and activate the console.

Caveats

[!CAUTION] This plugin is intended for development purposes only, sensitive information may be exposed if used in a production environment.

  • The plugin is tailored towards Caddyfile config. However, JSON config can be used with limited experience.
  • Due to the in-built order of directives in Caddy, inspect is more predictable in a route block. Otherwise, it is ordered after the encode directive.
  • The information displayed are read-only and cannot be modified.
  • HTTP request and response bodies cannot be inspected. It is a deliberate limitation until there is a strong argument in favour.
  • The plugin stemmed from a personal use-case. Feedbacks would be appreciated to accommodate more use-cases.

Attribution

The Caddy logo is a trademark of Caddy Web Server.

License

MIT

Sponsoring

You can support the author by donating on Github Sponsors or Buy me a coffee.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware struct {
	Key string
	// contains filtered or unexported fields
}

Middleware implements an HTTP handler that inspects the current request.

func (Middleware) CaddyModule

func (Middleware) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*Middleware) Provision

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

Provision implements caddy.Provisioner.

func (Middleware) ServeHTTP

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

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*Middleware) UnmarshalCaddyfile

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

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

func (*Middleware) Validate

func (m *Middleware) Validate() error

Validate implements caddy.Validator.

type Response

type Response struct {
	URL             string      `json:"url,omitempty"`
	Method          string      `json:"method,omitempty"`
	Host            string      `json:"host,omitempty"`
	RequestHeaders  http.Header `json:"request_headers,omitempty"`
	ResponseHeaders http.Header `json:"response_headers,omitempty"`
	RemoteAddress   string      `json:"remote_address,omitempty"`
	Form            string      `json:"form,omitempty"`
	Proto           string      `json:"proto,omitempty"`
	UserAgent       string      `json:"user_agent,omitempty"`
	Referer         string      `json:"referer,omitempty"`
	ContentLength   int64       `json:"content_length,omitempty"`
	BasicAuth       *struct {
		Username string `json:"username,omitempty"`
		Password string `json:"password,omitempty"`
	} `json:"basic_auth,omitempty"`
	Cookies      []*http.Cookie `json:"cookies,omitempty"`
	CaddyVersion string         `json:"caddy_version,omitempty"`
	CaddyContext struct {
		Variables map[string]any `json:"Variables,omitempty"`
		Modules   []string       `json:"Modules,omitempty"`
		Error     any            `json:"Error,omitempty"`
	} `json:"caddy_context,omitempty"`
	CaddyModules []string `json:"caddy_modules,omitempty"`
	Caddyfile    *struct {
		File            string   `json:"file,omitempty"`
		Line            int      `json:"line,omitempty"`
		Source          []string `json:"source,omitempty"`
		SourceLineStart int      `json:"source_line_start,omitempty"`
	} `json:"caddyfile,omitempty"`
	MemoryUsage string `json:"memory_usage,omitempty"`
	// contains filtered or unexported fields
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

Jump to

Keyboard shortcuts

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