forked from mrlauer/gofcgisrv
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathphp_test.go
39 lines (33 loc) · 794 Bytes
/
php_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package gofcgisrv
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 Example_php() {
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!
}