Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 2.82 KB

README.md

File metadata and controls

76 lines (57 loc) · 2.82 KB

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"
    }
  }
}