fcgi

Imports

Imports #

"context"
"errors"
"fmt"
"io"
"net"
"net/http"
"net/http/cgi"
"os"
"strings"
"time"
"bufio"
"bytes"
"encoding/binary"
"errors"
"io"
"sync"

Constants & Variables

ErrConnClosed var #

ErrConnClosed is returned by Read when a handler attempts to read the body of a request after the connection to the web server has been closed.

var ErrConnClosed = *ast.CallExpr

ErrRequestAborted var #

ErrRequestAborted is returned by Read when a handler attempts to read the body of a request that has been aborted by the web server.

var ErrRequestAborted = *ast.CallExpr

emptyBody var #

var emptyBody = *ast.CallExpr

errCloseConn var #

var errCloseConn = *ast.CallExpr

flagKeepConn const #

keep the connection between web-server and responder open after request

const flagKeepConn = 1

maxPad const #

const maxPad = 255

maxWrite const #

const maxWrite = 65535

pad var #

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

var pad [maxPad]byte

roleAuthorizer const #

const roleAuthorizer

roleFilter const #

const roleFilter

roleResponder const #

const roleResponder = *ast.BinaryExpr

statusCantMultiplex const #

const statusCantMultiplex

statusOverloaded const #

const statusOverloaded

statusRequestComplete const #

const statusRequestComplete = iota

statusUnknownRole const #

const statusUnknownRole

typeAbortRequest const #

const typeAbortRequest recType = 2

typeBeginRequest const #

const typeBeginRequest recType = 1

typeData const #

const typeData recType = 8

typeEndRequest const #

const typeEndRequest recType = 3

typeGetValues const #

const typeGetValues recType = 9

typeGetValuesResult const #

const typeGetValuesResult recType = 10

typeParams const #

const typeParams recType = 4

typeStderr const #

const typeStderr recType = 7

typeStdin const #

const typeStdin recType = 5

typeStdout const #

const typeStdout recType = 6

typeUnknownType const #

const typeUnknownType recType = 11

Type Aliases

recType type #

recType is a record type, as defined by https://web.archive.org/web/20150420080736/http://www.fastcgi.com/drupal/node/6?q=node/22#S8

type recType uint8

Structs

beginRequest struct #

type beginRequest struct {
role uint16
flags uint8
reserved [5]uint8
}

bufWriter struct #

bufWriter encapsulates bufio.Writer but also closes the underlying stream when Closed.

type bufWriter struct {
closer io.Closer
*bufio.Writer
}

child struct #

type child struct {
conn *conn
handler http.Handler
requests map[uint16]*request
}

conn struct #

conn sends records over rwc

type conn struct {
mutex sync.Mutex
rwc io.ReadWriteCloser
closeErr error
closed bool
buf bytes.Buffer
h header
}

envVarsContextKey struct #

envVarsContextKey uniquely identifies a mapping of CGI environment variables to their values in a request context

type envVarsContextKey struct {

}

record struct #

type record struct {
h header
buf [*ast.BinaryExpr]byte
}

request struct #

request holds the state for an in-progress request. As soon as it's complete, it's converted to an http.Request.

type request struct {
pw *io.PipeWriter
reqId uint16
params map[string]string
buf [1024]byte
rawParams []byte
keepConn bool
}

response struct #

response implements http.ResponseWriter.

type response struct {
req *request
header http.Header
code int
wroteHeader bool
wroteCGIHeader bool
w *bufWriter
}

streamWriter struct #

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

type streamWriter struct {
c *conn
recType recType
reqId uint16
}

Functions

Close method #

func (w *streamWriter) Close() error

Close method #

func (w *bufWriter) Close() error

Close method #

Close closes the conn if it is not already closed.

func (c *conn) Close() error

Close method #

func (r *response) Close() error

Flush method #

func (r *response) Flush()

ProcessEnv function #

ProcessEnv returns FastCGI environment variables associated with the request r for which no effort was made to be included in the request itself - the data is hidden in the request's context. As an example, if REMOTE_USER is set for a request, it will not be found anywhere in r, but it will be included in ProcessEnv's response (via r's context).

func ProcessEnv(r *http.Request) map[string]string

Serve function #

Serve accepts incoming FastCGI connections on the listener l, creating a new goroutine for each. The goroutine reads requests and then calls handler to reply to them. If l is nil, Serve accepts connections from os.Stdin. If handler is nil, [http.DefaultServeMux] is used.

func Serve(l net.Listener, handler http.Handler) error

Write method #

func (w *streamWriter) Write(p []byte) (int, error)

Write method #

func (r *response) Write(p []byte) (n int, err error)

WriteHeader method #

func (r *response) WriteHeader(code int)

addFastCGIEnvToContext function #

addFastCGIEnvToContext reports whether to include the FastCGI environment variable s in the http.Request.Context, accessible via ProcessEnv.

func addFastCGIEnvToContext(s string) bool

cleanUp method #

func (c *child) cleanUp()

content method #

func (r *record) content() []byte

encodeSize function #

func encodeSize(b []byte, size uint32) int

filterOutUsedEnvVars function #

filterOutUsedEnvVars returns a new map of env vars without the variables in the given envVars map that are read for creating each http.Request

func filterOutUsedEnvVars(envVars map[string]string) map[string]string

handleRecord method #

func (c *child) handleRecord(rec *record) error

init method #

func (h *header) init(recType recType, reqId uint16, contentLength int)

newChild function #

func newChild(rwc io.ReadWriteCloser, handler http.Handler) *child

newConn function #

func newConn(rwc io.ReadWriteCloser) *conn

newRequest function #

func newRequest(reqId uint16, flags uint8) *request

newResponse function #

func newResponse(c *child, req *request) *response

newWriter function #

func newWriter(c *conn, recType recType, reqId uint16) *bufWriter

parseParams method #

parseParams reads an encoded []byte into Params.

func (r *request) parseParams()

read method #

func (rec *record) read(r io.Reader) (err error)

read method #

func (br *beginRequest) read(content []byte) error

readSize function #

func readSize(s []byte) (uint32, int)

readString function #

func readString(s []byte, size uint32) string

serve method #

func (c *child) serve()

serveRequest method #

func (c *child) serveRequest(req *request, body io.ReadCloser)

writeCGIHeader method #

writeCGIHeader finalizes the header sent to the client and writes it to the output. p is not written by writeHeader, but is the first chunk of the body that will be written. It is sniffed for a Content-Type if none is set explicitly.

func (r *response) writeCGIHeader(p []byte)

writeEndRequest method #

func (c *conn) writeEndRequest(reqId uint16, appStatus int, protocolStatus uint8) error

writePairs method #

func (c *conn) writePairs(recType recType, reqId uint16, pairs map[string]string) error

writeRecord method #

writeRecord writes and sends a single record.

func (c *conn) writeRecord(recType recType, reqId uint16, b []byte) error

Generated with Arrow