aboutsummaryrefslogtreecommitdiff
path: root/lib/http/http.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-04-14 20:13:48 +0700
committerShulhan <m.shulhan@gmail.com>2020-04-22 14:52:04 +0700
commitca478decceae6da66eb4efe3a8ae63bad1d6a1ec (patch)
tree1857f16a2753482428e0a42fcecce101234c278a /lib/http/http.go
parent263830db01f4c144ee28ea390f9c19ea3f5930e0 (diff)
downloadpakakeh.go-ca478decceae6da66eb4efe3a8ae63bad1d6a1ec.tar.xz
http: automatically uncompress the response body from server
If the content-type of response body from server is text or JSON and Content-Encoding is one of the compression methods (bzip2, compress, deflate, or gzip) then uncompress them before returning it to user.
Diffstat (limited to 'lib/http/http.go')
-rw-r--r--lib/http/http.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/http/http.go b/lib/http/http.go
index f3b11954..d13f3c8b 100644
--- a/lib/http/http.go
+++ b/lib/http/http.go
@@ -142,8 +142,15 @@ import (
// List of known HTTP header keys and values.
const (
- ContentEncoding = "Content-Encoding"
- ContentLength = "Content-Length"
+ AcceptEncoding = "Accept-Encoding"
+ ContentEncoding = "Content-Encoding"
+ ContentEncodingBzip2 = "bzip2"
+ ContentEncodingCompress = "compress" // Using LZW.
+ ContentEncodingGzip = "gzip"
+ ContentEncodingDeflate = "deflate" // Using zlib.
+
+ ContentLength = "Content-Length"
+
ContentType = "Content-Type"
ContentTypeBinary = "application/octet-stream"
ContentTypeForm = "application/x-www-form-urlencoded"
@@ -151,7 +158,9 @@ const (
ContentTypeJSON = "application/json"
ContentTypePlain = "text/plain; charset=utf-8"
ContentTypeXML = "text/xml; charset=utf-8"
- HeaderLocation = "Location"
+
+ HeaderLocation = "Location"
+ UserAgent = "User-Agent"
)
var (