diff options
Diffstat (limited to 'parsers/http_response_parser.go')
-rw-r--r-- | parsers/http_response_parser.go | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/parsers/http_response_parser.go b/parsers/http_response_parser.go index 1770116..e61fffd 100644 --- a/parsers/http_response_parser.go +++ b/parsers/http_response_parser.go @@ -1,3 +1,20 @@ +/* + * This file is part of caronte (https://github.com/eciavatta/caronte). + * Copyright (c) 2020 Emiliano Ciavatta. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package parsers import ( @@ -9,7 +26,7 @@ import ( "net/http" ) -type HttpResponseMetadata struct { +type HTTPResponseMetadata struct { BasicMetadata Status string `json:"status"` StatusCode int `json:"status_code"` @@ -23,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 { @@ -57,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, |