Skip to content

Commit

Permalink
[BREAKING] NewRequest signature change
Browse files Browse the repository at this point in the history
* remove the id field from NewRequest follow the field Request.ID
  retirement.
  • Loading branch information
yookoala committed Feb 8, 2018
1 parent c9163df commit ba615b2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// NewAuthRequest returns a new *http.Request
// and a *Request with the body buffered
// into new NopReader.
func NewAuthRequest(id uint16, orgl *http.Request) (r *http.Request, req *Request, err error) {
func NewAuthRequest(orgl *http.Request) (r *http.Request, req *Request, err error) {

// new request struct that inherits orgl values
r = &http.Request{}
Expand Down
2 changes: 1 addition & 1 deletion authorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestNewAuthRequest(t *testing.T) {
return
}
// clone the request into 2
r, req, err := gofast.NewAuthRequest(0, raw)
r, req, err := gofast.NewAuthRequest(raw)
if err != nil {
t.Errorf("unexpected error: %s", err)
return
Expand Down
18 changes: 3 additions & 15 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (

// NewRequest returns a standard FastCGI request
// with a unique request ID allocted by the client
func NewRequest(id uint16, r *http.Request) (req *Request) {
func NewRequest(r *http.Request) (req *Request) {
req = &Request{
Raw: r,
Role: RoleResponder,
Expand Down Expand Up @@ -76,7 +76,7 @@ func (p *idPool) Alloc() uint16 {
func (p *idPool) Release(id uint16) {
go func() {
// release the ID back to channel for reuse
// use goroutine to prevent blocking ReleaseID
// use goroutine to prev0, ent blocking ReleaseID
p.IDs <- id
}()
}
Expand Down Expand Up @@ -114,17 +114,6 @@ type client struct {
ids idPool
}

// AllocID implements Client.AllocID
func (c *client) AllocID() (reqID uint16) {
reqID = c.ids.Alloc()
return
}

// ReleaseID implements Client.ReleaseID
func (c *client) ReleaseID(reqID uint16) {
c.ids.Release(reqID)
}

// writeRequest writes params and stdin to the FastCGI application
func (c *client) writeRequest(reqID uint16, req *Request) (err error) {

Expand Down Expand Up @@ -197,7 +186,6 @@ func (c *client) writeRequest(reqID uint16, req *Request) (err error) {

_, err = dataWriter.Write(p[:count])
if err != nil {
c.AllocID()
return
}
}
Expand Down Expand Up @@ -255,7 +243,6 @@ func (c *client) Do(req *Request) (resp *ResponsePipe, err error) {
// validate the request
// if role is a filter, it has to have Data stream
if req.Role == RoleFilter {
c.AllocID()
// validate the request
if req.Data == nil {
err = fmt.Errorf("filter request requries a data stream")
Expand All @@ -275,6 +262,7 @@ func (c *client) Do(req *Request) (resp *ResponsePipe, err error) {
}
}

// allocate request ID
reqID := c.ids.Alloc()

// create response pipe
Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestClient_canceled(t *testing.T) {
}
}

req = gofast.NewRequest(0, r)
req = gofast.NewRequest(r)
req.Params["CONTENT_TYPE"] = r.Header.Get("Content-Type")
req.Params["CONTENT_LENGTH"] = r.Header.Get("Content-Length")
req.Params["HTTPS"] = isHTTPS
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestClient_StdErr(t *testing.T) {
p.network, p.address, err.Error())
return
}
req := gofast.NewRequest(0, nil)
req := gofast.NewRequest(nil)

// Some required paramters with invalid values
req.Params["REQUEST_METHOD"] = ""
Expand Down
2 changes: 1 addition & 1 deletion host.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (h *defaultHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// handle the session
resp, err := h.sessionHandler(c, NewRequest(0, r))
resp, err := h.sessionHandler(c, NewRequest(r))
if err != nil {
http.Error(w, "failed to process request", http.StatusInternalServerError)
log.Printf("gofast: unable to process request %s",
Expand Down
2 changes: 1 addition & 1 deletion session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestMapFilterRequest(t *testing.T) {
return
}
c := NopClient(1)
_, err = sess(c, gofast.NewRequest(0, r))
_, err = sess(c, gofast.NewRequest(r))
if err != nil {
t.Errorf("unexpected error: %s", err)
return
Expand Down

0 comments on commit ba615b2

Please sign in to comment.