hosty 0.0.1 → 0.0.6

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
- SHA1:
3
- metadata.gz: 00869051be7d97f98e4ebc2f562743e6b4ee0c7c
4
- data.tar.gz: 61aec49f9845a4e8c3189ae0c1b833df288061bf
2
+ SHA256:
3
+ metadata.gz: e44b12f715535f0faf2337303d7fb2968487c80e833d7d012a3da68a8ac2f2d9
4
+ data.tar.gz: 927aff95eb4f69528c7a89a7a4f46e212ea480baaaddda4076833c505470de85
5
5
  SHA512:
6
- metadata.gz: c6431644278be6510c1f1328f43d6d7b0ff914a79c2ffd50b7db1fab414906249c9a06c2dd6bd7188f82eea8be19352b4888a1a4fcf195053c48131c560d7fef
7
- data.tar.gz: cb8d1db939a94aead86289586b4bb55402850c53d78e7c5adfa9adb15f5c1898b73f39e688ade8393b8f481920a6d783dd675aa314c2d19d56728789507258c5
6
+ metadata.gz: d560a7d74c707cfc334716b92332df421d84d2cc92eea2420f3c896658bd6725c5f1df2adc28ed4d9bc319770a3badc6226cff9bc0224639967d8ba3ce83471e
7
+ data.tar.gz: ae0200fd4da6f4895f417743d51e3e716bd813ee56fac5cbe7f5829ff6f0bbeec172cbdb21094f8bfae4bcf91dbb09b00091534561b7678301097fe6c872be33
data/.gitignore CHANGED
@@ -7,3 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ # editors
12
+ /.idea/
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Shintaro Kojima
3
+ Copyright (c) 2021 Shintaro Kojima
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -31,16 +31,30 @@ 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
45
59
 
46
- Copyright (c) 2016 Shintaro Kojima. Code released under the [MIT license](LICENSE).
60
+ Copyright (c) 2021 Shintaro Kojima. Code released under the [MIT license](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
@@ -1,9 +1,36 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
4
+ require 'pathname'
3
5
  require 'rack'
4
6
 
7
+ $: << File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
8
+
9
+ require 'hosty'
10
+
11
+
5
12
  config = File.expand_path('../../config.ru', __FILE__)
6
13
 
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
14
+ opts = OptionParser.new do |opts|
15
+ opts.banner = 'hosty: /etc/hosts based tiny reverse proxy'
16
+ opts.define_head 'Usage: hosty [options]'
17
+ opts.separator ''
18
+ opts.separator 'Options:'
19
+
20
+ opts.on '-d', '--debug', 'Turn on debug mode' do
21
+ $HOSTY_DEBUG = true
22
+ end
23
+
24
+ opts.on_tail '-h', '--help', 'Show this message' do
25
+ puts opts
26
+ exit
27
+ end
28
+
29
+ opts.on_tail '-v', '--version', 'Show version' do
30
+ puts Hosty::VERSION
31
+ exit
32
+ end
33
+ end
34
+ opts.parse!
9
35
 
36
+ Rack::Server.start(config: config, Host: '127.0.0.1', Port: 80)
data/hosty.gemspec CHANGED
@@ -1,10 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hosty/version'
4
5
 
5
6
  Gem::Specification.new do |spec|
6
7
  spec.name = "hosty"
7
- spec.version = '0.0.1'
8
+ spec.version = Hosty::VERSION
8
9
  spec.authors = ["Shintaro Kojima"]
9
10
  spec.email = ["goodies@codeout.net"]
10
11
 
@@ -28,10 +29,11 @@ It allows you to manage mappings of local server name and port on /etc/hosts.
28
29
  spec.require_paths = ["lib"]
29
30
 
30
31
  spec.add_runtime_dependency "rack-reverse-proxy"
32
+ spec.add_runtime_dependency "webrick"
31
33
 
32
- spec.add_development_dependency "bundler", "~> 1.11"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "test-unit", "~> 3.0"
34
+ spec.add_development_dependency "bundler"
35
+ spec.add_development_dependency "rake"
36
+ spec.add_development_dependency "test-unit"
35
37
 
36
38
  spec.required_ruby_version = '>= 2.1.0'
37
39
  end
data/lib/hosty.rb CHANGED
@@ -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
data/lib/hosty/hosts.rb CHANGED
@@ -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] && 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
@@ -0,0 +1,3 @@
1
+ module Hosty
2
+ VERSION = '0.0.6'
3
+ end
@@ -1,7 +1,30 @@
1
1
  module Hosty
2
2
  module VirtualHostable
3
+ def proxy
4
+ debug "<= #{env['REQUEST_METHOD']} #{source_request.url}"
5
+
6
+ return app.call(env) if uri.nil?
7
+ return https_redirect if need_https_redirect?
8
+
9
+ setup_request
10
+ setup_response_headers
11
+
12
+ debug " -> #{env['REQUEST_METHOD']} #{uri}"
13
+
14
+ transform_response(rack_response).tap {|t|
15
+ debug " <- #{t[0]}"
16
+ }
17
+ end
18
+
3
19
  def rules
4
20
  super.select {|r| r.options[:vhost] == env['SERVER_NAME'] }
5
21
  end
22
+
23
+
24
+ private
25
+
26
+ def debug(message)
27
+ puts "#{Time.now} #{message}" if $HOSTY_DEBUG
28
+ end
6
29
  end
7
30
  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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shintaro Kojima
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-01 00:00:00.000000000 Z
11
+ date: 2021-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-reverse-proxy
@@ -24,48 +24,62 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webrick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: '1.11'
47
+ version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: '1.11'
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '10.0'
61
+ version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - "~>"
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '10.0'
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: test-unit
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: '3.0'
75
+ version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '3.0'
82
+ version: '0'
69
83
  description: |
70
84
  /etc/hosts based tiny reverse proxy.
71
85
 
@@ -93,13 +107,13 @@ files:
93
107
  - hosty.gemspec
94
108
  - lib/hosty.rb
95
109
  - lib/hosty/hosts.rb
96
- - lib/hosty/scheme_detectable.rb
110
+ - lib/hosty/version.rb
97
111
  - lib/hosty/virtual_hostable.rb
98
112
  - lib/portable_string.rb
99
113
  homepage: https://github.com/codeout/hosty
100
114
  licenses: []
101
115
  metadata: {}
102
- post_install_message:
116
+ post_install_message:
103
117
  rdoc_options: []
104
118
  require_paths:
105
119
  - lib
@@ -114,10 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
128
  - !ruby/object:Gem::Version
115
129
  version: '0'
116
130
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.5.1
119
- signing_key:
131
+ rubygems_version: 3.2.15
132
+ signing_key:
120
133
  specification_version: 4
121
134
  summary: "/etc/hosts based tiny reverse proxy."
122
135
  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