Go API Documentation

github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi

No package summary is available.

Package

Files: 7. Third party imports: 2. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

Vars

for padding so we don't have to allocate all the time not synchronized because we don't care what the contents are

Map of supported protocols to Apache ssl_mod format Note that these are slightly different from SupportedProtocols in caddytls/config.go

Types

Transport

Transport facilitates FastCGI communication.

Field name Field type Comment
Root

string

Use this directory as the fastcgi root directory. Defaults to the root directory of the parent virtual host.

SplitPath

[]string

The path in the URL will be split into two, with the first piece ending with the value of SplitPath. The first piece will be assumed as the actual resource (CGI script) name, and the second piece will be set to PATH_INFO for the CGI script to use.

Future enhancements should be careful to avoid CVE-2019-11043, which can be mitigated with use of a try_files-like behavior that 404s if the fastcgi path info is not found.

ResolveRootSymlink

bool

Path declared as root directory will be resolved to its absolute value after the evaluation of any symbolic links. Due to the nature of PHP opcache, root directory path is cached: when using a symlinked directory as root this could generate errors when symlink is changed without php-fpm being restarted; enabling this directive will set $_SERVER['DOCUMENT_ROOT'] to the real directory path.

EnvVars

map[string]string

Extra environment variables.

DialTimeout

caddy.Duration

The duration used to set a deadline when connecting to an upstream. Default: 3s.

ReadTimeout

caddy.Duration

The duration used to set a deadline when reading from the FastCGI server.

WriteTimeout

caddy.Duration

The duration used to set a deadline when sending to the FastCGI server.

CaptureStderr

bool

Capture and log any messages sent by the upstream on stderr. Logs at WARN level by default. If the response has a 4xx or 5xx status ERROR level will be used instead.

serverSoftware

string

No comment on field.
logger

*zap.Logger

No comment on field.

client

client implements a FastCGI client, which is a standard for interfacing external applications with Web servers.

Field name Field type Comment
rwc

net.Conn

No comment on field.
reqID

uint16

keepAlive bool // TODO: implement

stderr

bool

No comment on field.
logger

*zap.Logger

No comment on field.

clientCloser

clientCloser is a io.ReadCloser. It wraps a io.Reader with a Closer that closes the client connection.

Field name Field type Comment
rwc

net.Conn

No comment on field.
r

*streamReader

No comment on field.

io.Reader

No comment on field.
status

int

No comment on field.
logger

*zap.Logger

No comment on field.

envVars

This type doesn't have documentation.

Field name Field type Comment
type

map[string]string

No comment on field.

This type doesn't have documentation.

Field name Field type Comment
Version

uint8

No comment on field.
Type

uint8

No comment on field.
ID

uint16

No comment on field.
ContentLength

uint16

No comment on field.
PaddingLength

uint8

No comment on field.
Reserved

uint8

No comment on field.

loggableEnv

loggableEnv is a simple type to allow for speeding up zap log encoding.

Field name Field type Comment
vars

envVars

No comment on field.
logCredentials

bool

No comment on field.

record

This type doesn't have documentation.

Field name Field type Comment
h

header

No comment on field.
lr

io.LimitedReader

No comment on field.
padding

int64

No comment on field.

streamReader

This type doesn't have documentation.

Field name Field type Comment
c

*client

No comment on field.
rec

record

No comment on field.
stderr

bytes.Buffer

No comment on field.

streamWriter

streamWriter abstracts out the separation of a stream into discrete records. It only writes maxWrite bytes at a time.

Field name Field type Comment
c

*client

No comment on field.
h

header

No comment on field.
buf

*bytes.Buffer

No comment on field.
recType

uint8

No comment on field.

Functions

func (*Transport) Provision

Provision sets up t.

Uses: time.Second.

func (*Transport) UnmarshalCaddyfile

UnmarshalCaddyfile deserializes Caddyfile tokens into h.

transport fastcgi {
    root <path>
    split <at>
    env <key> <value>
    resolve_root_symlink
    dial_timeout <duration>
    read_timeout <duration>
    write_timeout <duration>
    capture_stderr
}

func (*client) Do

Do made the request and returns a io.Reader that translates the data read from fcgi responder out of fcgi packet before returning it.

Uses: bytes.Buffer, caddyhttp.Error, http.StatusLengthRequired, io.Copy, strconv.ParseUint.

func (*client) Get

Get issues a GET request to the fcgi responder.

Uses: strconv.FormatInt.

Head issues a HEAD request to the fcgi responder.

func (*client) Options

Options issues an OPTIONS request to the fcgi responder.

func (*client) Post

Post issues a POST request to the fcgi responder. with request body in the format that bodyType specified

Uses: strconv.FormatInt, strings.ToUpper.

func (*client) PostFile

PostFile issues a POST to the fcgi responder in multipart(RFC 2046) standard, with form as a string key to a list values (url.Values), and/or with file as a string key to a list file path.

Uses: bytes.Buffer, filepath.Base, io.Copy, multipart.NewWriter, os.Open.

func (*client) PostForm

PostForm issues a POST to the fcgi responder, with form as a string key to a list values (url.Values)

Uses: bytes.NewReader.

func (*client) Request

Request returns a HTTP Response with Header and Body from fcgi responder

Uses: bufio.NewReader, http.Header, http.Response, http.StatusOK, httputil.NewChunkedReader, io.EOF, strconv.Atoi, strconv.ParseInt, strings.Cut, textproto.NewReader.

func (*client) SetReadTimeout

SetReadTimeout sets the read timeout for future calls that read from the fcgi responder. A zero value for t means no timeout will be set.

Uses: time.Now.

func (*client) SetWriteTimeout

SetWriteTimeout sets the write timeout for future calls that send data to the fcgi responder. A zero value for t means no timeout will be set.

Uses: time.Now.

func (*record) Read

func (*streamReader) Read

Uses: io.Copy.

func (*streamWriter) Flush

Flush write buffer data to the underlying connection, it assumes header data is the first 8 bytes of buf

func (*streamWriter) FlushStream

FlushStream flush data then end current stream

func (*streamWriter) Write

func (Transport) CaddyModule

CaddyModule returns the Caddy module information.

func (Transport) RoundTrip

RoundTrip implements http.RoundTripper.

Uses: caddyhttp.Error, caddyhttp.LoggableHTTPRequest, caddyhttp.Server, caddyhttp.ServerCtxKey, fmt.Errorf, http.MethodGet, http.MethodHead, http.MethodOptions, http.Response, http.StatusBadRequest, net.Dialer, reverseproxy.GetDialInfo, strconv.ParseInt, strings.Contains, time.Duration, zap.Object, zap.String, zapcore.DebugLevel.

func (clientCloser) Close

Uses: zap.ByteString, zapcore.ErrorLevel, zapcore.WarnLevel.

func (loggableEnv) MarshalLogObject

Uses: strings.ToLower.

Private functions

func chunked

Checks whether chunked is part of the encodings stack

func encodeSize

References: binary.BigEndian.

func init

References: httpcaddyfile.RegisterDirective.

func parsePHPFastCGI

parsePHPFastCGI parses the php_fastcgi directive, which has the same syntax as the reverse_proxy directive (in fact, the reverse_proxy's directive Unmarshaler is invoked by this function) but the resulting proxy is specially configured for most™️ PHP apps over FastCGI. A line such as this:

php_fastcgi localhost:7777

is equivalent to a route consisting of:

# Add trailing slash for directory requests
# This redirection is automatically disabled if "{http.request.uri.path}/index.php"
# doesn't appear in the try_files list
@canonicalPath {
    file {path}/index.php
    not path */
}
redir @canonicalPath {path}/ 308

# If the requested file does not exist, try index files and assume index.php always exists
@indexFiles file {
    try_files {path} {path}/index.php index.php
    try_policy first_exist_fallback
    split_path .php
}
rewrite @indexFiles {http.matchers.file.relative}

# Proxy PHP files to the FastCGI responder
@phpFiles path *.php
reverse_proxy @phpFiles localhost:7777 {
    transport fastcgi {
        split .php
    }
}

Thus, this directive produces multiple handlers, each with a different matcher because multiple consecutive handlers are necessary to support the common PHP use case. If this "common" config is not compatible with a user's PHP requirements, they can use a manual approach based on the example above to configure it precisely as they need.

If a matcher is specified by the user, for example:

php_fastcgi /subpath localhost:7777

then the resulting handlers are wrapped in a subroute that uses the user's matcher as a prerequisite to enter the subroute. In other words, the directive's matcher is necessary, but not sufficient.

References: caddyconfig.JSONModuleObject, caddyhttp.MatchNot, caddyhttp.MatchPath, caddyhttp.Route, caddyhttp.RouteList, caddyhttp.StaticResponse, caddyhttp.Subroute, caddyhttp.WeakString, fileserver.MatchFile, http.Header, http.StatusPermanentRedirect, httpcaddyfile.ConfigValue, json.RawMessage, reverseproxy.Handler, rewrite.Rewrite, slices.Contains, strconv.Itoa, strings.HasSuffix.

func init

func fill

References: binary.BigEndian, binary.Read, errors.New, io.Copy, io.Discard, io.EOF.

func hasMore

func endStream

func writeBeginRequest

func writeHeader

writeHeader populate header wire data in buf, it abuses buffer.Bytes() modification

References: binary.BigEndian.

func writePairs

func writeRecord

func buildEnv

buildEnv returns a set of CGI environment variables for the request.

References: caddyhttp.OriginalRequestCtxKey, caddyhttp.SanitizedPathJoin, caddytls.SupportedCipherSuites, filepath.EvalSymlinks, http.Request, net.SplitHostPort, strings.HasPrefix, strings.Join, strings.LastIndex, strings.Replace, strings.ToUpper, strings.TrimSuffix.

func splitPos

splitPos returns the index where path should be split based on t.SplitPath.

References: strings.Index, strings.ToLower.


Tests

Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

Vars

Types

FastCGIServer

This type doesn't have documentation.