debug

package module
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: Apache-2.0 Imports: 14 Imported by: 12

README

caddy-trace

Request Debugging Middleware Plugin for Caddy v2.

Table of Contents

Overview

The plugin is a middleware which displays the content of the request it handles. It helps troubleshooting web requests by exposing headers (e.g. cookies), URL parameters, etc.

For background, the idea for the creation of plugin came during a development of another plugin which rewrites headers of web requests. There was a need to compare "before and after" content of the request.

The trace directive gets inserted prior to the plugin which modifies a request and immediately after it. The log with the content of the request show up twice and it is easy to compare the two.

Getting Started

Add trace handler to enable this plugin.

The disabled=yes argument disables the operation of the plugin.

The tag argument injects the value in the log output. This way, one can have multiple handlers and there is a way to deferentiate between them.

The response_debug argument instructs the plugin to buffer responses and log response related metadata, i.e. status codes, length, etc.

The uri_filter directive instructs the plugin to intercepts only the requests with the URI matching the regular expression in the filter.

When a request arrives for /version, the plugin will be triggered two (2) times. The first handler is disables. The two (2) other handlers will trigger with different tags. The respond handler is terminal and it means the handler with marvel tag will not trigger.

When a request arrives for /whoami, the plugin will be triggered three (2) times because respond /version will not terminate the handling of the plugin. Notably, the plugin will output response metadata due to the presence of response_debug argument.

{
  http_port     9080
  https_port    9443
}

localhost:9080 {
  route {
    trace disabled=yes
    trace disabled=no tag="foo"
    trace disabled=no tag="bar"
    respond /version "1.0.0" 200
    trace tag="marvel" response_debug=yes
    trace tag="custom" response_debug=yes uri_filter="^/whoami$"
    respond /whoami 200 {
      body "greenpau"
    }
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RequestDebugger

type RequestDebugger struct {
	// Enables or disables the plugin.
	Disabled bool `json:"disabled,omitempty"`
	// Adds a tag to a log message
	Tag string `json:"tag,omitempty"`
	// Adds response buffering and debugging
	ResponseDebugEnabled bool `json:"response_debug_enabled,omitempty"`
	// If URIFilter is not empty, then only the plugin
	// intercepts only the pages matching the regular expression
	// in the filter
	URIFilter string `json:"uri_filter,omitempty"`
	// contains filtered or unexported fields
}

RequestDebugger is a middleware which displays the content of the request it handles. It helps troubleshooting web requests by exposing headers (e.g. cookies), URL parameters, etc.

func (RequestDebugger) CaddyModule

func (RequestDebugger) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*RequestDebugger) Provision

func (dbg *RequestDebugger) Provision(ctx caddy.Context) error

Provision sets up RequestDebugger.

func (RequestDebugger) ServeHTTP

func (dbg RequestDebugger) ServeHTTP(resp http.ResponseWriter, req *http.Request, next caddyhttp.Handler) error

Jump to

Keyboard shortcuts

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