hosty 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 00869051be7d97f98e4ebc2f562743e6b4ee0c7c
4
- data.tar.gz: 61aec49f9845a4e8c3189ae0c1b833df288061bf
3
+ metadata.gz: aa4c812980a81da36b3932c3d701f91890b01a9a
4
+ data.tar.gz: c5d0e7696dc1b6b551cfffa8d2800f0aea1aa9bf
5
5
  SHA512:
6
- metadata.gz: c6431644278be6510c1f1328f43d6d7b0ff914a79c2ffd50b7db1fab414906249c9a06c2dd6bd7188f82eea8be19352b4888a1a4fcf195053c48131c560d7fef
7
- data.tar.gz: cb8d1db939a94aead86289586b4bb55402850c53d78e7c5adfa9adb15f5c1898b73f39e688ade8393b8f481920a6d783dd675aa314c2d19d56728789507258c5
6
+ metadata.gz: 2a1bfd75a8406de3be137551db8169522457eac4efee1019852cc7ad88c64babb0202a8b46e1b432e26b89a4457c9631a0e8c47db7ffdc0dfbb7b3f7c41ede91
7
+ data.tar.gz: ecb768e70845bc7c87a7356cb53fff1f108b305c49fec3cf77c1020ab3abf61bff5f80cb729d7916a2d18bc26ef878916dc8c14d973fa8933c14499b4dc37a09
data/README.md CHANGED
@@ -31,14 +31,28 @@ If you have lines below in your ```/etc/hosts```:
31
31
  127.0.0.1 rails # :3000
32
32
  ```
33
33
 
34
- Hosty accepts ```http(s)://internal.example.com/foo``` locally and proxies it
35
- into ```http(s)://internal.example.com:8080/foo``` for example. URL scheme will be kept intact.
34
+ Hosty accepts ```http://internal.example.com/foo``` locally and proxies it
35
+ into ```http://internal.example.com:8080/foo``` for example.
36
36
 
37
- Shortly,
38
37
 
39
- * http(s)://internal.example.com → http(s)://internal.example.com:8080
40
- * http(s)://internal → http(s)://internal:8080
41
- * http(s)://rails http(s)://rails:3000
38
+ ### Use https
39
+
40
+ You can specify ```tls``` option at the end of each line:
41
+
42
+ ```
43
+ 127.0.0.1 internal.example.com internal # :8080 tls
44
+ ```
45
+
46
+ Hosty accepts ```http://internal.example.com/foo``` and proxies into ```https://internal.example.com:8080/foo```. Also, you can spacify 'verify_none' to skip server cert verification.
47
+
48
+ ```
49
+ 127.0.0.1 internal.example.com internal # :8080 tls verify_none
50
+ ```
51
+
52
+ **Note**
53
+
54
+ The URL scheme in your browser is always 'http'.
55
+
42
56
 
43
57
 
44
58
  ## Copyright and License
data/config.ru CHANGED
@@ -3,9 +3,14 @@ require 'hosty'
3
3
  use Rack::ReverseProxy do
4
4
  Hosty::Hosts.mapping do |map|
5
5
  port = map[:port]
6
+ scheme = map[:options].include?('tls') ? 'https' : 'http'
7
+
8
+ proxy_options = {}
9
+ proxy_options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if map[:options].include?('verify_none')
10
+
6
11
 
7
12
  map[:servers].each do |server|
8
- reverse_proxy /(.*)/, "//#{server}:#{port}/$1", vhost: server
13
+ reverse_proxy /(.*)/, "#{scheme}://#{server}:#{port}/$1", {vhost: server}.merge(proxy_options)
9
14
  end
10
15
  end
11
16
  end
data/exe/hosty CHANGED
@@ -4,6 +4,4 @@ require 'rack'
4
4
 
5
5
  config = File.expand_path('../../config.ru', __FILE__)
6
6
 
7
- Thread.start { Rack::Server.start(config: config, Port: 80) }
8
- Thread.start { Rack::Server.start(config: config, Port: 443) }.join # single ^C to kill all
9
-
7
+ Rack::Server.start(config: config, Port: 80)
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "hosty"
7
- spec.version = '0.0.1'
7
+ spec.version = '0.0.2'
8
8
  spec.authors = ["Shintaro Kojima"]
9
9
  spec.email = ["goodies@codeout.net"]
10
10
 
@@ -1,7 +1,5 @@
1
1
  require 'hosty/hosts'
2
- require 'hosty/scheme_detectable'
3
2
  require 'hosty/virtual_hostable'
4
3
  require 'rack/reverse_proxy'
5
4
 
6
5
  RackReverseProxy::RoundTrip.prepend Hosty::VirtualHostable
7
- RackReverseProxy::Rule::Candidate.prepend Hosty::SchemeDetectable
@@ -13,19 +13,36 @@ module Hosty
13
13
  private
14
14
 
15
15
  def parse(str, &block)
16
- content(str).each_line do |l|
17
- columns = l.split
18
- next unless columns[0].local_address?
19
-
20
- if columns.last.port_number?
21
- yield servers: columns[1..-2], port: columns.last.port_number
22
- end
23
- end
16
+ str.each_line {|l| new(l).parse &block }
24
17
  end
18
+ end
25
19
 
26
- def content(raw)
27
- raw.skip_comment_lines.shorten_port_definitions
28
- end
20
+
21
+ def initialize(line)
22
+ @line = line
23
+ end
24
+
25
+ def parse(&block)
26
+ return unless content
27
+ yield content
28
+ end
29
+
30
+
31
+ private
32
+
33
+ def content
34
+ return @content if @content
35
+
36
+ columns = @line.split
37
+ return unless columns[0].local_address?
38
+
39
+ mark_index = columns.index('#')
40
+ return unless mark_index
41
+ return unless columns[mark_index+1] && columns[mark_index+1].port_number?
42
+
43
+ @content = {servers: columns[1..mark_index-1],
44
+ port: columns[mark_index+1].port_number,
45
+ options: columns[mark_index+2..-1]}
29
46
  end
30
47
  end
31
48
  end
@@ -4,14 +4,6 @@ module PortableString
4
4
  self == '127.0.0.1' || self == '::1'
5
5
  end
6
6
 
7
- def skip_comment_lines
8
- gsub(/^ *#.*\n/, '')
9
- end
10
-
11
- def shorten_port_definitions
12
- gsub(/# *(:\d+).*/) { $1 }
13
- end
14
-
15
7
  def port_number?
16
8
  port_number != nil
17
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hosty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shintaro Kojima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-01 00:00:00.000000000 Z
11
+ date: 2016-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-reverse-proxy
@@ -93,7 +93,6 @@ files:
93
93
  - hosty.gemspec
94
94
  - lib/hosty.rb
95
95
  - lib/hosty/hosts.rb
96
- - lib/hosty/scheme_detectable.rb
97
96
  - lib/hosty/virtual_hostable.rb
98
97
  - lib/portable_string.rb
99
98
  homepage: https://github.com/codeout/hosty
@@ -120,4 +119,3 @@ signing_key:
120
119
  specification_version: 4
121
120
  summary: "/etc/hosts based tiny reverse proxy."
122
121
  test_files: []
123
- has_rdoc:
@@ -1,13 +0,0 @@
1
- module Hosty
2
- module SchemeDetectable
3
- def url
4
- original = super
5
-
6
- if original[0..1] == '//'
7
- "#{env['rack.url_scheme']}:#{original}"
8
- else
9
- original
10
- end
11
- end
12
- end
13
- end