Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:37:44+00:00 2026-05-30T20:37:44+00:00

So i’ve looked around at a few things involving writting an HTTP Proxy using

  • 0

So i’ve looked around at a few things involving writting an HTTP Proxy using python and the Twisted framework.

Essentially, like some other questions, I’d like to be able to modify the data that will be sent back to the browser. That is, the browser requests a resource and the proxy will fetch it. Before the resource is returned to the browser, i’d like to be able to modify ANY (HTTP headers AND content) content.

This ( Need help writing a twisted proxy ) was what I initially found. I tried it out, but it didn’t work for me. I also found this ( Python Twisted proxy – how to intercept packets ) which i thought would work, however I can only see the HTTP requests from the browser.

I am looking for any advice. Some thoughts I have are to use the ProxyClient and ProxyRequest classes and override the functions, but I read that the Proxy class itself is a combination of the both.

For those who may ask to see some code, it should be noted that I have worked with only the above two examples. Any help is great.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:37:45+00:00Added an answer on May 30, 2026 at 8:37 pm

    To create ProxyFactory that can modify server response headers, content you could override ProxyClient.handle*() methods:

    from twisted.python import log
    from twisted.web import http, proxy
    
    class ProxyClient(proxy.ProxyClient):
        """Mangle returned header, content here.
    
        Use `self.father` methods to modify request directly.
        """
        def handleHeader(self, key, value):
            # change response header here
            log.msg("Header: %s: %s" % (key, value))
            proxy.ProxyClient.handleHeader(self, key, value)
    
        def handleResponsePart(self, buffer):
            # change response part here
            log.msg("Content: %s" % (buffer[:50],))
            # make all content upper case
            proxy.ProxyClient.handleResponsePart(self, buffer.upper())
    
    class ProxyClientFactory(proxy.ProxyClientFactory):
        protocol = ProxyClient
    
    class ProxyRequest(proxy.ProxyRequest):
        protocols = dict(http=ProxyClientFactory)
    
    class Proxy(proxy.Proxy):
        requestFactory = ProxyRequest
    
    class ProxyFactory(http.HTTPFactory):
        protocol = Proxy
    

    I’ve got this solution by looking at the source of twisted.web.proxy. I don’t know how idiomatic it is.

    To run it as a script or via twistd, add at the end:

    portstr = "tcp:8080:interface=localhost" # serve on localhost:8080
    
    if __name__ == '__main__': # $ python proxy_modify_request.py
        import sys
        from twisted.internet import endpoints, reactor
    
        def shutdown(reason, reactor, stopping=[]):
            """Stop the reactor."""
            if stopping: return
            stopping.append(True)
            if reason:
                log.msg(reason.value)
            reactor.callWhenRunning(reactor.stop)
    
        log.startLogging(sys.stdout)
        endpoint = endpoints.serverFromString(reactor, portstr)
        d = endpoint.listen(ProxyFactory())
        d.addErrback(shutdown, reactor)
        reactor.run()
    else: # $ twistd -ny proxy_modify_request.py
        from twisted.application import service, strports
    
        application = service.Application("proxy_modify_request")
        strports.service(portstr, ProxyFactory()).setServiceParent(application)
    

    Usage

    $ twistd -ny proxy_modify_request.py
    

    In another terminal:

    $ curl -x localhost:8080 http://example.com
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.