Class: Net::HTTP
- Inherits:
-
Protocol
- Object
- Protocol
- Net::HTTP
- Defined in:
- lib/rb-gae-support/net_http.rb
Overview
Monkey Patching bundled Net::HTTP Library for java.new.URLConnection
Instance Attribute Summary collapse
-
#ca_file ⇒ Object
Override ssl context accessors TODO - check what we can implement.
-
#ca_path ⇒ Object
Override ssl context accessors TODO - check what we can implement.
-
#cert ⇒ Object
Override ssl context accessors TODO - check what we can implement.
-
#cert_store ⇒ Object
Override ssl context accessors TODO - check what we can implement.
-
#key ⇒ Object
Override ssl context accessors TODO - check what we can implement.
-
#verify_callback ⇒ Object
Override ssl context accessors TODO - check what we can implement.
-
#verify_depth ⇒ Object
Override ssl context accessors TODO - check what we can implement.
-
#verify_mode ⇒ Object
Override ssl context accessors TODO - check what we can implement.
Class Method Summary collapse
-
.new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil) ⇒ Object
Creates an instance.
Instance Method Summary collapse
-
#initialize(address, port = nil) ⇒ HTTP
constructor
Contructor - saves address and port.
-
#request(req, body = nil, &block) ⇒ Object
Actual request.
-
#started? ⇒ Boolean
We are always started.
-
#use_ssl=(flag) ⇒ Object
Avoids OpenSSL calls, sets the use SSL value which is checked when generating the URL.
Constructor Details
Instance Attribute Details
#ca_file ⇒ Object
Override ssl context accessors TODO - check what we can implement
81 82 83 |
# File 'lib/rb-gae-support/net_http.rb', line 81 def ca_file @ca_file end |
#ca_path ⇒ Object
Override ssl context accessors TODO - check what we can implement
81 82 83 |
# File 'lib/rb-gae-support/net_http.rb', line 81 def ca_path @ca_path end |
#cert ⇒ Object
Override ssl context accessors TODO - check what we can implement
81 82 83 |
# File 'lib/rb-gae-support/net_http.rb', line 81 def cert @cert end |
#cert_store ⇒ Object
Override ssl context accessors TODO - check what we can implement
81 82 83 |
# File 'lib/rb-gae-support/net_http.rb', line 81 def cert_store @cert_store end |
#key ⇒ Object
Override ssl context accessors TODO - check what we can implement
81 82 83 |
# File 'lib/rb-gae-support/net_http.rb', line 81 def key @key end |
#verify_callback ⇒ Object
Override ssl context accessors TODO - check what we can implement
81 82 83 |
# File 'lib/rb-gae-support/net_http.rb', line 81 def verify_callback @verify_callback end |
#verify_depth ⇒ Object
Override ssl context accessors TODO - check what we can implement
81 82 83 |
# File 'lib/rb-gae-support/net_http.rb', line 81 def verify_depth @verify_depth end |
#verify_mode ⇒ Object
Override ssl context accessors TODO - check what we can implement
81 82 83 |
# File 'lib/rb-gae-support/net_http.rb', line 81 def verify_mode @verify_mode end |
Class Method Details
.new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil) ⇒ Object
Creates an instance. Ignores proxy config, not needed
14 15 16 17 |
# File 'lib/rb-gae-support/net_http.rb', line 14 def self.new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil) # ignore proxy - google don't need it. return newobj(address, port) end |
Instance Method Details
#request(req, body = nil, &block) ⇒ Object
Actual request. Forms a URL, and uses a java.net.URLConnection to retrieve the body, which it inserts into a Net::HTTPResponse object. Actual network operation is completed here.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rb-gae-support/net_http.rb', line 29 def request(req, body = nil, &block) url = @use_ssl ? 'https://' : 'http://' + address + req.path jurl = java.net.URL.new(url) urlconn = jurl.openConnection() #puts "METHOD: #{req.method}" #puts "REQ: #{req.to_yaml}" req.each_header do |k,v| urlconn.addRequestProperty(k,v) #puts "#{k}; #{v}" end #p req.header urlconn.setRequestMethod(req.method) if req.method == 'POST' || req.method == 'PUT' urlconn.setDoOutput(true) urlconn.connect() if req.body out=urlconn.getOutputStream() out.write(req.body.to_java_bytes) out.close end end inStream = java.io.InputStreamReader.new(urlconn.getInputStream()) buff = java.io.BufferedReader.new(inStream) result = '' while line = buff.readLine() do result << line end resp = HTTPResponse.new("1.1", urlconn.getResponseCode(), urlconn.getResponseMessage()) resp.body = result resp end |
#started? ⇒ Boolean
We are always started
67 68 69 70 |
# File 'lib/rb-gae-support/net_http.rb', line 67 def started? puts 'started called' true #always started. end |
#use_ssl=(flag) ⇒ Object
Avoids OpenSSL calls, sets the use SSL value which is checked when generating the URL
74 75 76 77 |
# File 'lib/rb-gae-support/net_http.rb', line 74 def use_ssl=(flag) flag = (flag ? true : false) @use_ssl = flag end |