From 5cc3d2d45551a027af38246ca6635202c938cbf3 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 4 Apr 2020 12:03:29 +0200 Subject: [PATCH] use http.Request instead of pointer --- internal/reqdata/set.go | 12 ++++++------ internal/reqdata/set_test.go | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/reqdata/set.go b/internal/reqdata/set.go index 4baca97..3930927 100644 --- a/internal/reqdata/set.go +++ b/internal/reqdata/set.go @@ -39,7 +39,7 @@ func New(service *config.Service) *Set { } // ExtractURI fills 'Set' with creating pointers inside 'Url' -func (i *Set) ExtractURI(req *http.Request) error { +func (i *Set) ExtractURI(req http.Request) error { uriparts := config.SplitURL(req.URL.RequestURI()) for _, capture := range i.service.Captures { @@ -71,7 +71,7 @@ func (i *Set) ExtractURI(req *http.Request) error { } // ExtractQuery data from the url query parameters -func (i *Set) ExtractQuery(req *http.Request) error { +func (i *Set) ExtractQuery(req http.Request) error { query := req.URL.Query() for name, param := range i.service.Query { @@ -108,7 +108,7 @@ func (i *Set) ExtractQuery(req *http.Request) error { // - parse 'form-data' if not supported for non-POST requests // - parse 'x-www-form-urlencoded' // - parse 'application/json' -func (i *Set) ExtractForm(req *http.Request) error { +func (i *Set) ExtractForm(req http.Request) error { // ignore GET method if req.Method == http.MethodGet { @@ -138,7 +138,7 @@ func (i *Set) ExtractForm(req *http.Request) error { // parseJSON parses JSON from the request body inside 'Form' // and 'Set' -func (i *Set) parseJSON(req *http.Request) error { +func (i *Set) parseJSON(req http.Request) error { parsed := make(map[string]interface{}, 0) @@ -178,7 +178,7 @@ func (i *Set) parseJSON(req *http.Request) error { // parseUrlencoded parses urlencoded from the request body inside 'Form' // and 'Set' -func (i *Set) parseUrlencoded(req *http.Request) error { +func (i *Set) parseUrlencoded(req http.Request) error { // use http.Request interface if err := req.ParseForm(); err != nil { return err @@ -215,7 +215,7 @@ func (i *Set) parseUrlencoded(req *http.Request) error { // parseMultipart parses multi-part from the request body inside 'Form' // and 'Set' -func (i *Set) parseMultipart(req *http.Request) error { +func (i *Set) parseMultipart(req http.Request) error { // 1. create reader boundary := req.Header.Get("Content-Type")[len("multipart/form-data; boundary="):] diff --git a/internal/reqdata/set_test.go b/internal/reqdata/set_test.go index efcb459..7496327 100644 --- a/internal/reqdata/set_test.go +++ b/internal/reqdata/set_test.go @@ -131,7 +131,7 @@ func TestStoreWithUri(t *testing.T) { store := New(service) req := httptest.NewRequest(http.MethodGet, "http://host.com"+test.URI, nil) - err := store.ExtractURI(req) + err := store.ExtractURI(*req) if err != nil { if test.Err != nil { if !errors.Is(err, test.Err) { @@ -242,7 +242,7 @@ func TestExtractQuery(t *testing.T) { store := New(getServiceWithQuery(test.ServiceParam...)) req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://host.com?%s", test.Query), nil) - err := store.ExtractQuery(req) + err := store.ExtractQuery(*req) if err != nil { if test.Err != nil { if !errors.Is(err, test.Err) { @@ -324,7 +324,7 @@ func TestStoreWithUrlEncodedFormParseError(t *testing.T) { // defer req.Body.Close() store := New(nil) - err := store.ExtractForm(req) + err := store.ExtractForm(*req) if err == nil { t.Errorf("expected malformed urlencoded to have FailNow being parsed (got %d elements)", len(store.Data)) t.FailNow() @@ -420,7 +420,7 @@ func TestExtractFormUrlEncoded(t *testing.T) { defer req.Body.Close() store := New(getServiceWithForm(test.ServiceParams...)) - err := store.ExtractForm(req) + err := store.ExtractForm(*req) if err != nil { if test.Err != nil { if !errors.Is(err, test.Err) { @@ -563,7 +563,7 @@ func TestJsonParameters(t *testing.T) { defer req.Body.Close() store := New(getServiceWithForm(test.ServiceParams...)) - err := store.ExtractForm(req) + err := store.ExtractForm(*req) if err != nil { if test.Err != nil { if !errors.Is(err, test.Err) { @@ -720,7 +720,7 @@ x defer req.Body.Close() store := New(getServiceWithForm(test.ServiceParams...)) - err := store.ExtractForm(req) + err := store.ExtractForm(*req) if err != nil { if test.Err != nil { if !errors.Is(err, test.Err) {