From 3debf75eb9229144a05701e03ba59408a75dd815 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 26 Dec 2019 15:26:23 -0800 Subject: 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 --- http/client/response.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'http/client/response.go') 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) } -- cgit v1.2.3