version: 1.10

package cgi

import "net/http/cgi"

Overview

Package cgi implements CGI (Common Gateway Interface) as specified in RFC 3875.

Note that using CGI means starting a new process to handle each request, which
is typically less efficient than using a long-running server. This package is
intended primarily for compatibility with existing systems.

Index

Package files

child.go host.go

func Request

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

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 RequestFromMap

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

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

func Serve

  1. func Serve(handler http.Handler) error

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.

type Handler

  1. type Handler struct {
  2. Path string // path to the CGI executable
  3. Root string // root URI prefix of handler or empty for "/"
  4.  
  5. // Dir specifies the CGI executable's working directory.
  6. // If Dir is empty, the base directory of Path is used.
  7. // If Path has no base directory, the current working
  8. // directory is used.
  9. Dir string
  10.  
  11. Env []string // extra environment variables to set, if any, as "key=value"
  12. InheritEnv []string // environment variables to inherit from host, as "key"
  13. Logger *log.Logger // optional log for errors or nil to use log.Print
  14. Args []string // optional arguments to pass to child process
  15. Stderr io.Writer // optional stderr for the child process; nil means os.Stderr
  16.  
  17. // PathLocationHandler specifies the root http Handler that
  18. // should handle internal redirects when the CGI process
  19. // returns a Location header value starting with a "/", as
  20. // specified in RFC 3875 § 6.3.2. This will likely be
  21. // http.DefaultServeMux.
  22. //
  23. // If nil, a CGI response with a local URI path is instead sent
  24. // back to the client and not redirected internally.
  25. PathLocationHandler http.Handler
  26. }

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

func (*Handler) ServeHTTP

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