yookoala / gofast

gofast is a FastCGI "client" library written purely in go
BSD 3-Clause "New" or "Revised" License
220 stars 47 forks source link

Lack a way to do simple request #38

Open yookoala opened 5 years ago

yookoala commented 5 years ago

The current library presume library-users are working on a proxy to application server (as described in the FastCGI specification). But some library (e.g. https://github.com/tomasen/fcgi_client) works as a simple request-response interface for the application server.

gofast should also support this.

Conceptually, it should probably look like this


...

address := os.Getenv("FASTCGI_ADDR")

// A client to directly connect FCGI backend
f := gofast.SimpleClientFactory(gofast.SimpleConnFactory("tcp", address), 0)
client := gofast.NewDirectClient(f, ...)

// Request specifying "SCRIPT_FILENAME" and
// a small subset of usual header by default
// (user can supply more parameters)
req := gofast.NewDirectRequest(...)

// make the direct request
var resp http.Response := client.Do(req)

...
...

Connections are closed by the end of every session. Should be pretty straightforward to use.

thirdwheel commented 4 years ago

Yes, this would be greatly appreciated. I've tried to roll my own without success - I just get a 500 error.

func directFS(root string) gofast.Middleware {
    fs := &gofast.FileSystemRouter{
        DocRoot: root,
        //Exts:     []string{""},
        DirIndex: []string{"index.html", "index.htm"},
    }
    return gofast.Chain(
        gofast.BasicParamsMap,
        gofast.MapHeader,
        fs.Router(),
    )
}

Since my FastCGI endpoint is a unix domain socket, I have limited testing capability. Any thoughts?

thirdwheel commented 4 years ago

By way of sanity check, I tested against php's fastcgi mode and no matter what filename I give it, I get 'No input file specified.'