requestbodyvar

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: MIT Imports: 15 Imported by: 0

README

requestbodyvar

A Caddy v2 extension to add support for the {http.request.body.*} placeholder (variable).

Installation

$ xcaddy build --with github.com/RussellLuo/caddy-ext/requestbodyvar

Example

With the following Caddyfile:

localhost:8080 {
    route / {
        request_body_var

        respond {http.request.body.name}
    }
}

You can get the responses as below:

$ curl -XPOST https://localhost:8080 -d '{"name":"caddy"}'
caddy
$ curl -XPOST https://localhost:8080 -d '{"name":"wow"}'
wow

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSON

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

func (JSON) Query

func (j JSON) Query(key string) string

type Querier

type Querier interface {
	Query(string) string
}

type RequestBodyVar

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

RequestBodyVar implements an HTTP handler that replaces {http.request.body.*} with the value of the given field from request body, if any.

func (RequestBodyVar) CaddyModule

func (RequestBodyVar) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*RequestBodyVar) Provision

func (rbv *RequestBodyVar) Provision(ctx caddy.Context) (err error)

Provision implements caddy.Provisioner.

func (RequestBodyVar) ServeHTTP

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

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*RequestBodyVar) UnmarshalCaddyfile

func (rbv *RequestBodyVar) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile - this is a no-op

type XML

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

func (XML) Query

func (x XML) Query(key string) string

Jump to

Keyboard shortcuts

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