mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Fix POST requests
This commit is contained in:
@@ -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
@@ -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()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user