vendredi 5 janvier 2018

proxy server allows texts but not images

Im trying to make a web proxy in python which is able to get the texts from the main server but not the images. The url http://ift.tt/2CNQMU1 contains a line of text i am able to view in the browser and the url http://ift.tt/2lfoI2a contains a image which i am not able to display in the browser. Im using Google Chrome. Below is my code. (I have hard-coded the hostname of the the image url for this post). Can anyone help me fix the problem.

from socket import *
client= socket(AF_INET, SOCK_STREAM)
proxy_port = 8880
client.bind(("", proxy_port ))
client.listen(10)

while 1:
    client_connection, client_address = CLIENT.accept()
    request = client_connection.recv(102400).decode()

    if request.startswith("GET"):
        try:
            print(request)
            web = socket(AF_INET, SOCK_STREAM)
            web.connect(("images.mid-day.com", 80))
            web.send(request.encode())
            reply = web.recv(102400).decode()
            print(reply)
            client_connection.send(reply.encode())
            web.close()
        except:
            print("illegal req")
client.close()

This is my get request from the browser

Aucun commentaire:

Enregistrer un commentaire