Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Http connection manipulations

by kazak (Beadle)
on Jan 10, 2012 at 17:16 UTC ( [id://947198]=perlquestion: print w/replies, xml ) Need Help??

kazak has asked for the wisdom of the Perl Monks concerning the following question:

Hi 2 all,and here is a problem. There is system (a perl proxy server + 10 parent-proxies) This proxy listens certain address\port and balances traffic between parents. From time to time some of upstream proxies are down. There are a bunch of scripts (black boxes that can't follow redirects) that must get their requested content. Is there a possibility, in case of a certain response, replace a content that supposed to be returned. I mean for example if response is "404":

Detect this event (Done)

Get initial URI (Done)

Return this content through another proxy ( Almost done)

Write returned content to a certain connection while it's open.

I mean if client that supposed to receive 404 error, came from 111.111.111.111:15000, content requested by this client must be returned through another proxy-parent(roundrobin will take care about "return through another parent" part) and written to a 111.111.111.111:15000 socket. Is that possible, and if possible, then how? Thanks in advance to all monks.

Replies are listed 'Best First'.
Re: Http connection manipulations
by dd-b (Monk) on Jan 10, 2012 at 23:33 UTC

    I'm not sure I understand your structure. The phrase "parent-proxies" isn't clear to me. I don't understand what socket connections exist. Client to proxy to "parent-proxy"? In that case I'd call them "servers"; they're not in any sense proxies.

    Your question looks either trivial or obviously impossible, depending on what the actual structure is. Either the code with the content to return has the open socket from the client, or it doesn't. If it does, just write it there. If it doesn't, no hope. (Possibly by restructuring things completely, it could be made possible.) But my lack of understanding of the structure probably means it's not like this.

      1. custom proxy = perl HTTP::Proxy

      2. Squid used for roundrobin traffic between 10 external proxy servers.

      3. System:

      clients<->HTTP::Proxy<->SQUID<-ROUND_ROBIN->External Proxy servers (Parent-proxies 1...10)

      .

      Problem resides here clients<->HTTP::Proxy

      If one of external parent proxy is dead, repeat request through another external parent proxy. Some clients can't follow redirects, so the solution as (far as I can say, but it's may be wrong) is to return content with LWPUserAgent for example, and write it to the "appropriate" connection (from a client to a custom proxy, it can be identified by port, while it's open). I have a working code it's working for redirection, but since not all clients can follow it I have no choice but try to do this thing.

        1. custom proxy = perl HTTP::Proxy . . . clients<->HTTP::Proxy<->SQUID<-ROUND_ROBIN->External Proxy servers (Pa +rent-proxies 1...10) Problem resides here clients<->HTTP::Proxy

        If I understand your problem (maybe), how do you know which server "SQUID" selects? Second, you now become the single point of failure in your network. Third, Squid is a caching proxy, so if configured correctly, shouldn't it being redirecting to a running server?

        I have never used/configured Squid, but maybe the correct solution is in reconfiguring Squid?

        Good Luck.

        "Well done is better than well said." - Benjamin Franklin

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://947198]
Approved by gman
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found