diff --git a/v2/pkg/protocols/http/build_request.go b/v2/pkg/protocols/http/build_request.go index 11467de6d..7a4f6673d 100644 --- a/v2/pkg/protocols/http/build_request.go +++ b/v2/pkg/protocols/http/build_request.go @@ -114,12 +114,6 @@ func (r *requestGenerator) makeHTTPRequestFromModel(ctx context.Context, data st // makeHTTPRequestFromRaw creates a *http.Request from a raw request func (r *requestGenerator) makeHTTPRequestFromRaw(ctx context.Context, baseURL, data string, values, payloads map[string]interface{}) (*generatedRequest, error) { - // Add "\r\n" only to RCF compliant requests without body - if !r.request.Unsafe && !rawHasBody(data) { - data += "\r\n" - } else { - data = strings.TrimSuffix(data, "\r\n") - } return r.handleRawWithPaylods(ctx, data, baseURL, values, payloads) } @@ -178,6 +172,9 @@ func (r *requestGenerator) handleRawWithPaylods(ctx context.Context, rawRequest, return nil, err } for key, value := range rawRequestData.Headers { + if key == "" { + continue + } req.Header[key] = []string{value} } request, err := r.fillRequest(req, values) diff --git a/v2/pkg/protocols/http/raw/raw.go b/v2/pkg/protocols/http/raw/raw.go index 698e1cb81..ff8b85f8f 100644 --- a/v2/pkg/protocols/http/raw/raw.go +++ b/v2/pkg/protocols/http/raw/raw.go @@ -49,6 +49,7 @@ func Parse(request, baseURL string, unsafe bool) (*Request, error) { // Set the request Method rawRequest.Method = parts[0] + var mutlipartRequest bool // Accepts all malformed headers var key, value string for { @@ -66,6 +67,9 @@ func Parse(request, baseURL string, unsafe bool) (*Request, error) { if len(p) > 1 { value = p[1] } + if strings.Contains(key, "Content-Type") && strings.Contains(value, "multipart/") { + mutlipartRequest = true + } // in case of unsafe requests multiple headers should be accepted // therefore use the full line as key @@ -127,5 +131,8 @@ func Parse(request, baseURL string, unsafe bool) (*Request, error) { return nil, fmt.Errorf("could not read request body: %s", err) } rawRequest.Data = string(b) + if !mutlipartRequest { + rawRequest.Data = strings.TrimSuffix(rawRequest.Data, "\r\n") + } return rawRequest, nil }