summaryrefslogtreecommitdiff
path: root/plugins/http/request.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-16 14:21:35 +0300
committerValery Piashchynski <[email protected]>2020-11-16 14:21:35 +0300
commit57ad958acab2d108be0a35547faf6e7a791cf069 (patch)
tree3c519708540265a7e74b03d1fe17ef4101ffcfdf /plugins/http/request.go
parentd890eee1742dc3a0a1c787f7e65d40b1e81a94db (diff)
Update Pool
Diffstat (limited to 'plugins/http/request.go')
-rw-r--r--plugins/http/request.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/plugins/http/request.go b/plugins/http/request.go
index b3123eb2..7e9839b2 100644
--- a/plugins/http/request.go
+++ b/plugins/http/request.go
@@ -9,6 +9,7 @@ import (
"strings"
json "github.com/json-iterator/go"
+ "github.com/spiral/roadrunner/v2"
"github.com/spiral/roadrunner/v2/interfaces/log"
)
@@ -66,8 +67,8 @@ func fetchIP(pair string) string {
}
// NewRequest creates new PSR7 compatible request using net/http request.
-func NewRequest(r *http.Request, cfg *UploadsConfig) (req *Request, err error) {
- req = &Request{
+func NewRequest(r *http.Request, cfg *UploadsConfig) (*Request, error) {
+ req := &Request{
RemoteAddr: fetchIP(r.RemoteAddr),
Protocol: r.Proto,
Method: r.Method,
@@ -75,7 +76,7 @@ func NewRequest(r *http.Request, cfg *UploadsConfig) (req *Request, err error) {
Header: r.Header,
Cookies: make(map[string]string),
RawQuery: r.URL.RawQuery,
- Attributes: attributes.All(r),
+ //Attributes: attributes.All(r),
}
for _, c := range r.Cookies() {
@@ -89,18 +90,19 @@ func NewRequest(r *http.Request, cfg *UploadsConfig) (req *Request, err error) {
return req, nil
case contentStream:
+ var err error
req.body, err = ioutil.ReadAll(r.Body)
return req, err
case contentMultipart:
- if err = r.ParseMultipartForm(defaultMaxMemory); err != nil {
+ if err := r.ParseMultipartForm(defaultMaxMemory); err != nil {
return nil, err
}
req.Uploads = parseUploads(r, cfg)
fallthrough
case contentFormData:
- if err = r.ParseForm(); err != nil {
+ if err := r.ParseForm(); err != nil {
return nil, err
}
@@ -121,7 +123,7 @@ func (r *Request) Open(log log.Logger) {
}
// Close clears all temp file uploads
-func (r *Request) Close(log *logrus.Logger) {
+func (r *Request) Close(log log.Logger) {
if r.Uploads == nil {
return
}
@@ -131,17 +133,17 @@ func (r *Request) Close(log *logrus.Logger) {
// Payload request marshaled RoadRunner payload based on PSR7 data. values encode method is JSON. Make sure to open
// files prior to calling this method.
-func (r *Request) Payload() (p *roadrunner.Payload, err error) {
- p = &roadrunner.Payload{}
+func (r *Request) Payload() (roadrunner.Payload, error) {
+ p := roadrunner.Payload{}
- j := json.ConfigCompatibleWithStandardLibrary
- if p.Context, err = j.Marshal(r); err != nil {
- return nil, err
+ var err error
+ if p.Context, err = json.Marshal(r); err != nil {
+ return roadrunner.EmptyPayload, err
}
if r.Parsed {
- if p.Body, err = j.Marshal(r.body); err != nil {
- return nil, err
+ if p.Body, err = json.Marshal(r.body); err != nil {
+ return roadrunner.EmptyPayload, err
}
} else if r.body != nil {
p.Body = r.body.([]byte)