How to write an HTTP1.1 Proxy using Twisted?
Hi all, I have recently started to learn and use Twisted. The first task is to write an HTTP proxy. I found Twisted provides a built-in proxy module described here: http://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#a... It says the server part inherits http.HTTPChannel, while the client part inherits http.HTTPClient. However, as I later find out, *http.HTTPClient is only a HTTP 1.0 client,*which is not enough for my task. I also found there is another class called *twisted.web.client.Agent *which seems to be more advanced than http.HTTPClient and supports HTTP 1.1. Questions: 1. Can twisted.web.client.Agent be used in a Proxy implementation with http.HTTPChannel? Is there any examples? 2. Does http.HTTPChannel support HTTP 1.1? Thanks! Sha
Hi Sha, I'm not sure about HTTPChannel, but Agent definitely supports HTTP/1.1. Supporting it shouldn't be too hard, but I don't know of any examples. Essentially, you just replace the proxy's client bits (which makes responses on behalf of the thing that's connecting to the proxy) with agent calls. I recommend just reading the code; it's what I did when I wrote lvh/minitrue. hth lvh
Thanks. Yes. I am just planning to replace the HTTPClient part in the Proxy implementation with Agent. Not sure if any problems may arise. Thanks! Why would they have both Agent (1.1) and HTTPClient (1.0) as built-in HTTP Client modules? The latter should be removed. Sha On Mon, Jan 27, 2014 at 11:12 AM, Laurens Van Houtven <_@lvh.io> wrote:
Hi Sha,
I'm not sure about HTTPChannel, but Agent definitely supports HTTP/1.1. Supporting it shouldn't be too hard, but I don't know of any examples. Essentially, you just replace the proxy's client bits (which makes responses on behalf of the thing that's connecting to the proxy) with agent calls. I recommend just reading the code; it's what I did when I wrote lvh/minitrue.
hth lvh
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
On Mon, Jan 27, 2014 at 8:23 PM, Sha Hua <huasha1985@gmail.com> wrote:
Why would they have both Agent (1.1) and HTTPClient (1.0) as built-in HTTP Client modules? The latter should be removed.
Backwards compatibilty. Tons of code uses HTTPChannel, including the proxy code you're using. It'd be great if it could be deprecated, but it'll take a while before that's done. Hopefully your contribution of HTTP proxy code using Agent to twisted will help this process forward ;) hth lvh
participants (3)
-
Glyph Lefkowitz
-
Laurens Van Houtven
-
Sha Hua