Class: Net::HTTP

Inherits:
Protocol
  • Object
show all
Defined in:
lib/rb-gae-support/net_http.rb

Overview

Monkey Patching bundled Net::HTTP Library for java.new.URLConnection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, port = nil) ⇒ HTTP

Contructor - saves address and port



20
21
22
23
24
# File 'lib/rb-gae-support/net_http.rb', line 20

def initialize(address, port = nil)
  #raise 'got initialize'
  @address = address
  @port    = (port || HTTP.default_port)
end

Instance Attribute Details

#ca_fileObject

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_pathObject

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

#certObject

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_storeObject

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

#keyObject

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_callbackObject

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_depthObject

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_modeObject

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

Returns:

  • (Boolean)


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