|
| 1 | +########################################################################## |
| 2 | +# Copyright 2016 ThoughtWorks, Inc. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +########################################################################## |
| 16 | + |
1 | 17 | class JettyWeakEtagMiddleware |
2 | 18 | def initialize(app) |
3 | 19 | @app = app |
4 | 20 | end |
5 | 21 |
|
| 22 | + MATCH_REGEX = /--(gzip|deflate)"$/ |
| 23 | + REPLACE_REGEX = /--(gzip|deflate)"?$/ |
| 24 | + |
6 | 25 | def call(env) |
7 | 26 | # make weak etags sent by jetty strong see: http://stackoverflow.com/questions/18693718/weak-etags-in-rails |
8 | | - if env['HTTP_IF_MATCH'] =~ /--gzip"$/ |
9 | | - env['HTTP_IF_MATCH'] = env['HTTP_IF_MATCH'].gsub(/--gzip"?$/, '"') |
| 27 | + if env['HTTP_IF_MATCH'] =~ MATCH_REGEX |
| 28 | + env['HTTP_IF_MATCH'] = env['HTTP_IF_MATCH'].gsub(REPLACE_REGEX, '"') |
10 | 29 | end |
11 | 30 |
|
12 | | - if env['HTTP_IF_NONE_MATCH'] =~ /--gzip"$/ |
13 | | - env['HTTP_IF_NONE_MATCH'] = env['HTTP_IF_NONE_MATCH'].gsub(/--gzip"?$/, '"') |
| 31 | + if env['HTTP_IF_NONE_MATCH'] =~ MATCH_REGEX |
| 32 | + env['HTTP_IF_NONE_MATCH'] = env['HTTP_IF_NONE_MATCH'].gsub(REPLACE_REGEX, '"') |
14 | 33 | end |
15 | 34 |
|
16 | 35 | status, headers, body = @app.call(env) |
|
0 commit comments