alephant-broker 3.8.0 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26af20b2231cdb88d51a7ad006a5b807093d6d70
4
- data.tar.gz: 947c6ffae0e64eb7a77ff013ac8d7ddb7fcee67e
3
+ metadata.gz: 4250980c2dff335870765123e880080637deca3e
4
+ data.tar.gz: 29f174d321cf7b3807f6822500f6708c60f1752b
5
5
  SHA512:
6
- metadata.gz: 49147d5e3b73712e211e5db6ec26f35efe0e99e4cea1b9e9e261aab2cdbf316968e1e627e7de2dffbc3735961870b131926203fa16423d9414be8665469b7781
7
- data.tar.gz: 6dbc3c9d3bb758bfa64bf424a36adfdbe1456c018f55d7184914e3e05a6bad414ddeff8a9700db573ab7ee6bf66a3a8b6cb68e91ec4d237dbd201db6c4629d96
6
+ metadata.gz: 90837f01e54ecd028a680aef5907f2dd516f1c91e760c83ba9ec76f39815d5fdb02ba63b7cb29ac003729fdb04e4932c7f7f149a7552b11c457aa7c6bc82d637
7
+ data.tar.gz: 1d81181f2b962eab42c609d1065dc6fa361467e2f520fb20b7e9b06121b881cbbd8257ec8e2036dae89b0ee2cf66b0868e6318f2b03cec1ddd6d029f03a56d53
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "rack-test"
33
33
 
34
34
  spec.add_runtime_dependency "alephant-lookup"
35
- spec.add_runtime_dependency "alephant-storage"
35
+ spec.add_runtime_dependency "alephant-storage", ">= 1.1.0"
36
36
  spec.add_runtime_dependency "alephant-logger", "1.2.0"
37
37
  spec.add_runtime_dependency 'alephant-sequencer'
38
38
  spec.add_runtime_dependency "dalli-elasticache"
@@ -51,7 +51,10 @@ module Alephant
51
51
  end
52
52
 
53
53
  def header_key(key)
54
- key.gsub(HEADER_PREFIX, "").split("-").map(&:capitalize).join("-")
54
+ key = key.gsub(HEADER_PREFIX, "")
55
+ return key if key == "ETag"
56
+
57
+ key.split("-").map(&:capitalize).join("-")
55
58
  end
56
59
 
57
60
  def symbolize(hash)
@@ -1,4 +1,5 @@
1
- require 'alephant/logger'
1
+ require "alephant/logger"
2
+ require "crimp"
2
3
 
3
4
  module Alephant
4
5
  module Broker
@@ -12,7 +13,7 @@ module Alephant
12
13
  @components = components
13
14
  @batch_id = batch_id
14
15
 
15
- super(200, 'application/json')
16
+ super(200, "application/json")
16
17
  end
17
18
 
18
19
  def setup
@@ -20,6 +21,8 @@ module Alephant
20
21
  'batch_id' => batch_id,
21
22
  'components' => json
22
23
  })
24
+
25
+ @headers.merge!(batch_response_headers)
23
26
  end
24
27
 
25
28
  private
@@ -28,18 +31,40 @@ module Alephant
28
31
  logger.info "Broker: Batch load started (#{batch_id})"
29
32
  components.map do |component|
30
33
  {
31
- 'component' => component.id,
32
- 'options' => component.options,
33
- 'status' => component.status,
34
- 'content_type' => component.content_type,
35
- 'body' => component.content
34
+ "component" => component.id,
35
+ "options" => component.options,
36
+ "status" => component.status,
37
+ "content_type" => component.content_type,
38
+ "body" => component.content
36
39
  }
37
- end.tap {
38
- logger.info "Broker: Batch load done (#{batch_id})"
40
+ end.tap {
41
+ logger.info "Broker: Batch load done (#{batch_id})"
39
42
  logger.metric "BrokerBatchLoadCount"
40
43
  }
41
44
  end
42
45
 
46
+ def batch_response_headers
47
+ {
48
+ "ETag" => batch_response_etag,
49
+ "Last-Modified" => batch_response_last_modified
50
+ }
51
+ end
52
+
53
+ def batch_response_etag
54
+ etags = components.map do |component|
55
+ component.headers["ETag"]
56
+ end.compact
57
+
58
+ Crimp.signature(etags)
59
+ end
60
+
61
+ def batch_response_last_modified
62
+ last_modifieds = components.map do |component|
63
+ component.headers["Last-Modified"]
64
+ end.compact
65
+
66
+ last_modifieds.max
67
+ end
43
68
  end
44
69
  end
45
70
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Broker
3
- VERSION = "3.8.0"
3
+ VERSION = "3.9.0"
4
4
  end
5
5
  end
@@ -20,7 +20,10 @@ describe Alephant::Broker::Application do
20
20
  AWS::Core::Data.new(
21
21
  :content_type => "test/content",
22
22
  :content => "Test",
23
- :meta => {}
23
+ :meta => {
24
+ "head_ETag" => "123",
25
+ "head_Last-Modified" => "Mon, 11 Apr 2016 10:39:57 GMT"
26
+ }
24
27
  )
25
28
  end
26
29
  let(:sequencer_double) do
@@ -76,6 +79,8 @@ describe Alephant::Broker::Application do
76
79
  specify { expect(last_response.headers).to_not include("Cache-Control") }
77
80
  specify { expect(last_response.headers).to_not include("Pragma") }
78
81
  specify { expect(last_response.headers).to_not include("Expires") }
82
+ specify { expect(last_response.headers["ETag"]).to eq("123") }
83
+ specify { expect(last_response.headers["Last-Modified"]).to eq("Mon, 11 Apr 2016 10:39:57 GMT") }
79
84
  end
80
85
 
81
86
  context "for valid URL parameters in request" do
@@ -95,16 +100,44 @@ describe Alephant::Broker::Application do
95
100
  end
96
101
 
97
102
  before do
103
+ allow(s3_double).to receive(:get).and_return(
104
+ content,
105
+ AWS::Core::Data.new(
106
+ :content_type => "test/content",
107
+ :content => "Test",
108
+ :meta => {
109
+ "head_ETag" => "abc",
110
+ "head_Last-Modified" => "Mon, 11 Apr 2016 09:39:57 GMT"
111
+ }
112
+ )
113
+ )
114
+
98
115
  allow(Alephant::Storage).to receive(:new) { s3_double }
99
116
  end
100
117
 
101
118
  context "when using valid batch asset data" do
102
119
  let(:path) { "/components/batch" }
103
120
  let(:content_type) { "application/json" }
121
+
104
122
  before { post path, batch_json, "CONTENT_TYPE" => content_type }
105
123
 
106
124
  specify { expect(last_response.status).to eql 200 }
107
125
  specify { expect(last_response.body).to eq batch_compiled_json }
126
+
127
+ describe "response should have headers" do
128
+ it "should have content headers" do
129
+ expect(last_response.headers["Content-Type"]).to eq("application/json")
130
+ expect(last_response.headers["Content-Length"]).to eq("266")
131
+ end
132
+
133
+ it "should have ETag cache header" do
134
+ expect(last_response.headers["ETag"]).to eq("34774567db979628363e6e865127623f")
135
+ end
136
+
137
+ it "should have most recent Last-Modified header" do
138
+ expect(last_response.headers["Last-Modified"]).to eq("Mon, 11 Apr 2016 10:39:57 GMT")
139
+ end
140
+ end
108
141
  end
109
142
  end
110
143
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.0
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BBC News
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-22 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -183,7 +183,7 @@ dependencies:
183
183
  requirements:
184
184
  - - '>='
185
185
  - !ruby/object:Gem::Version
186
- version: '0'
186
+ version: 1.1.0
187
187
  name: alephant-storage
188
188
  prerelease: false
189
189
  type: :runtime
@@ -191,7 +191,7 @@ dependencies:
191
191
  requirements:
192
192
  - - '>='
193
193
  - !ruby/object:Gem::Version
194
- version: '0'
194
+ version: 1.1.0
195
195
  - !ruby/object:Gem::Dependency
196
196
  requirement: !ruby/object:Gem::Requirement
197
197
  requirements: