diff options
Diffstat (limited to 'parsers')
-rw-r--r-- | parsers/http_request_parser.go | 28 | ||||
-rw-r--r-- | parsers/http_response_parser.go | 12 | ||||
-rw-r--r-- | parsers/parser.go | 4 |
3 files changed, 22 insertions, 22 deletions
diff --git a/parsers/http_request_parser.go b/parsers/http_request_parser.go index 56093c9..d7ed81c 100644 --- a/parsers/http_request_parser.go +++ b/parsers/http_request_parser.go @@ -28,7 +28,7 @@ import ( "strings" ) -type HttpRequestMetadata struct { +type HTTPRequestMetadata struct { BasicMetadata Method string `json:"method"` URL string `json:"url"` @@ -40,19 +40,19 @@ type HttpRequestMetadata struct { FormData map[string]string `json:"form_data" binding:"omitempty"` Body string `json:"body" binding:"omitempty"` Trailer map[string]string `json:"trailer" binding:"omitempty"` - Reproducers HttpRequestMetadataReproducers `json:"reproducers"` + Reproducers HTTPRequestMetadataReproducers `json:"reproducers"` } -type HttpRequestMetadataReproducers struct { +type HTTPRequestMetadataReproducers struct { CurlCommand string `json:"curl_command"` RequestsCode string `json:"requests_code"` FetchRequest string `json:"fetch_request"` } -type HttpRequestParser struct { +type HTTPRequestParser struct { } -func (p HttpRequestParser) TryParse(content []byte) Metadata { +func (p HTTPRequestParser) TryParse(content []byte) Metadata { reader := bufio.NewReader(bytes.NewReader(content)) request, err := http.ReadRequest(reader) if err != nil { @@ -68,7 +68,7 @@ func (p HttpRequestParser) TryParse(content []byte) Metadata { _ = request.Body.Close() _ = request.ParseForm() - return HttpRequestMetadata{ + return HTTPRequestMetadata{ BasicMetadata: BasicMetadata{"http-request"}, Method: request.Method, URL: request.URL.String(), @@ -80,7 +80,7 @@ func (p HttpRequestParser) TryParse(content []byte) Metadata { FormData: JoinArrayMap(request.Form), Body: body, Trailer: JoinArrayMap(request.Trailer), - Reproducers: HttpRequestMetadataReproducers{ + Reproducers: HTTPRequestMetadataReproducers{ CurlCommand: curlCommand(content), RequestsCode: requestsCode(request, body), FetchRequest: fetchRequest(request, body), @@ -92,17 +92,17 @@ func curlCommand(content []byte) string { // a new reader is required because all the body is read before and GetBody() doesn't works reader := bufio.NewReader(bytes.NewReader(content)) request, _ := http.ReadRequest(reader) - if command, err := http2curl.GetCurlCommand(request); err == nil { + command, err := http2curl.GetCurlCommand(request) + if err == nil { return command.String() - } else { - return err.Error() } + return err.Error() } func requestsCode(request *http.Request, body string) string { var b strings.Builder - headers := toJson(JoinArrayMap(request.Header)) - cookies := toJson(CookiesMap(request.Cookies())) + headers := toJSON(JoinArrayMap(request.Header)) + cookies := toJSON(CookiesMap(request.Cookies())) b.WriteString("import requests\n\nresponse = requests." + strings.ToLower(request.Method) + "(") b.WriteString("\"" + request.URL.String() + "\"") @@ -146,14 +146,14 @@ func fetchRequest(request *http.Request, body string) string { data["method"] = request.Method // TODO: mode - if jsonData := toJson(data); jsonData != "" { + if jsonData := toJSON(data); jsonData != "" { return "fetch(\"" + request.URL.String() + "\", " + jsonData + ");" } else { return "invalid-request" } } -func toJson(obj interface{}) string { +func toJSON(obj interface{}) string { if buffer, err := json.MarshalIndent(obj, "", "\t"); err == nil { return string(buffer) } else { diff --git a/parsers/http_response_parser.go b/parsers/http_response_parser.go index e5ef1ac..e61fffd 100644 --- a/parsers/http_response_parser.go +++ b/parsers/http_response_parser.go @@ -26,7 +26,7 @@ import ( "net/http" ) -type HttpResponseMetadata struct { +type HTTPResponseMetadata struct { BasicMetadata Status string `json:"status"` StatusCode int `json:"status_code"` @@ -40,10 +40,10 @@ type HttpResponseMetadata struct { Trailer map[string]string `json:"trailer" binding:"omitempty"` } -type HttpResponseParser struct { +type HTTPResponseParser struct { } -func (p HttpResponseParser) TryParse(content []byte) Metadata { +func (p HTTPResponseParser) TryParse(content []byte) Metadata { reader := bufio.NewReader(bytes.NewReader(content)) response, err := http.ReadResponse(reader, nil) if err != nil { @@ -74,11 +74,11 @@ func (p HttpResponseParser) TryParse(content []byte) Metadata { _ = response.Body.Close() var location string - if locationUrl, err := response.Location(); err == nil { - location = locationUrl.String() + if locationURL, err := response.Location(); err == nil { + location = locationURL.String() } - return HttpResponseMetadata{ + return HTTPResponseMetadata{ BasicMetadata: BasicMetadata{"http-response"}, Status: response.Status, StatusCode: response.StatusCode, diff --git a/parsers/parser.go b/parsers/parser.go index a29b1ab..9aca3b6 100644 --- a/parsers/parser.go +++ b/parsers/parser.go @@ -30,8 +30,8 @@ type BasicMetadata struct { } var parsers = []Parser{ // order matter - HttpRequestParser{}, - HttpResponseParser{}, + HTTPRequestParser{}, + HTTPResponseParser{}, } func Parse(content []byte) Metadata { |