Skip to content

Commit

Permalink
readme: add filter example
Browse files Browse the repository at this point in the history
* add filter example.
* add TODO in filter code to remind future development needs.
  • Loading branch information
yookoala committed Jul 19, 2018
1 parent a26f053 commit dc83a6c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,54 @@ func main() {
[fastcgi-authorizer]: http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html#S6.3


#### FastCGI Filter

FastCGI specified a [filter role][fastcgi-filter] for filtering web server
assets before sending out. As different from a usual FastCGI application
(i.e. **responder**), the requested data is on the web server side. So the
web server will pass those data to the application when requested.

<details>
<summary>Code</summary>
<div>

```go

package main

import (
"net/http"
"time"

"github.com/yookoala/gofast"
)

func main() {
address := os.Getenv("FASTCGI_ADDR")
connFactory := gofast.SimpleConnFactory("tcp", address)
clientFactory := gofast.SimpleClientFactory(connFactory, 0)

// Note: The local file system "/var/www/html/" only need to be
// local to web server. No need for the FastCGI application to access
// it directly.
connFactory := gofast.SimpleConnFactory(network, address)
http.Handle("/", gofast.NewHandler(
gofast.NewFilterLocalFS("/var/www/html/")(gofast.BasicSession),
clientFactory,
))

// serve at 8080 port
log.Fatal(http.ListenAndServe(":8080", nil))
}

```

</div>
</details>

[fastcgi-filter]: http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html#S6.4


#### Pooling Clients

To have a better, more controlled, scaling property, you may
Expand Down
2 changes: 2 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ func MapEndpoint(endpointFile string) Middleware {
//
// If the file do not exists or cannot be opened, the middleware
// will return empty response pipe and the error.
//
// TODO: provide way to inject authorization check
func MapFilterRequest(fs http.FileSystem) Middleware {
return func(inner SessionHandler) SessionHandler {
return func(client Client, req *Request) (*ResponsePipe, error) {
Expand Down

0 comments on commit dc83a6c

Please sign in to comment.