Send headers to FastCGI server

This commit is contained in:
Trevor Slocum 2020-11-04 13:07:06 -08:00
parent 5e9515ff09
commit 8e2e404a81
2 changed files with 13 additions and 11 deletions

View file

@ -10,7 +10,6 @@ import (
"regexp"
"strconv"
"strings"
"time"
"github.com/kballard/go-shellquote"
"github.com/yookoala/gofast"
@ -60,7 +59,7 @@ type serverConfig struct {
hostname string
port int
fcgiPools map[string]*gofast.ClientPool
fcgiPools map[string]gofast.ConnFactory
}
var config *serverConfig
@ -102,7 +101,7 @@ func readconfig(configPath string) error {
}
}
config.fcgiPools = make(map[string]*gofast.ClientPool)
config.fcgiPools = make(map[string]gofast.ConnFactory)
for hostname, host := range config.Hosts {
if host.Cert == "" || host.Key == "" {
log.Fatal("a certificate must be specified for each domain (gemini requires TLS for all connections)")
@ -140,9 +139,7 @@ func readconfig(configPath string) error {
log.Fatalf("failed to parse fastcgi resource %s: %s", serve.FastCGI, err)
}
connFactory := gofast.SimpleConnFactory(f.Scheme, f.Host+f.Path)
clientFactory := gofast.SimpleClientFactory(connFactory, 0)
config.fcgiPools[serve.FastCGI] = gofast.NewClientPool(clientFactory, 1, 1*time.Minute)
config.fcgiPools[serve.FastCGI] = gofast.SimpleConnFactory(f.Scheme, f.Host+f.Path)
}
} else if serve.Command != "" {
serve.cmd, err = shellquote.Split(serve.Command)

View file

@ -32,22 +32,27 @@ func (w *responseWriter) WriteHeader(statusCode int) {
// Do nothing
}
func serveFastCGI(c net.Conn, clientPool *gofast.ClientPool, reqURL *url.URL, filePath string) {
func serveFastCGI(c net.Conn, connFactory gofast.ConnFactory, u *url.URL, filePath string) {
header := map[string][]string{
"Accept": {"*/*"},
"Host": {u.Hostname()},
}
r := &http.Request{
Method: "GET",
URL: reqURL,
URL: u,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: make(http.Header),
Header: header,
Body: ioutil.NopCloser(bytes.NewReader(nil)),
Host: reqURL.Host,
Host: u.Host,
}
gofast.
NewHandler(
gofast.NewFileEndpoint(filePath)(gofast.BasicSession),
clientPool.CreateClient,
gofast.SimpleClientFactory(connFactory, 0),
).
ServeHTTP(newResponseWriter(c), r)