Progress
This commit is contained in:
parent
ac022435a4
commit
b5745c941b
@ -31,15 +31,9 @@ func (client *FCGIClient) writeRecord(recType FCGIRequestType, content []byte) (
|
||||
client.mutex.Lock()
|
||||
defer client.mutex.Unlock()
|
||||
client.buf.Reset()
|
||||
// Initialize the record
|
||||
header := Header{}
|
||||
header.init(recType, 1, len(content))
|
||||
rec := Record{
|
||||
Header: header,
|
||||
Content: content,
|
||||
}
|
||||
|
||||
// Write the record to the connection
|
||||
rec := NewRecord(recType, content)
|
||||
b, err := rec.toBytes()
|
||||
_, err = client.rwc.Write(b)
|
||||
return err
|
||||
|
@ -22,11 +22,6 @@ type Header struct {
|
||||
}
|
||||
|
||||
func (h *Header) init(reqType FCGIRequestType, reqId uint16, l int) {
|
||||
h.Version = 1
|
||||
h.Type = reqType
|
||||
h.Id = reqId
|
||||
h.ContentLength = uint16(l)
|
||||
h.PaddingLength = uint8(-l & 7)
|
||||
}
|
||||
|
||||
// A record is essentially a "packet" in FastCGI.
|
||||
@ -47,6 +42,38 @@ type Record struct {
|
||||
ReadBuffer []byte // Buffer to use when reading a response
|
||||
}
|
||||
|
||||
func NewRecord(t FCGIRequestType, content []byte) *Record {
|
||||
r := Record{}
|
||||
|
||||
r.Header.Version = 1
|
||||
r.Header.Type = t
|
||||
r.Header.Id = 1
|
||||
r.Header.ContentLength = uint16(len(content))
|
||||
r.Header.PaddingLength = uint8(-len(content) & 7)
|
||||
r.Content = content
|
||||
|
||||
return &r
|
||||
}
|
||||
|
||||
func NewBeginRequestRecord() *Record {
|
||||
role := uint16(FCGI_RESPONDER)
|
||||
flags := byte(0)
|
||||
// Create an 8-byte array as per the FastCGI specification.
|
||||
var b [8]byte
|
||||
|
||||
// Split the 16-bit role into two bytes and assign them.
|
||||
b[0] = byte(role >> 8) // High byte
|
||||
b[1] = byte(role) // Low byte
|
||||
|
||||
// Set the flags.
|
||||
b[2] = flags
|
||||
|
||||
// The reserved bytes (b[3] to b[7]) will remain zero by default.
|
||||
|
||||
// Return a begin request record
|
||||
return NewRecord(FCGI_BEGIN_REQUEST, b[:])
|
||||
}
|
||||
|
||||
// Turn a record into a byte array so it can be
|
||||
// sent over the network socket
|
||||
func (r *Record) toBytes() ([]byte, error) {
|
||||
@ -109,30 +136,6 @@ func RequestFromHttp(r *http.Request) *FCGIRequest {
|
||||
return &c
|
||||
}
|
||||
|
||||
func NewBeginRequestRecord() *Record {
|
||||
role := uint16(FCGI_RESPONDER)
|
||||
flags := byte(0)
|
||||
// Create an 8-byte array as per the FastCGI specification.
|
||||
var b [8]byte
|
||||
|
||||
// Split the 16-bit role into two bytes and assign them.
|
||||
b[0] = byte(role >> 8) // High byte
|
||||
b[1] = byte(role) // Low byte
|
||||
|
||||
// Set the flags.
|
||||
b[2] = flags
|
||||
|
||||
// The reserved bytes (b[3] to b[7]) will remain zero by default.
|
||||
|
||||
// Return a begin request record
|
||||
h := Header{}
|
||||
h.init(FCGI_BEGIN_REQUEST, 1, len(b))
|
||||
return &Record{
|
||||
Header: h,
|
||||
Content: b[:],
|
||||
}
|
||||
}
|
||||
|
||||
func (req *FCGIRequest) Script(path string) {
|
||||
req.Context["SCRIPT_FILENAME"] = path
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user