rack-joint 0.3.3 → 0.3.4

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: ee257b799f66a7c26ac7f2c84c21cae1db7b2d43dd7c119ef79bf644b9d529b5
4
- data.tar.gz: b9d746c446d687b39edadf90078a02449675f0952a57b142eb2e784656be933a
3
+ metadata.gz: c970bb4e0434cb885b6964104eac12d33fe5b10088183ce1a9d751f88408f443
4
+ data.tar.gz: d7f226e76b27b5958598e63dc9f48002553a070ced6be052c91211eb6de672c8
5
5
  SHA512:
6
- metadata.gz: a3b15942200d64afa3af22f76e89d5ac26bb75b95994c941c82fed88fa8de33a9f6830ec06f4f9e821df2d22c6ff500681fd50c14363f418f731dfc490ed780e
7
- data.tar.gz: a95a55acbde20af0026cd4e5d9db0d67a7c201428868476844dbdf8d69a604cb73e78f3fa711cc3ec4f56e383f9ee6bf8070955ce9474fe85278ec440ac7454f
6
+ metadata.gz: c5a0da46d2f05ada980d6de76654d94970091ac41483e1afdc194809aa63f6b5d6a9066536adb337ea4a5a767608628e0334257523cb147dd403abdc281d89a1
7
+ data.tar.gz: e03c685fb7237a11f4cf56bae63c27134f7d3913751397a3015e316b490837c1d6e44353c2bf64d27a34fc1fd8cf3745a48afc856ae78ab24f39d0dd12fa6383
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ### 0.3.4 (2019-03-25)
6
+ * Allow query parameters when request URLs have them. [#18](https://github.com/akito19/rack-joint/pull/18)
7
+
5
8
  ### 0.3.3 (2019-01-19)
6
9
  * Support Bundler2. [#15](https://github.com/akito19/rack-joint/pull/15)
7
10
 
@@ -2,6 +2,7 @@ require "rack"
2
2
  require "rack/joint/context"
3
3
  require "rack/joint/redirect"
4
4
  require "rack/joint/redirect_interface"
5
+ require "rack/joint/url_builder"
5
6
  require "rack/joint/version"
6
7
 
7
8
  module Rack
@@ -27,7 +28,7 @@ module Rack
27
28
 
28
29
  private
29
30
 
30
- # @param mapping [Array] URI mappings for redirecting.
31
+ # @param mappings [Array] URI mappings for redirecting.
31
32
  # @param host [String] Requested hostname(env).
32
33
  # @return [Array] Return URL mapped responses.
33
34
  def valid_mapping(mappings, host)
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
- require 'uri'
3
-
4
2
  module Rack
5
3
  class Joint
6
4
  class BadRedirectError < StandardError; end
7
5
 
8
6
  class RedirectInterface
9
- attr_reader :scheme, :request_scheme, :old_host, :old_path
7
+ attr_reader :scheme, :request_scheme, :request_query, :old_host, :old_path
10
8
  def initialize(request, old_host, old_path, &block)
11
9
  @status = 301
12
10
  @scheme = nil
11
+ @request_query = request.query_string
13
12
  @request_scheme = request.scheme
14
13
  @old_host = old_host
15
14
  @old_path = old_path || request.path_info
@@ -21,8 +20,8 @@ module Rack
21
20
  @scheme ||= request_scheme
22
21
  @new_host ||= old_host
23
22
  @new_path ||= old_path
24
- old_url = build_uri(request_scheme, old_host, old_path)
25
- new_location = build_uri(scheme, @new_host, @new_path)
23
+ old_url = UrlBuilder.new(request_scheme, request_query, old_host, old_path).build
24
+ new_location = UrlBuilder.new(scheme, request_query, @new_host, @new_path).build
26
25
  if old_url == new_location
27
26
  raise BadRedirectError.new('Redirect URL has been declared the same as current URL.')
28
27
  end
@@ -31,18 +30,6 @@ module Rack
31
30
 
32
31
  private
33
32
 
34
- # @param scheme [String] 'http' or 'https'
35
- # @param host [String] Host name
36
- # @param path [String] Path name
37
- # @return [URI]
38
- def build_uri(scheme, host, path)
39
- if scheme == 'https'
40
- URI::HTTPS.build({ scheme: scheme, host: host, path: path }).to_s
41
- else
42
- URI::HTTP.build({ scheme: scheme, host: host, path: path }).to_s
43
- end
44
- end
45
-
46
33
  # @param flag [Boolean]
47
34
  # @return [String] `http` or `https`
48
35
  def ssl(flag)
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ require 'uri'
3
+
4
+ module Rack
5
+ class Joint
6
+ class UrlBuilder
7
+ attr_reader :scheme, :query, :host, :path
8
+ def initialize(scheme, request_query, host, path)
9
+ @scheme = scheme
10
+ @query = request_query
11
+ @host = host
12
+ @path = path
13
+ end
14
+
15
+ # @return [URI] URL with SSL or non-SSL
16
+ def build
17
+ if scheme == 'https'
18
+ https_url_builder
19
+ else
20
+ http_url_builder
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ # @return [URI]
27
+ def https_url_builder
28
+ # When query parameters isn't added to request URL,
29
+ # returns empty String object with `Rack::Request::Helper#query_string`.
30
+ if query.empty?
31
+ URI::HTTPS.build({ host: host, path: path }).to_s
32
+ else
33
+ URI::HTTPS.build({ host: host, path: path, query: query }).to_s
34
+ end
35
+ end
36
+
37
+ # @return [URI]
38
+ def http_url_builder
39
+ # When query parameters isn't added to request URL,
40
+ # returns empty String object with `Rack::Request::Helper#query_string`.
41
+ if query.empty?
42
+ URI::HTTP.build({ host: host, path: path }).to_s
43
+ else
44
+ URI::HTTP.build({ host: host, path: path, query: query }).to_s
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Joint
3
- VERSION = "0.3.3"
3
+ VERSION = "0.3.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-joint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akito Kasai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-19 00:00:00.000000000 Z
11
+ date: 2019-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -102,6 +102,7 @@ files:
102
102
  - lib/rack/joint/context.rb
103
103
  - lib/rack/joint/redirect.rb
104
104
  - lib/rack/joint/redirect_interface.rb
105
+ - lib/rack/joint/url_builder.rb
105
106
  - lib/rack/joint/version.rb
106
107
  - rack-joint.gemspec
107
108
  homepage: https://github.com/akito19/rack-joint