Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python
/pixel.gif 요청에 빈 GIF로 응답하는 Raw WSGI (Gunicorn, uWSGI, mod_wsgi)용 Python 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.
Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python
import base64
GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
HEADERS = [
("Content-Type", "image/gif"),
("Content-Length", str(len(GIF))),
("Cache-Control", "no-store"),
]
def app(environ, start_response):
if environ["REQUEST_METHOD"] == "GET" and environ["PATH_INFO"] == "/pixel.gif":
start_response("200 OK", HEADERS)
return [GIF]
start_response("404 Not Found", [("Content-Type", "text/plain")])
return [b"Not Found"]
이 스니펫은 실행해 보고, 반환된 바이트를 비교했습니다.
확인
curl -sI http://localhost:8080/pixel.gif
공식 사이트: Raw WSGI (Gunicorn, uWSGI, mod_wsgi)