Permalink
Browse files

adding support for Expect: 100-continue

  • Loading branch information...
1 parent bdc6eba commit 1ab2c2ac532e476668859cbd96a6e7c63bb9242d Scott White committed Apr 26, 2013
Showing with 40 additions and 0 deletions.
  1. +31 −0 continue.go
  2. +9 −0 request.go
View
@@ -0,0 +1,31 @@
+package falcore
+
+import (
+ "io"
+)
+
+type continueReader struct {
+ req *Request
+ r io.ReadCloser
+ opened bool
+}
+
+var _ io.ReadCloser = new(continueReader)
+
+func (r *continueReader) Read(p []byte) (int, error) {
+ // sent 100 continue the first time we try to read the body
+ if !r.opened {
+ resp := SimpleResponse(r.req.HttpRequest, 100, nil, "")
+ if err := resp.Write(r.req.Connection); err != nil {
+ return 0, err
+ }
+ r.req = nil
+ r.opened = true
+ }
+ return r.r.Read(p)
+}
+
+func (r *continueReader) Close() error {
+ r.req = nil
+ return r.r.Close()
+}
View
@@ -69,6 +69,15 @@ func newRequest(request *http.Request, conn net.Conn, startTime time.Time) *Requ
fReq.ID = fmt.Sprintf("%010x", (ut-(ut-(ut%1e12)))+int64(rand.Intn(999)))
fReq.PipelineStageStats = list.New()
fReq.pipelineHash = crc32.NewIEEE()
+
+ // Support for 100-continue requests
+ // http.Server (and presumably google app engine) already handle this
+ // case. So we don't need to do anything if we don't own the
+ // connection.
+ if conn != nil && request.Header.Get("Expect") == "100-continue" {
+ request.Body = &continueReader{req: fReq, r: request.Body}
+ }
+
return fReq
}

0 comments on commit 1ab2c2a

Please sign in to comment.