Sign inSign up

mejatos/request-headers

By mejatos

•Updated about 1 year ago

A simple container that displays HTTP request headers.

Image
Developer tools
0

10K+

mejatos/request-headers repository overview

⁠Flask Request Headers Printer

⁠Overview

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.

⁠Flask Application Code

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)
⁠Features
  • Request Header Display: The application captures HTTP request headers and renders them in a simple HTML list format.
  • Supports GET and POST Methods: It listens for both GET and POST requests at the root endpoint (/).
  • Lightweight and Easy to Use: Built with Flask, this app is easy to run and deploy, especially in containerized environments.

⁠Usage

You can easily pull the image from Docker Hub and run it locally or in your cloud environment.

⁠Steps to Run:
  1. Pull the Docker image from Docker Hub:

    docker pull mejatos/request-headers
    
  2. Run the container:

    docker run -p 80:80 mejatos/request-headers
    
  3. 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.

⁠Example Response

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>

⁠Building the Image Locally

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
⁠Maintainer

This image is maintained by https://github.com/flyingsquirrelcloud/request-headers⁠

Tag summary

Content type

Image

Digest

sha256:0657fa280…

Size

51.5 MB

Last updated

over 1 year ago

docker pull mejatos/request-headers