rack-canonical-host 1.2.0 → 1.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: 8d04ccdf68037f3995ea1a93a9f7858d5363fa9e4eae2797d6b35eb14b00e0f2
4
- data.tar.gz: 30f80af7f437c52e4bdbe61b3a95ee560bba6250546a4b02153d11565e0a9bc6
3
+ metadata.gz: 8352b4f1e9965403537863274605aa874e659dd21601d1bd30e75530c9aa3c26
4
+ data.tar.gz: bc8e09feaf6ef9fc84faf977b9e6a86efb9ee3af1e3efa5b3e03437bbde0c4a0
5
5
  SHA512:
6
- metadata.gz: 78b807b256f6683f3a8864e0f422208475cb03e4baa4bbce50a998000958f98b43f41deead8f400cb0ae78b9ee6b57b0bbb6d3d0504e9faf6b31db3ad13faccc
7
- data.tar.gz: 3a7186d72cea3a465fece9c11d2e178f1e6f09fa29e39463b58b92440fba32ecc56f2ff42742f5ad1a9359f17a4bff8a2ad3344c47308fd16a71bc2abb540230
6
+ metadata.gz: a27ba70e319608c1c0732a4cfb03ecd8ac972f49d43ff10d27d05342282dccd6f392d4601e975d7228ef895a3e6f63b206476f48c8cced5828b1cf35ed73d5f1
7
+ data.tar.gz: a49b560f4628d5f6e60dac7baa7452adee5d852b8a36532536bd95b59ddeda4d19022d496461f97a02cad2f1a87d04241c63e187d56ff69ebf00c452b72dc53f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.0 (2024-03-15)
4
+
5
+ * Respond to invalid request URL with 400 ([Gareth Jones][G-Rath])
6
+ * Drop support for Rack 1.5 ([Tyler Hunt][tylerhunt])
7
+
3
8
  ## 1.2.0 (2023-04-14)
4
9
 
5
10
  * Add support for Rack 3.0 ([Vinny Diehl][vinnydiehl])
@@ -94,3 +99,4 @@
94
99
  [zoso10]: https://github.com/zoso10
95
100
  [olleolleolle]: https://github.com/olleolleolle
96
101
  [vinnydiehl]: https://github.com/vinnydiehl
102
+ [G-Rath]: https://github.com/G-Rath
@@ -0,0 +1,37 @@
1
+ require 'addressable/uri'
2
+ require 'rack'
3
+
4
+ module Rack
5
+ class CanonicalHost
6
+ class Request
7
+ BAD_REQUEST = <<-HTML.gsub(/^\s+/, '')
8
+ <!DOCTYPE html>
9
+ <html lang="en-US">
10
+ <head><title>400 Bad Request</title></head>
11
+ <body>
12
+ <h1>Bad Request</h1>
13
+ </body>
14
+ </html>
15
+ HTML
16
+
17
+ def initialize(env)
18
+ self.env = env
19
+ end
20
+
21
+ def valid?
22
+ Addressable::URI.parse(Rack::Request.new(env).url)
23
+ true
24
+ rescue Addressable::URI::InvalidURIError
25
+ false
26
+ end
27
+
28
+ def bad_request_response
29
+ [400, { 'content-type' => 'text/html' }, [BAD_REQUEST]]
30
+ end
31
+
32
+ protected
33
+
34
+ attr_accessor :env
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class CanonicalHost
3
- VERSION = '1.2.0'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require 'rack'
2
2
  require 'rack/canonical_host/redirect'
3
+ require 'rack/canonical_host/request'
3
4
  require 'rack/canonical_host/version'
4
5
 
5
6
  module Rack
@@ -12,6 +13,10 @@ module Rack
12
13
  end
13
14
 
14
15
  def call(env)
16
+ request = Request.new(env)
17
+
18
+ return request.bad_request_response unless request.valid?
19
+
15
20
  host = evaluate_host(env)
16
21
  redirect = Redirect.new(env, host, options)
17
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-canonical-host
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Hunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-14 00:00:00.000000000 Z
11
+ date: 2024-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '1'
39
+ version: '1.6'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '4'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '1'
49
+ version: '1.6'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '4'
@@ -104,6 +104,7 @@ files:
104
104
  - lib/rack-canonical-host.rb
105
105
  - lib/rack/canonical_host.rb
106
106
  - lib/rack/canonical_host/redirect.rb
107
+ - lib/rack/canonical_host/request.rb
107
108
  - lib/rack/canonical_host/version.rb
108
109
  homepage: https://github.com/tylerhunt/rack-canonical-host
109
110
  licenses: