slimmer 13.2.2 → 13.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dad0beacc561e5407f29aaeabea18a46087d12b5bc22b28fa9bffbc4c17c0fd
4
- data.tar.gz: 11bc7fc2a2e3d9add7485fd327751be25aa1b744ed5e90dfde7bd6f0a58991bf
3
+ metadata.gz: 29c95c6ec5fcb3d786e88628da00aa44018de1a338e49359d19088db092ea025
4
+ data.tar.gz: 5c2f32ef832e751dc5812af7cb9d388fd4a36c8bde03d9525f58b7a46b5f0e87
5
5
  SHA512:
6
- metadata.gz: 13594f752cdecb7288c867c063d83237a1a6aee22720bee8b6cdc233c377a3c7c7bb4664591a51962b82c2f8d72325038621230270d1e37c4d58b3b46464fb81
7
- data.tar.gz: f03a441b1f847173daf557889a5acc52fae82f5a7763cb03bb4baa53160443a52666fc457d7e2e108907f0a3f16552d33a1a4e2bbe4106effad350d4ed81c356
6
+ metadata.gz: 111d7b5964863534428a2a6b9f46252f49624cb226c524e6c048cbff155c2a37d96cf14f85ade73d71b9b8bbeef1065596f9e795682f7f4fe913529fb0225116
7
+ data.tar.gz: 182cab20358b7ae4b69b17c11b19ddb6697e54bd94cd66575478bdc0fa11d6a03597d9788ec4c03b6da22f6ccbb5a4156042aaecb433b1c7ddc907c2e3b7934f
@@ -1,3 +1,7 @@
1
+ # 13.3.0
2
+
3
+ * Add X-Slimmer-Ignore-Error header flag to prevent overriding non-200 status responses
4
+
1
5
  # 13.2.2
2
6
 
3
7
  * Fix bug where parent_name was called without app
@@ -64,6 +64,10 @@ module Slimmer
64
64
  !!response.headers[Headers::SKIP_HEADER]
65
65
  end
66
66
 
67
+ def ignore_error_header?(response)
68
+ !!response.headers[Headers::IGNORE_ERROR_HEADER]
69
+ end
70
+
67
71
  def s(body)
68
72
  return body.to_s unless body.respond_to?(:each)
69
73
 
@@ -84,26 +88,32 @@ module Slimmer
84
88
  # Store the request id so it can be passed on with any template requests
85
89
  GovukRequestId.value = env["HTTP_GOVUK_REQUEST_ID"]
86
90
 
87
- rewritten_body = case response.status
88
- when 200
89
- @skin.success request, response, s(response.body)
90
- when 403
91
- @skin.error "403", s(response.body), request.env
92
- when 404
93
- @skin.error "404", s(response.body), request.env
94
- when 410
95
- @skin.error "410", s(response.body), request.env
96
- else
97
- @skin.error "500", s(response.body), request.env
98
- end
99
-
100
- rewritten_body = [rewritten_body] unless rewritten_body.respond_to?(:each)
101
- response.body = rewritten_body
91
+ body = rewritten_body(request, response)
92
+
93
+ body = [body] unless body.respond_to?(:each)
94
+ response.body = body
102
95
  response.headers["Content-Length"] = content_length(response.body)
103
96
 
104
97
  response.finish
105
98
  end
106
99
 
100
+ def rewritten_body(request, response)
101
+ return @skin.success request, response, s(response.body) if ignore_error_header?(response)
102
+
103
+ case response.status
104
+ when 200
105
+ @skin.success request, response, s(response.body)
106
+ when 403
107
+ @skin.error "403", s(response.body), request.env
108
+ when 404
109
+ @skin.error "404", s(response.body), request.env
110
+ when 410
111
+ @skin.error "410", s(response.body), request.env
112
+ else
113
+ @skin.error "500", s(response.body), request.env
114
+ end
115
+ end
116
+
107
117
  def strip_slimmer_headers(headers)
108
118
  headers.reject { |k, _v| k =~ /\A#{Headers::HEADER_PREFIX}/ }
109
119
  end
@@ -20,6 +20,7 @@ module Slimmer
20
20
  skip: "Skip",
21
21
  template: "Template",
22
22
  remove_search: "Remove-Search",
23
+ ignore_error: "Ignore-Error",
23
24
  }.freeze
24
25
 
25
26
  # @private
@@ -55,10 +56,15 @@ module Slimmer
55
56
  # @private
56
57
  REMOVE_SEARCH_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:remove_search]}".freeze
57
58
 
59
+ # @private
60
+ IGNORE_ERROR_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:ignore_error]}".freeze
61
+
62
+
58
63
  # Set the "slimmer headers" to configure the page
59
64
  #
60
65
  # @param hash [Hash] the options
61
66
  # @option hash [String] application_name
67
+ # @option hash [String] ignore_error
62
68
  # @option hash [String] format
63
69
  # @option hash [String] organisations
64
70
  # @option hash [String] page_owner
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = "13.2.2".freeze
2
+ VERSION = "13.3.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.2.2
4
+ version: 13.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-04 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport