Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/yookoala/gofast
module github.com/MoHuacong/gofast

go 1.7

Expand Down
16 changes: 14 additions & 2 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@ type Handler interface {
SetLogger(logger *log.Logger)
}

type CallBack func (w http.ResponseWriter, r *http.Request) bool

func DefaultCallBack(w http.ResponseWriter, r *http.Request) bool {
return false
}

// NewHandler returns the default Handler implementation. This default Handler
// act as the "web server" component in fastcgi specification, which connects
// fastcgi "application" through the network/address and passthrough I/O as
// specified.
func NewHandler(sessionHandler SessionHandler, clientFactory ClientFactory) Handler {
func NewHandler(sessionHandler SessionHandler, clientFactory ClientFactory, callback CallBack) Handler {
return &defaultHandler{
sessionHandler: sessionHandler,
newClient: clientFactory,
callback: callback,
}
}

// defaultHandler implements Handler
type defaultHandler struct {
sessionHandler SessionHandler
newClient ClientFactory
callback CallBack
logger *log.Logger
}

Expand All @@ -37,7 +45,11 @@ func (h *defaultHandler) SetLogger(logger *log.Logger) {

// ServeHTTP implements http.Handler
func (h *defaultHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

if h.callback != nil {
if h.callback(w, r) {
return
}
}
// TODO: separate dial logic to pool client / connection
c, err := h.newClient()
if err != nil {
Expand Down