qeweney 0.8.1 → 0.9.1

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
  SHA256:
3
- metadata.gz: 43b284ffdbd86680bb9e5c34738006fa8b3e0d48f36ce45df533e8afcd3f2961
4
- data.tar.gz: 5d69cc440ed42251b6970a86e9b63ec3419aa0fad946f9353d29ec58526c6d0f
3
+ metadata.gz: e7607c9eba1cc73f966e3da34d266c40aa0dec6d9294da905b49f3b3efc628ff
4
+ data.tar.gz: 16c15a7655cab3ed23437ed6f1f12d63df3676d63145cfb75a0505de1b8b5f3b
5
5
  SHA512:
6
- metadata.gz: 5fd5ce37b83afc129ae262d8dcfc0288bd206e6b3c260577c00a89a5bcc7b44a3337d67087a9b05c281f49aa9f35b6202d44c8c5f535023c9c30929232e5bee5
7
- data.tar.gz: cb7636b76961093665c6cf92c882a377ed028d0afa2a048dfd92da51fae88ca2815353287de5f2c34f75f81ddf056fc434c9cc71c34c4b6429f594c6b1c30068
6
+ metadata.gz: 7ce90ffad9f012d33ebaf6a48100ad684151b1b62be47004fdc8d991e6e755755c15ce945a602d607d1124db962e7a49921e369d9c9dadb059c776ae7c94c175
7
+ data.tar.gz: 0b950d98a942954ae7c824c3a475eaaeb9752a6d7a854fbebd383a02afde1d703ddf530538900d5f79ba61eddc1ab8220a0e2b9e95c488be225170d62d7de296
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## 0.9.1 2021-06-14
2
+
3
+ - Fix reading host from `:authority` header
4
+
5
+ ## 0.9.0 2021-05-14
6
+
7
+ - Fix query parsing for fields with empty value
8
+
9
+ ## 0.8.4 2021-03-23
10
+
11
+ - Rename and fix `#parse_query` to deal with no-value query parts
12
+
13
+ ## 0.8.3 2021-03-22
14
+
15
+ - Streamline routing behaviour in sub routes (an explicit default sub route is
16
+ now required if no sub route matches)
17
+
18
+ ## 0.8.2 2021-03-17
19
+
20
+ - Fix form parsing when charset is specified
21
+
1
22
  ## 0.8.1 2021-03-10
2
23
 
3
24
  - Add `Request#transfer_counts`, `Request#total_transfer`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qeweney (0.8.1)
4
+ qeweney (0.9.1)
5
5
  escape_utils (~> 1.2.1)
6
6
 
7
7
  GEM
@@ -6,8 +6,9 @@ require 'escape_utils'
6
6
  module Qeweney
7
7
  module RequestInfoMethods
8
8
  def host
9
- @headers['host']
9
+ @headers['host'] || @headers[':authority']
10
10
  end
11
+ alias_method :authority, :host
11
12
 
12
13
  def connection
13
14
  @headers['connection']
@@ -52,14 +53,16 @@ module Qeweney
52
53
  def query
53
54
  return @query if @query
54
55
 
55
- @query = (q = uri.query) ? split_query_string(q) : {}
56
+ @query = (q = uri.query) ? parse_query(q) : {}
56
57
  end
57
58
 
58
- def split_query_string(query)
59
+ QUERY_KV_REGEXP = /([^=]+)(?:=(.*))?/
60
+
61
+ def parse_query(query)
59
62
  query.split('&').each_with_object({}) do |kv, h|
60
- k, v = kv.split('=')
61
- p split_query_string: { k: k, v: v }
62
- h[k.to_sym] = URI.decode_www_form_component(v)
63
+ k, v = kv.match(QUERY_KV_REGEXP)[1..2]
64
+ # k, v = kv.split('=')
65
+ h[k.to_sym] = v ? URI.decode_www_form_component(v) : true
63
66
  end
64
67
  end
65
68
 
@@ -102,10 +105,10 @@ module Qeweney
102
105
  module RequestInfoClassMethods
103
106
  def parse_form_data(body, headers)
104
107
  case (content_type = headers['content-type'])
105
- when /multipart\/form\-data; boundary=([^\s]+)/
108
+ when /^multipart\/form\-data; boundary=([^\s]+)/
106
109
  boundary = "--#{Regexp.last_match(1)}"
107
110
  parse_multipart_form_data(body, boundary)
108
- when 'application/x-www-form-urlencoded'
111
+ when /^application\/x-www-form-urlencoded/
109
112
  parse_urlencoded_form_data(body)
110
113
  else
111
114
  raise "Unsupported form data content type: #{content_type}"
@@ -16,7 +16,7 @@ module Qeweney
16
16
 
17
17
  def route_found(&block)
18
18
  catch(:stop, &block)
19
- throw :stop, headers_sent? ? :found : nil
19
+ throw :stop, :found
20
20
  end
21
21
 
22
22
  @@regexp_cache = {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Qeweney
4
- VERSION = '0.8.1'
4
+ VERSION = '0.9.1'
5
5
  end
@@ -13,12 +13,31 @@ class RequestInfoTest < MiniTest::Test
13
13
  assert_equal({ a: '1', b: '2', c: '3/4' }, r.query)
14
14
  end
15
15
 
16
+ def test_query
17
+ r = Qeweney.mock(':path' => '/GponForm/diag_Form?images/')
18
+ assert_equal '/GponForm/diag_Form', r.path
19
+ assert_equal({:'images/' => true}, r.query)
20
+
21
+ r = Qeweney.mock(':path' => '/?a=1&b=2')
22
+ assert_equal '/', r.path
23
+ assert_equal({a: '1', b: '2'}, r.query)
24
+
25
+ r = Qeweney.mock(':path' => '/?l=a&t=&x=42')
26
+ assert_equal({l: 'a', t: '', x: '42'}, r.query)
27
+ end
28
+
16
29
  def test_host
17
30
  r = Qeweney.mock(':path' => '/')
18
31
  assert_nil r.host
32
+ assert_nil r.authority
19
33
 
20
34
  r = Qeweney.mock('host' => 'my.example.com')
21
35
  assert_equal 'my.example.com', r.host
36
+ assert_equal 'my.example.com', r.authority
37
+
38
+ r = Qeweney.mock(':authority' => 'my.foo.com')
39
+ assert_equal 'my.foo.com', r.host
40
+ assert_equal 'my.foo.com', r.authority
22
41
  end
23
42
 
24
43
  def test_full_uri
data/test/test_routing.rb CHANGED
@@ -12,6 +12,7 @@ class RoutingTest < MiniTest::Test
12
12
  r.on_post do
13
13
  r.redirect '/'
14
14
  end
15
+ r.default { r.respond nil, ':status' => 404 }
15
16
  end
16
17
  end
17
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qeweney
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubygems_version: 3.0.8
139
+ rubygems_version: 3.1.4
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Qeweney - cross library HTTP request / response API