|
3 | 3 | module Grape
|
4 | 4 | class Request < Rack::Request
|
5 | 5 | DEFAULT_PARAMS_BUILDER = :hash_with_indifferent_access
|
6 |
| - HTTP_PREFIX = 'HTTP_' |
| 6 | + # Based on rack 3 KNOWN_HEADERS |
| 7 | + # https://github.com/rack/rack/blob/4f15e7b814922af79605be4b02c5b7c3044ba206/lib/rack/headers.rb#L10 |
| 8 | + |
| 9 | + KNOWN_HEADERS = %w[ |
| 10 | + Accept |
| 11 | + Accept-CH |
| 12 | + Accept-Encoding |
| 13 | + Accept-Language |
| 14 | + Accept-Patch |
| 15 | + Accept-Ranges |
| 16 | + Accept-Version |
| 17 | + Access-Control-Allow-Credentials |
| 18 | + Access-Control-Allow-Headers |
| 19 | + Access-Control-Allow-Methods |
| 20 | + Access-Control-Allow-Origin |
| 21 | + Access-Control-Expose-Headers |
| 22 | + Access-Control-Max-Age |
| 23 | + Age |
| 24 | + Allow |
| 25 | + Alt-Svc |
| 26 | + Authorization |
| 27 | + Cache-Control |
| 28 | + Client-Ip |
| 29 | + Connection |
| 30 | + Content-Disposition |
| 31 | + Content-Encoding |
| 32 | + Content-Language |
| 33 | + Content-Length |
| 34 | + Content-Location |
| 35 | + Content-MD5 |
| 36 | + Content-Range |
| 37 | + Content-Security-Policy |
| 38 | + Content-Security-Policy-Report-Only |
| 39 | + Content-Type |
| 40 | + Cookie |
| 41 | + Date |
| 42 | + Delta-Base |
| 43 | + Dnt |
| 44 | + ETag |
| 45 | + Expect-CT |
| 46 | + Expires |
| 47 | + Feature-Policy |
| 48 | + Forwarded |
| 49 | + Host |
| 50 | + If-Modified-Since |
| 51 | + If-None-Match |
| 52 | + IM |
| 53 | + Last-Modified |
| 54 | + Link |
| 55 | + Location |
| 56 | + NEL |
| 57 | + P3P |
| 58 | + Permissions-Policy |
| 59 | + Pragma |
| 60 | + Preference-Applied |
| 61 | + Proxy-Authenticate |
| 62 | + Public-Key-Pins |
| 63 | + Range |
| 64 | + Referer |
| 65 | + Referrer-Policy |
| 66 | + Refresh |
| 67 | + Report-To |
| 68 | + Retry-After |
| 69 | + Sec-Fetch-Dest |
| 70 | + Sec-Fetch-Mode |
| 71 | + Sec-Fetch-Site |
| 72 | + Sec-Fetch-User |
| 73 | + Server |
| 74 | + Set-Cookie |
| 75 | + Status |
| 76 | + Strict-Transport-Security |
| 77 | + Timing-Allow-Origin |
| 78 | + Tk |
| 79 | + Trailer |
| 80 | + Transfer-Encoding |
| 81 | + Upgrade |
| 82 | + Upgrade-Insecure-Requests |
| 83 | + User-Agent |
| 84 | + Vary |
| 85 | + Version |
| 86 | + Via |
| 87 | + Warning |
| 88 | + WWW-Authenticate |
| 89 | + X-Accel-Buffering |
| 90 | + X-Accel-Charset |
| 91 | + X-Accel-Expires |
| 92 | + X-Accel-Limit-Rate |
| 93 | + X-Accel-Mapping |
| 94 | + X-Accel-Redirect |
| 95 | + X-Access-Token |
| 96 | + X-Auth-Request-Access-Token |
| 97 | + X-Auth-Request-Email |
| 98 | + X-Auth-Request-Groups |
| 99 | + X-Auth-Request-Preferred-Username |
| 100 | + X-Auth-Request-Redirect |
| 101 | + X-Auth-Request-Token |
| 102 | + X-Auth-Request-User |
| 103 | + X-Cascade |
| 104 | + X-Client-Ip |
| 105 | + X-Content-Duration |
| 106 | + X-Content-Security-Policy |
| 107 | + X-Content-Type-Options |
| 108 | + X-Correlation-Id |
| 109 | + X-Download-Options |
| 110 | + X-Forwarded-Access-Token |
| 111 | + X-Forwarded-Email |
| 112 | + X-Forwarded-For |
| 113 | + X-Forwarded-Groups |
| 114 | + X-Forwarded-Host |
| 115 | + X-Forwarded-Port |
| 116 | + X-Forwarded-Preferred-Username |
| 117 | + X-Forwarded-Proto |
| 118 | + X-Forwarded-Scheme |
| 119 | + X-Forwarded-Ssl |
| 120 | + X-Forwarded-Uri |
| 121 | + X-Forwarded-User |
| 122 | + X-Frame-Options |
| 123 | + X-HTTP-Method-Override |
| 124 | + X-Permitted-Cross-Domain-Policies |
| 125 | + X-Powered-By |
| 126 | + X-Real-IP |
| 127 | + X-Redirect-By |
| 128 | + X-Request-Id |
| 129 | + X-Requested-With |
| 130 | + X-Runtime |
| 131 | + X-Sendfile |
| 132 | + X-Sendfile-Type |
| 133 | + X-UA-Compatible |
| 134 | + X-WebKit-CS |
| 135 | + X-XSS-Protection |
| 136 | + ].each_with_object({}) do |header, response| |
| 137 | + response["HTTP_#{header.upcase.tr('-', '_')}"] = header |
| 138 | + end.freeze |
7 | 139 |
|
8 | 140 | alias rack_params params
|
9 | 141 | alias rack_cookies cookies
|
@@ -49,15 +181,11 @@ def make_params
|
49 | 181 |
|
50 | 182 | def build_headers
|
51 | 183 | each_header.with_object(Grape::Util::Header.new) do |(k, v), headers|
|
52 |
| - next unless k.start_with? HTTP_PREFIX |
| 184 | + next unless k.start_with? 'HTTP_' |
53 | 185 |
|
54 |
| - transformed_header = Grape::Http::Headers::HTTP_HEADERS[k] || transform_header(k) |
| 186 | + transformed_header = KNOWN_HEADERS.fetch(k) { -k[5..].tr('_', '-').downcase } |
55 | 187 | headers[transformed_header] = v
|
56 | 188 | end
|
57 | 189 | end
|
58 |
| - |
59 |
| - def transform_header(header) |
60 |
| - -header[5..].tr('_', '-').downcase |
61 |
| - end |
62 | 190 | end
|
63 | 191 | end
|
0 commit comments