tunnels 1.0.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.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tunnels.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ Tunnels
2
+ =======
3
+
4
+ This tunnels https to http.
5
+
6
+ ![image](http://i.imgur.com/5F9tJ.png)
7
+
8
+ Installation
9
+ ------------
10
+
11
+ $ gem install tunnels
12
+
13
+ Run
14
+ ---
15
+
16
+ $ tunnels
17
+
18
+ or
19
+
20
+ $ sudo tunnels
21
+
22
+ Copyright
23
+ ---------
24
+
25
+ Copyright (c) 2012 jugyo, released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/tunnels ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'tunnels'
3
+ Tunnels.run!
data/lib/tunnels.rb ADDED
@@ -0,0 +1,84 @@
1
+ require "tunnels/version"
2
+ require "eventmachine"
3
+
4
+ # most of code is from [thin-glazed](https://github.com/freelancing-god/thin-glazed).
5
+ # Copyright © 2012, Thin::Glazed was a Rails Camp New Zealand project, and is developed and maintained by Pat Allan. It is released under the open MIT Licence.
6
+
7
+ module Tunnels
8
+ def self.run!(host = '127.0.0.1', from = 443, to = 80)
9
+ EventMachine.run do
10
+ EventMachine.start_server(host, from, HttpsProxy, to)
11
+ puts "Ready :)"
12
+ end
13
+ rescue => e
14
+ puts e.message
15
+ puts "Maybe you should run on `sudo`"
16
+ end
17
+
18
+ class HttpClient < EventMachine::Connection
19
+ attr_reader :proxy
20
+
21
+ def initialize(proxy)
22
+ @proxy = proxy
23
+ @connected = EventMachine::DefaultDeferrable.new
24
+ end
25
+
26
+ def connection_completed
27
+ @connected.succeed
28
+ end
29
+
30
+ def receive_data(data)
31
+ proxy.relay_from_client(data)
32
+ end
33
+
34
+ def send(data)
35
+ @connected.callback { send_data data }
36
+ end
37
+
38
+ def unbind
39
+ proxy.unbind_client
40
+ end
41
+ end
42
+
43
+ class HttpProxy < EventMachine::Connection
44
+ attr_reader :client_port
45
+
46
+ def initialize(client_port)
47
+ @client_port = client_port
48
+ end
49
+
50
+ def receive_data(data)
51
+ client.send_data data unless data.nil?
52
+ end
53
+
54
+ def relay_from_client(data)
55
+ send_data data unless data.nil?
56
+ end
57
+
58
+ def unbind
59
+ client.close_connection
60
+ @client = nil
61
+ end
62
+
63
+ def unbind_client
64
+ close_connection_after_writing
65
+ @client = nil
66
+ end
67
+
68
+ private
69
+
70
+ def client
71
+ @client ||= EventMachine.connect '127.0.0.1', client_port, HttpClient, self
72
+ end
73
+ end
74
+
75
+ class HttpsProxy < HttpProxy
76
+ def post_init
77
+ start_tls
78
+ end
79
+
80
+ def receive_data(data)
81
+ super data.gsub(/\r\n\r\n/, "\r\nX_FORWARDED_PROTO: https\r\n\r\n")
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module Tunnels
2
+ VERSION = "1.0.0"
3
+ end
data/tunnels.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tunnels/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tunnels"
7
+ s.version = Tunnels::VERSION
8
+ s.authors = ["jugyo"]
9
+ s.email = ["jugyo.org@gmail.com"]
10
+ s.homepage = "https://github.com/jugyo/tunnels"
11
+ s.summary = %q{https --(--)--> http}
12
+ s.description = %q{tunnel https to http}
13
+
14
+ s.rubyforge_project = "tunnels"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "eventmachine"
24
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tunnels
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jugyo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: eventmachine
16
+ requirement: &70238701544800 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70238701544800
25
+ description: tunnel https to http
26
+ email:
27
+ - jugyo.org@gmail.com
28
+ executables:
29
+ - tunnels
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - bin/tunnels
37
+ - lib/tunnels.rb
38
+ - lib/tunnels/version.rb
39
+ - tunnels.gemspec
40
+ homepage: https://github.com/jugyo/tunnels
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project: tunnels
60
+ rubygems_version: 1.8.10
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: https --(--)--> http
64
+ test_files: []