rack-joint 0.2.0 → 0.3.0

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: f3e792eebe6018b20bcfcd52b8585ed66527ef3f726d66c262870713de146734
4
- data.tar.gz: 637b67d842b4a9d8fd1ad282eb411d2d643e939bc06fd870f268d9e44dccdf0e
3
+ metadata.gz: f3059643a9228fad6f23fa1f0a6851023c1612c5bd8fbbde57fe0f584f600ca9
4
+ data.tar.gz: '05907c6390bfb966cd2a517c0a2e247f2b51a449aaee09da4e2b27f2368fd6b2'
5
5
  SHA512:
6
- metadata.gz: 8a4903e59817ca4e4bdb9a0a8beb65e31a152dd36f575fb9f53f45b52863e01afe126c4f6ea0edcfb3fb597f84b8b318c79bb9687d85c1ce8e5a371285530161
7
- data.tar.gz: 414c0224b3ec9097f2d600fcc70c36ae92ad4fc0cc7dd27859b51005c3742aff5f5ed0e8d469b94c854bcfbe93016a0b0633a4f85bc34bfc23c63cd54e9a18a4
6
+ metadata.gz: 6cdb06e0d4b1e06182f8a69d6d78907b19cd39f5ac925c5b9c14ec642a123f8336b31af5adc974715b3fe6b102b4f3650bc226066774a8799fd7d16f75cc60a1
7
+ data.tar.gz: 6d2222cb89b23d1e014bb74dd42c07f2cc55c569f18342c8ac647fb3669c0a9080499a4991ed66ebd415d386bbecdbc7b08fd8f6a1a97737e2e39a918ea2fb8b
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ### 0.3.0 (2018-09-01)
6
+ * Determine scheme in response to requests. [#7](https://github.com/akito19/rack-joint/pull/7)
7
+
5
8
  ### 0.2.0 (2018-08-30)
6
9
  * Enable to use SSL when redirecting. [#4](https://github.com/akito19/rack-joint/pull/4)
7
10
  * Refactor to run redirect process. [#5](https://github.com/akito19/rack-joint/pull/5)
data/README.md CHANGED
@@ -73,9 +73,9 @@ You can use following resources with block.
73
73
  | :------- | :--- | :---------- |
74
74
  | `host` | String | Host name. |
75
75
  | `redirect` | String | Path name. |
76
- | `ssl` | Boolean | Whether to enable SSL or not; which is `false` to default. |
77
- | `new_host` | String | A new host name redirects to. Optional. |
78
- | `to` | String | A new path name redirects to. Optional. |
76
+ | `ssl` | Boolean | Whether to enable SSL. If the option isn't set, the scheme of `Location` header is determined in response to GET request. |
77
+ | `new_host` | String | A new host name redirects to. |
78
+ | `to` | String | A new path name redirects to. |
79
79
  | `status` | Integer | Status when redirecting. You can use `301`, `302`, `303`, `307`, `308`; which is `301` to default. |
80
80
 
81
81
  ## Development
@@ -6,22 +6,23 @@ module Rack
6
6
  class BadRedirectError < StandardError; end
7
7
 
8
8
  class RedirectInterface
9
- attr_reader :request, :old_host, :old_path, :old_url
9
+ attr_reader :scheme, :request_scheme, :old_host, :old_path, :old_url
10
10
  def initialize(request, old_host, old_path, &block)
11
11
  @status = 301
12
- @ssl = false
13
- @request = request
12
+ @scheme = nil
13
+ @request_scheme = request.scheme
14
14
  @old_host = old_host
15
15
  @old_path = old_path
16
- @old_url = build_uri(request.scheme, old_host, old_path)
16
+ @old_url = build_uri(request_scheme, old_host, old_path)
17
17
  instance_exec(&block)
18
18
  end
19
19
 
20
20
  # @return [Array] Return response given parameters in `config.ru`.
21
21
  def apply!
22
+ @scheme ||= request_scheme
22
23
  @new_host ||= old_host
23
24
  @new_path ||= old_path
24
- new_location = build_uri(uri_scheme, @new_host, @new_path)
25
+ new_location = build_uri(scheme, @new_host, @new_path)
25
26
  if old_url == new_location
26
27
  raise BadRedirectError.new('Redirect URL has been declared the same as current URL.')
27
28
  end
@@ -30,15 +31,6 @@ module Rack
30
31
 
31
32
  private
32
33
 
33
- # @return [String] `http` or `https`
34
- def uri_scheme
35
- if @ssl
36
- 'https'
37
- else
38
- 'http'
39
- end
40
- end
41
-
42
34
  # @param scheme [String] 'http' or 'https'
43
35
  # @param host [String] Host name
44
36
  # @param path [String] Path name
@@ -51,10 +43,15 @@ module Rack
51
43
  end
52
44
  end
53
45
 
54
- # @param scheme [Boolean] Wether enabling SSL or not.
55
- # @return [Boolean]
56
- def ssl(scheme)
57
- @ssl = scheme
46
+ # @param flag [Boolean]
47
+ # @return [String] `http` or `https`
48
+ def ssl(flag)
49
+ @scheme =
50
+ if flag
51
+ 'https'
52
+ else
53
+ 'http'
54
+ end
58
55
  end
59
56
 
60
57
  # @param status [Integer] `status` parameter when redirecting in `config.ru`.
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Joint
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["kasai@akito19.com"]
11
11
 
12
12
  spec.summary = %q{A rack middleware for redirecting.}
13
- spec.description = %q{A rack middleware to help you to redirect.}
13
+ spec.description = %q{Rack::Joint is a rack middleware to help redirecting to each path.}
14
14
  spec.homepage = "https://github.com/akito19/rack-joint"
15
15
  spec.license = "MIT"
16
16
 
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akito Kasai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-29 00:00:00.000000000 Z
11
+ date: 2018-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: A rack middleware to help you to redirect.
83
+ description: Rack::Joint is a rack middleware to help redirecting to each path.
84
84
  email:
85
85
  - kasai@akito19.com
86
86
  executables: []