Documentation
¶
Overview ¶
Package gofcgisrv implements the webserver side of the CGI, FastCGI, and SCGI protocols.
CGI: http://tools.ietf.org/html/rfc3875 FastCGI: http://www.fastcgi.com/drupal/node/6?q=node/22 SCGI: http://python.ca/scgi/protocol.txt protocols.
Example (Php) ¶
package main import ( "fmt" "io/ioutil" "net/http" "net/http/httptest" "path" "strings" ) func phpCgiHandler(w http.ResponseWriter, r *http.Request) { filepath := path.Join("./testdata/", r.URL.Path) env := []string{ "REDIRECT_STATUS=200", "SCRIPT_FILENAME=" + filepath, } ServeHTTP(NewCGI("php-cgi"), env, w, r) } func main() { server := httptest.NewServer(http.HandlerFunc(phpCgiHandler)) defer server.Close() url := server.URL text := "This is a test!" resp, err := http.Post(url+"/echo.php", "text/plain", strings.NewReader(text)) if err == nil { fmt.Printf("Status: %v\n", resp.StatusCode) body, _ := ioutil.ReadAll(resp.Body) resp.Body.Close() fmt.Printf("Response: %s\n", body) } }
Output: Status: 200 Response: This is a test!
Index ¶
- func HTTPEnv(start []string, r *http.Request) []string
- func ProcessResponse(stdout io.Reader, w http.ResponseWriter, r *http.Request) error
- func ServeHTTP(s Requester, env []string, w http.ResponseWriter, r *http.Request)
- type CGIRequester
- type Dialer
- type FCGIRequester
- type Requester
- type RequesterFunc
- type SCGIRequester
- type StdinDialer
- type TCPDialer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProcessResponse ¶
ProcessResponse adds any returned header data to the response header and sends the rest to the response body.
Types ¶
type CGIRequester ¶
type CGIRequester struct {
// contains filtered or unexported fields
}
A CGI server.
func NewCGI ¶
func NewCGI(cmd string, args ...string) *CGIRequester
type FCGIRequester ¶
type FCGIRequester struct { // Parameters of the application CanMultiplex bool MaxConns int MaxRequests int // contains filtered or unexported fields }
Server is the external interface. It manages connections to a single FastCGI application. A server may maintain many connections, each of which may multiplex many requests.
func NewFCGI ¶
func NewFCGI(applicationAddr string) *FCGIRequester
NewServer creates a server that will attempt to connect to the application at the given address over TCP.
func NewFCGIStdin ¶
func NewFCGIStdin(app string, args ...string) *FCGIRequester
NewFCGIStdin creates a server that runs the app and connects over stdin.
func (*FCGIRequester) GetValues ¶
func (s *FCGIRequester) GetValues() error
PHP barfs on FCGI_GET_VALUES. I don't know why. Maybe it expects a different connection. For now don't do it unless asked.
func (*FCGIRequester) Request ¶
func (s *FCGIRequester) Request(env []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error
Request executes a request using env and stdin as inputs and stdout and stderr as outputs. env should be a slice of name=value pairs. It blocks until the application has finished.
func (*FCGIRequester) ServeHTTP ¶
func (s *FCGIRequester) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves an HTTP request.
type Requester ¶
type Requester interface {
Request(env []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error
}
Requester is the interface for any CGI-like protocol server.
type RequesterFunc ¶
Wrapper for functions
type SCGIRequester ¶
type SCGIRequester struct {
// contains filtered or unexported fields
}
func NewSCGI ¶
func NewSCGI(addr string) *SCGIRequester
type StdinDialer ¶
type StdinDialer struct {
// contains filtered or unexported fields
}
StdinDialer managers an app as a child process, creating a socket and passing it through stdin.
func (*StdinDialer) Close ¶
func (sd *StdinDialer) Close()
func (*StdinDialer) Start ¶
func (sd *StdinDialer) Start() error