Class: SSLGate::HTTPServer
- Inherits:
-
Object
- Object
- SSLGate::HTTPServer
- Defined in:
- lib/ssl_gate/base_gate.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.add_ons ⇒ Object
Returns the value of attribute add_ons.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(config) ⇒ HTTPServer
constructor
A new instance of HTTPServer.
Constructor Details
#initialize(config) ⇒ HTTPServer
Returns a new instance of HTTPServer.
11 12 13 14 15 |
# File 'lib/ssl_gate/base_gate.rb', line 11 def initialize(config) @config = { signals: false, # target: 'http://localhost:9000' }.merge config end |
Class Attribute Details
.add_ons ⇒ Object
Returns the value of attribute add_ons.
7 8 9 |
# File 'lib/ssl_gate/base_gate.rb', line 7 def add_ons @add_ons end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/ssl_gate/base_gate.rb', line 10 def config @config end |
Class Method Details
.start(config) ⇒ Object
42 43 44 45 |
# File 'lib/ssl_gate/base_gate.rb', line 42 def self.start(config) server = new(config) Thin::Server.start (config[:bind_interface] || '0.0.0.0'), config[:bind_port], server.config, server end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ssl_gate/base_gate.rb', line 17 def call(env) r_method = env['REQUEST_METHOD'].downcase.to_sym r_query = env['QUERY_STRING'] r_path = env['REQUEST_PATH'] # input = env['rack.input'] #StringIO env[:target_request_options] ||= { connect_timeout: 20, inactivity_timeout: 20 } puts "head: #{env[:target_get_options][:head] rescue ''}" request = EM::HttpRequest.new @config[:target], env[:target_request_options] http = request.send r_method, (env[:target_get_options] || {}).merge( path: r_path, query: r_query) # body: input puts "#{r_method}: #{r_path} #{r_query}" ready = lambda { headers = http.response_header.map{ |key, val| [key.tr('_', '-'), val] }.to_h headers.delete 'TRANSFER-ENCODING' headers.delete 'CONTENT-ENCODING' headers.delete 'CONTENT-LENGTH' puts "OK: #{headers}" env['async.callback'].call [http.response_header.status, headers, [http.response]] } http.callback { ready.call } http.errback { ready.call } throw :async end |