diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/http/handler_test.go | 10 | ||||
-rw-r--r-- | service/http/parse.go | 8 | ||||
-rw-r--r-- | service/http/request.go | 8 |
3 files changed, 15 insertions, 11 deletions
diff --git a/service/http/handler_test.go b/service/http/handler_test.go index c7b38ee2..560b9c1b 100644 --- a/service/http/handler_test.go +++ b/service/http/handler_test.go @@ -12,6 +12,7 @@ import ( "context" "bytes" "mime/multipart" + "time" ) // get request and return body @@ -281,6 +282,7 @@ func TestServer_JsonPayload_PATCH(t *testing.T) { defer hs.Shutdown(context.Background()) go func() { hs.ListenAndServe() }() + time.Sleep(time.Millisecond * 10) req, err := http.NewRequest( "PATCH", @@ -330,6 +332,7 @@ func TestServer_FormData_POST(t *testing.T) { defer hs.Shutdown(context.Background()) go func() { hs.ListenAndServe() }() + time.Sleep(time.Millisecond * 10) form := url.Values{} @@ -391,6 +394,7 @@ func TestServer_FormData_PUT(t *testing.T) { defer hs.Shutdown(context.Background()) go func() { hs.ListenAndServe() }() + time.Sleep(time.Millisecond * 10) form := url.Values{} @@ -452,6 +456,7 @@ func TestServer_FormData_PATCH(t *testing.T) { defer hs.Shutdown(context.Background()) go func() { hs.ListenAndServe() }() + time.Sleep(time.Millisecond * 10) form := url.Values{} @@ -513,6 +518,7 @@ func TestServer_Multipart_POST(t *testing.T) { defer hs.Shutdown(context.Background()) go func() { hs.ListenAndServe() }() + time.Sleep(time.Millisecond * 10) var mb bytes.Buffer w := multipart.NewWriter(&mb) @@ -578,6 +584,7 @@ func TestServer_Multipart_PUT(t *testing.T) { defer hs.Shutdown(context.Background()) go func() { hs.ListenAndServe() }() + time.Sleep(time.Millisecond * 10) var mb bytes.Buffer w := multipart.NewWriter(&mb) @@ -639,10 +646,11 @@ func TestServer_Multipart_PATCH(t *testing.T) { assert.NoError(t, st.rr.Start()) defer st.rr.Stop() - hs := &http.Server{Addr: ":8020", Handler: st,} + hs := &http.Server{Addr: ":8021", Handler: st,} defer hs.Shutdown(context.Background()) go func() { hs.ListenAndServe() }() + time.Sleep(time.Millisecond * 10) var mb bytes.Buffer w := multipart.NewWriter(&mb) diff --git a/service/http/parse.go b/service/http/parse.go index 0224af41..a7516ca6 100644 --- a/service/http/parse.go +++ b/service/http/parse.go @@ -12,7 +12,7 @@ type dataTree map[string]interface{} type fileTree map[string]interface{} // parseData parses incoming request body into data tree. -func parseData(r *http.Request) (dataTree, error) { +func parseData(r *http.Request) dataTree { data := make(dataTree) if r.PostForm != nil { for k, v := range r.PostForm { @@ -26,7 +26,7 @@ func parseData(r *http.Request) (dataTree, error) { } } - return data, nil + return data } // pushes value into data tree. @@ -61,7 +61,7 @@ func (d dataTree) mount(i []string, v []string) { } // parse incoming dataTree request into JSON (including contentMultipart form dataTree) -func parseUploads(r *http.Request, cfg *UploadsConfig) (*Uploads, error) { +func parseUploads(r *http.Request, cfg *UploadsConfig) *Uploads { u := &Uploads{ cfg: cfg, tree: make(fileTree), @@ -78,7 +78,7 @@ func parseUploads(r *http.Request, cfg *UploadsConfig) (*Uploads, error) { u.tree.push(k, files) } - return u, nil + return u } // exists if file exists. diff --git a/service/http/request.go b/service/http/request.go index f3f89969..80998b11 100644 --- a/service/http/request.go +++ b/service/http/request.go @@ -75,18 +75,14 @@ func NewRequest(r *http.Request, cfg *UploadsConfig) (req *Request, err error) { return nil, err } - if req.Uploads, err = parseUploads(r, cfg); err != nil { - return nil, err - } + req.Uploads = parseUploads(r, cfg) fallthrough case contentFormData: if err = r.ParseForm(); err != nil { return nil, err } - if req.body, err = parseData(r); err != nil { - return nil, err - } + req.body = parseData(r) } req.Parsed = true |