diff options
author | Frédéric Guillot <fred@miniflux.net> | 2019-12-26 15:26:23 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2019-12-26 15:56:59 -0800 |
commit | 3debf75eb9229144a05701e03ba59408a75dd815 (patch) | |
tree | 9e9eb6569db3234b514f798d4278b20793b79833 /http/client/response.go | |
parent | 200b1c304b999191a29f36d4122e7aa05481125c (diff) |
Normalize URL query string before executing HTTP requests
- Make sure query strings parameters are encoded
- As opposed to the standard library, do not append equal sign
for query parameters with empty value
- Strip URL fragments like Web browsers
Diffstat (limited to 'http/client/response.go')
-rw-r--r-- | http/client/response.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/http/client/response.go b/http/client/response.go index e62b5ab..122c40c 100644 --- a/http/client/response.go +++ b/http/client/response.go @@ -6,6 +6,7 @@ package client // import "miniflux.app/http/client" import ( "bytes" + "fmt" "io" "io/ioutil" "regexp" @@ -24,10 +25,24 @@ type Response struct { EffectiveURL string LastModified string ETag string + Expires string ContentType string ContentLength int64 } +func (r *Response) String() string { + return fmt.Sprintf( + `StatusCode=%d EffectiveURL=%q LastModified=%q ETag=%s Expires=%s ContentType=%q ContentLength=%d`, + r.StatusCode, + r.EffectiveURL, + r.LastModified, + r.ETag, + r.Expires, + r.ContentType, + r.ContentLength, + ) +} + // IsNotFound returns true if the resource doesn't exists anymore. func (r *Response) IsNotFound() bool { return r.StatusCode == 404 || r.StatusCode == 410 @@ -105,8 +120,8 @@ func (r *Response) EnsureUnicodeBody() (err error) { return err } -// String returns the response body as string. -func (r *Response) String() string { +// BodyAsString returns the response body as string. +func (r *Response) BodyAsString() string { bytes, _ := ioutil.ReadAll(r.Body) return string(bytes) } |