Python standard library (http.server) Python
/pixel.gif కు వచ్చే రిక్వెస్ట్లకు empty GIF తో జవాబిచ్చే, Python standard library (http.server) కోసం Python స్నిపెట్. GIF స్టార్టప్లో ఒక్కసారే డీకోడ్ అవుతుంది.
Python standard library (http.server) Python
import base64
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from urllib.parse import urlsplit
GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
class PixelHandler(BaseHTTPRequestHandler):
def do_GET(self):
if urlsplit(self.path).path != "/pixel.gif":
self.send_error(404)
return
self.send_response(200)
self.send_header("Content-Type", "image/gif")
self.send_header("Content-Length", str(len(GIF)))
self.send_header("Cache-Control", "no-store")
self.end_headers()
self.wfile.write(GIF)
ThreadingHTTPServer(("", 8080), PixelHandler).serve_forever()
మేము ఈ స్నిపెట్ను రన్ చేసి, అది తిరిగి ఇచ్చిన బైట్లను పోల్చి చూశాం.
చెక్ చేయండి
curl -sI http://localhost:8080/pixel.gif
అధికారిక సైట్: Python standard library (http.server)