A simple container that displays HTTP request headers.
10K+
This repository contains a simple Python Flask application that listens for HTTP GET and POST requests and prints the request headers in an HTML format. The application is lightweight and designed to run within a Docker container, making it ideal for testing and debugging HTTP headers.
Below is the core Python Flask application code:
from flask import Flask, request
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def print_headers():
headers = request.headers
header_html = "<html><body><h1>Request Headers</h1><ul>"
for header, value in headers.items():
header_html += f"<li><strong>{header}:</strong> {value}</li>"
header_html += "</ul></body></html>"
return header_html, 200
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80)
/).You can easily pull the image from Docker Hub and run it locally or in your cloud environment.
Pull the Docker image from Docker Hub:
docker pull mejatos/request-headers
Run the container:
docker run -p 80:80 mejatos/request-headers
Send a request to the application:
You can use curl, Postman, or a web browser to send an HTTP request:
curl http://localhost
The response will be an HTML page that lists all the request headers received.
After sending a request, the application will respond with an HTML page like this:
<html>
<body>
<h1>Request Headers</h1>
<ul>
<li><strong>Host:</strong> localhost</li>
<li><strong>User-Agent:</strong> curl/7.68.0</li>
<li><strong>Accept:</strong> */*</li>
</ul>
</body>
</html>
If you'd like to build the Docker image yourself, use the following Dockerfile:
# Use official Python runtime as parent image
FROM python:3.11-slim
# Set the working directory in the container
WORKDIR /app
# Copy the current directory contents into the container
COPY . /app
# Install Flask
RUN pip install Flask
# Expose port 80
EXPOSE 80
# Run the application
CMD ["python", "app.py"]
To build and run the image locally:
docker build -t flask-request-headers-printer .
docker run -p 80:80 flask-request-headers-printer
This image is maintained by https://github.com/flyingsquirrelcloud/request-headers
Content type
Image
Digest
sha256:0657fa280…
Size
51.5 MB
Last updated
over 1 year ago
docker pull mejatos/request-headers