Python or C ++: hijack http request to change destination

This can be difficult to explain, so I will use an example to illustrate this point.

I would like to be able to capture HTTP requests and (possibly) modify them in my path programmatically using C ++ or Python (preferably Python, since I know this better). Ultimately, I would like to achieve something similar to what web browsers do when serving cached objects.

Example

When a file is downloaded http://www.example.com/image.jpg(from any site), it is saved somewhere in the file system, so the following requests that the user's computer makes to this file (via a browser or wgeton Linux, etc.) will indicate a copy in the file system.

In short, I would like to be able to detect an outgoing request on http://www.example.com/image.jpgand change to something like /tmp/files/image.jpg.

This will become part of the larger research project we are working on.

It's hard for me to explain this, so please let me know if I need to provide more details.

Thank you in advance for your help.

+4
source share
1 answer

The most sensible way to do this is to implement a proxy . Then you can configure the browser to use a proxy server, and each request for resources from the Internet will be redirected to the proxy server.

- Python , (, urllib2). , proxpy, , , .

, , , , . , , , , , : , , .

+3
source

All Articles