# Net::HTTP, inheritance + proxy problem

**URL:** <https://www.ruby-forum.com/t/net-http-inheritance-proxy-problem/110960>\
**Category:** Ruby\
**Created:** [August 1, 2007, 2:29pm UTC](https://www.ruby-forum.com/t/net-http-inheritance-proxy-problem/110960 "2007-08-01T14:29:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rikard\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@Rikard\_L](https://www.ruby-forum.com/u/Rikard_L)\
**Post date:** [August 1, 2007, 2:29pm UTC](https://www.ruby-forum.com/t/net-http-inheritance-proxy-problem/110960/1 "2007-08-01T14:29:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rikard\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@Rikard\_L](https://www.ruby-forum.com/u/Rikard_L)\
**Post date:** [August 2, 2007, 12:13am UTC](https://www.ruby-forum.com/t/net-http-inheritance-proxy-problem/110960/2 "2007-08-02T00:13:34Z")

</div>

On 8/1/07, Rikard L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> instead of: conn = Net::HTTP.new(addr, port)  
> 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)
