-
Notifications
You must be signed in to change notification settings - Fork 0
/
php.go
46 lines (42 loc) · 1.13 KB
/
php.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
40
41
42
43
44
45
46
package handler
import (
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
"github.com/yookoala/gofast"
)
func setupPHP(cgiaddr *url.URL) gofast.ClientFactory {
network := cgiaddr.Scheme
address := cgiaddr.Host
if len(address) == 0 {
address = cgiaddr.Path
}
connFactory := gofast.SimpleConnFactory(network, address)
return gofast.SimpleClientFactory(connFactory)
}
func newPHPHandler(phpClientFactory gofast.ClientFactory, hostname, hostPath, endpoint string) (http.Handler, error) {
if phpClientFactory == nil {
return nil, fmt.Errorf("PHP not configured")
}
fi, err := os.Stat(endpoint)
if err != nil {
return nil, err
}
endpoint, err = filepath.Abs(endpoint)
if err != nil {
return nil, err
}
var targetPath string
var sessHandler gofast.SessionHandler
if fi.IsDir() {
sessHandler = gofast.NewPHPFS(endpoint)(gofast.BasicSession)
targetPath = endpoint
} else {
sessHandler = gofast.NewFileEndpoint(endpoint)(gofast.BasicSession)
targetPath = filepath.Dir(endpoint)
}
handler := gofast.NewHandler(sessHandler, phpClientFactory)
return handlePathCombinations(handler, hostname, hostPath, targetPath), nil
}