Fix POST requests

This commit is contained in:
Leonid Bugaev
2015-01-06 17:50:36 +05:00
parent ffe1646d8e
commit ed5c2215f5
2 changed files with 22 additions and 1 deletions
+8
View File
@@ -10,6 +10,7 @@ import (
"strings"
"sync/atomic"
"time"
"io/ioutil"
)
type RedirectNotAllowed struct{}
@@ -33,6 +34,13 @@ func ParseRequest(data []byte) (request *http.Request, err error) {
request, err = http.ReadRequest(reader)
if request.Method == "POST" {
body, _ := ioutil.ReadAll(reader)
bodyBuf := bytes.NewBuffer(body)
request.Body = ioutil.NopCloser(bodyBuf)
request.ContentLength = int64(bodyBuf.Len())
}
return
}
+14 -1
View File
@@ -7,11 +7,14 @@ import (
"sync"
"testing"
"time"
"io/ioutil"
"net/http/httputil"
_ "strings"
)
func startHTTP(cb func(*http.Request)) net.Listener {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
go cb(r)
cb(r)
})
listener, _ := net.Listen("tcp", ":0")
@@ -60,6 +63,16 @@ func TestHTTPOutput(t *testing.T) {
t.Error("Wrong method")
}
if req.Method == "POST" {
defer req.Body.Close()
body, _ := ioutil.ReadAll(req.Body)
if string(body) != "a=1&b=2\r\n\r\n" {
buf, _ := httputil.DumpRequest(req, true)
t.Error("Wrong POST body:", string(buf))
}
}
wg.Done()
})