web_fetch 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile.lock +1 -1
- data/lib/web_fetch/http_helpers.rb +8 -1
- data/lib/web_fetch/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f2284ce2ad4cac05effcd7ae1502f269ceb9d3b1b99f66be1e3ef8cdd6bd786
|
4
|
+
data.tar.gz: 04c3a091ced9abff4330b6bfca921d6be78df3b1842191082af8f7bffd2ba7a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92d7b6dc31b2d981a9679b4896325e77d397689ab54aca28ba4340234855a7c0e0e2ef7cedae655e147dca977a36ce025cf18a02306f680a1167d88f0ecf6690
|
7
|
+
data.tar.gz: a5894ebdac3925968cb28538f5891a102515c1c392f9a9b00b39bf839f1fb7bc6cb4ce54f0c3341879292425475ce17a6b36b6ff209472eac737fcfc3e951cbc
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -10,13 +10,15 @@ module WebFetch
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def compress(string)
|
13
|
+
return string unless accept_gzip?
|
14
|
+
|
13
15
|
ActiveSupport::Gzip.compress(string)
|
14
16
|
end
|
15
17
|
|
16
18
|
def default_headers(response)
|
17
19
|
response.headers['Content-Type'] = 'application/json; charset=utf-8'
|
18
20
|
response.headers['Cache-Control'] = 'max-age=0, private, must-revalidate'
|
19
|
-
response.headers['Content-Encoding'] = 'gzip'
|
21
|
+
response.headers['Content-Encoding'] = 'gzip' if accept_gzip?
|
20
22
|
response.headers['Vary'] = 'Accept-Encoding'
|
21
23
|
end
|
22
24
|
|
@@ -67,5 +69,10 @@ module WebFetch
|
|
67
69
|
},
|
68
70
|
uid: deferred[:uid] }
|
69
71
|
end
|
72
|
+
|
73
|
+
def accept_gzip?
|
74
|
+
# em-http-request doesn't do us any favours with parsing the HTTP headers
|
75
|
+
@http_headers.downcase.include?('accept-encoding: gzip')
|
76
|
+
end
|
70
77
|
end
|
71
78
|
end
|
data/lib/web_fetch/version.rb
CHANGED