Skip to content

Commit e5b9847

Browse files
author
Michael Lauer
committed
php example, some doc
1 parent bf25e31 commit e5b9847

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
gofcgisrv
2+
=========
3+
4+
Go package for the webserver end of the
5+
[CGI](http://tools.ietf.org/html/rfc3875),
6+
[FastCGI](http://www.fastcgi.com/drupal/node/6?q=node/22),
7+
and [SCGI](http://python.ca/scgi/protocol.txt) protocols.
8+
9+
The terms "server" and "client" are confusing. "Server" here generally means "webserver," as referred to in
10+
(for example) the FastCGI spec. In terms of who is dialing whom, the webserver is the FastCGI or SCGI client.
11+
Sorry.
12+
13+
See godoc for usage.
14+
15+
No one really seems to support FastCGI properly and completely.
16+
17+
Bugs and todos
18+
--------------
19+
20+
There is nothing here to launch processes. Only TCP connections are supported, not STDIN.
21+
22+
Not all CGI headers are correctly set.

gofcgisrv.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/*
2-
Package gofcgisrv implements the webserver side of the FastCGI protocol.
2+
Package gofcgisrv implements the webserver side of the CGI, FastCGI, and SCGI protocols.
3+
4+
CGI: http://tools.ietf.org/html/rfc3875
5+
FastCGI: http://www.fastcgi.com/drupal/node/6?q=node/22
6+
SCGI: http://python.ca/scgi/protocol.txt protocols.
37
*/
48
package gofcgisrv
59

php_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package gofcgisrv
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"net/http"
7+
"net/http/httptest"
8+
"path"
9+
"strings"
10+
)
11+
12+
func phpCgiHandler(w http.ResponseWriter, r *http.Request) {
13+
filepath := path.Join("./testdata/", r.URL.Path)
14+
env := []string{
15+
"REDIRECT_STATUS=200",
16+
"SCRIPT_FILENAME=" + filepath,
17+
}
18+
19+
ServeHTTP(NewCGI("php-cgi"), env, w, r)
20+
}
21+
22+
func Example_php() {
23+
server := httptest.NewServer(http.HandlerFunc(phpCgiHandler))
24+
defer server.Close()
25+
url := server.URL
26+
27+
text := "This is a test!"
28+
resp, err := http.Post(url+"/echo.php", "text/plain", strings.NewReader(text))
29+
if err == nil {
30+
fmt.Printf("Status: %v\n", resp.StatusCode)
31+
body, _ := ioutil.ReadAll(resp.Body)
32+
resp.Body.Close()
33+
fmt.Printf("Response: %s\n", body)
34+
}
35+
36+
// Output:
37+
// Status: 200
38+
// Response: This is a test!
39+
}

testdata/echo.php

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
$body = file_get_contents('php://input');
3+
echo $body;
4+
?>

0 commit comments

Comments
 (0)