Net::HTTP, inheritance + proxy problem

R

Rikard Lindby

Hi all,

I am trying to create a child class from Net::HTTP and the following
seems to work:
class Connection < Net::HTTP
def initialize(addr, port)
super(addr, port)
end
end
I can now write: conn = Connection.new(addr, port)
instead of: conn = Net::HTTP.new(addr, port)

But what I really would like is to be able to use the Proxy method of
Net::HTTP in initialize.
So that i could use: conn = Connection.new(addr, port, paddr, pport)
instead of: conn = Net::HTTP::proxy(paddr, pprort).new(addr, port)

But I have as of yet no idea how to incorporate the proxy in the
Connection class.
I have tried many, many different approaches but none works.

Something like the following would be what I am after, but it does not
work (of course)
class Connection < Net::HTTP
def initialize(addr, port, paddr=nil, pport=nil)
Proxy(paddr, pport).super(addr, port)
end

end

This must be a very common question but I have not been able to find a
simple answer .
Please help

Best regards
/Rikard
 
J

Jano Svitok

Hi all,

I am trying to create a child class from Net::HTTP and the following
seems to work:
class Connection < Net::HTTP
def initialize(addr, port)
super(addr, port)
end
end
I can now write: conn = Connection.new(addr, port)
instead of: conn = Net::HTTP.new(addr, port)

But what I really would like is to be able to use the Proxy method of
Net::HTTP in initialize.
So that i could use: conn = Connection.new(addr, port, paddr, pport)
instead of: conn = Net::HTTP::proxy(paddr, pprort).new(addr, port)

But I have as of yet no idea how to incorporate the proxy in the
Connection class.
I have tried many, many different approaches but none works.

Something like the following would be what I am after, but it does not
work (of course)
class Connection < Net::HTTP
def initialize(addr, port, paddr=nil, pport=nil)
Proxy(paddr, pport).super(addr, port)
end

end

What about either:

class Connection < Net::Http
def self.create(addr, port, paddr, pport)
Proxy(paddr, pport).new(addr, port)
end
end

or

class Connection
def self.create(..)
Net::Http.Proxy(...).new(...)
end
end

use:

Connection.create(...)

(not tested though)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top