How to write HTTP proxy caching in Perl?

I intend to write a simple HTTP proxy in Perl using HTTP :: Proxy . It’s clear to me that the main task is to create a proxy server and basic filters, and more. But I can’t understand how to manually force a file through the cache.

Basically, the scenario is that I run this proxy server on computer A. The user on computer B accesses the network using this proxy. Now this proxy will act only as a passage for all B requests until it requests a specific URL (file, say http://abc.com/file.zip ). I need to intercept this request, and instead of allowing it to download the actual .zip file, give it an already downloaded file, which I manually saved on computer A.

Also note that I may not have a web server running on computer A, so I cannot just redirect the URL, I need to serve it from the cache.

Any pointers to this would be appreciated. Thanks

Edit: additional information. I started using HTTP :: Daemon and LWP :: UserAgent in combination instead of HTTP :: Proxy So far I have successfully intercepted all requests and then look at the headers for the URL. If there is no specific file name, I simply pass the request to the actual destination using LWP: UserAgent (simple_request) and return the response to the original sender using send_response. If I find the file name, I will no longer redirect the request, instead I try to serve my file using the send_file_response method. The problem is that all other requests are working fine, and comp B is able to browse the network, but when it tries to download this file, it just waits for an answer. About using squid, this is not an option for me to install squid on these machines.

+4
source share
2 answers

Isn't it better to use Squid for something like this?

+3
source

I think from a distance we can only guess while send_file_response is not working. I would recommend

  • read and understand the documentation for the modules and methods that you use

  • register an action somehow on a proxy server (start, end)

  • Track communication between client B and the proxy server.

+1
source

All Articles