cgi

Imports

Imports #

"fmt"
"io"
"maps"
"net/http"
"os"
"path"
"slices"
"strings"
"time"
"bufio"
"crypto/tls"
"errors"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"bufio"
"fmt"
"io"
"log"
"net"
"net/http"
"net/textproto"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"golang.org/x/net/http/httpguts"

Constants & Variables

osDefaultInheritEnv var #

var osDefaultInheritEnv = *ast.CallExpr

testHookStartProcess var #

var testHookStartProcess func(*os.Process)

trailingPort var #

var trailingPort = *ast.CallExpr

Type Aliases

neverEnding type #

type neverEnding byte

Structs

Handler struct #

Handler runs an executable in a subprocess with a CGI environment.

type Handler struct {
Path string
Root string
Dir string
Env []string
InheritEnv []string
Logger *log.Logger
Args []string
Stderr io.Writer
PathLocationHandler http.Handler
}

response struct #

type response struct {
req *http.Request
header http.Header
code int
wroteHeader bool
wroteCGIHeader bool
bufw *bufio.Writer
}

Functions

Flush method #

func (r *response) Flush()

Read method #

func (b neverEnding) Read(p []byte) (n int, err error)

Request function #

Request returns the HTTP request as represented in the current environment. This assumes the current program is being run by a web server in a CGI environment. The returned Request's Body is populated, if applicable.

func Request() (*http.Request, error)

RequestFromMap function #

RequestFromMap creates an [http.Request] from CGI variables. The returned Request's Body field is not populated.

func RequestFromMap(params map[string]string) (*http.Request, error)

Serve function #

Serve executes the provided [Handler] on the currently active CGI request, if any. If there's no current CGI environment an error is returned. The provided handler may be nil to use [http.DefaultServeMux].

func Serve(handler http.Handler) error

ServeHTTP method #

func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Write method #

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

WriteHeader method #

func (r *response) WriteHeader(code int)

cgiMain function #

func cgiMain()

childCGIProcess function #

childCGIProcess is used by integration_test to complete unit tests.

func childCGIProcess()

envMap function #

func envMap(env []string) map[string]string

handleInternalRedirect method #

func (h *Handler) handleInternalRedirect(rw http.ResponseWriter, req *http.Request, path string)

printf method #

func (h *Handler) printf(format string, v ...any)

removeLeadingDuplicates function #

removeLeadingDuplicates remove leading duplicate in environments. It's possible to override environment like following. cgi.Handler{ ... Env: []string{"SCRIPT_FILENAME=foo.php"}, }

func removeLeadingDuplicates(env []string) (ret []string)

stderr method #

func (h *Handler) stderr() io.Writer

testCGI function #

testCGI is a CGI program translated from a Perl program to complete host_test. test cases in host_test should be provided by testCGI.

func testCGI()

upperCaseAndUnderscore function #

func upperCaseAndUnderscore(r rune) rune

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)

Generated with Arrow