• Stars
    star
    609
  • Rank 73,614 (Top 2 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Docker image that echoes request data as JSON; listens on HTTP/S, useful for debugging.

pulls Docker Image Version (latest semver) GitHub Workflow Status

mendhak/http-https-echo is a Docker image that can echo various HTTP request properties back to client in the response, as well as in the Docker container logs. It comes with various options that can manipulate the response output, see the table of contents for a full list.

browser

The image is available on Docker Hub: mendhak/http-https-echo:30
The image is available on Github Container Registry: ghcr.io/mendhak/http-https-echo:30

Please do not use the :latest tag as it will break without warning, use a specific version instead.

This image is executed as non root by default and is fully compliant with Kubernetes or Openshift deployment.

Basic Usage

Run with Docker

docker run -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:30

Or run with Docker Compose

docker-compose up

Then, issue a request via your browser or curl, and watch the response, as well as container log output.

curl -k -X PUT -H "Arbitrary:Header" -d aaa=bbb https://localhost:8443/hello-world

Choose your ports

You can choose a different internal port instead of 8080 and 8443 with the HTTP_PORT and HTTPS_PORT environment variables.

In this example I'm setting http to listen on 8888, and https to listen on 9999.

 docker run -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8080:8888 -p 8443:9999 --rm -t mendhak/http-https-echo:30

With docker compose, this would be:

my-http-listener:
    image: mendhak/http-https-echo:30
    environment:
        - HTTP_PORT=8888
        - HTTPS_PORT=9999
    ports:
        - "8080:8888"
        - "8443:9999"

Use your own certificates

The certificates are at /app/fullchain.pem and /app/privkey.pem.

You can use volume mounting to substitute the certificate and private key with your own.

my-http-listener:
    image: mendhak/http-https-echo:30
    ports:
        - "8080:8080"
        - "8443:8443"
    volumes:
        - /etc/ssl/certs/ssl-cert-snakeoil.pem:/app/fullchain.pem
        - /etc/ssl/private/ssl-cert-snakeoil.key:/app/privkey.pem

You can use the environment variables HTTPS_CERT_FILE and HTTPS_KEY_FILE to define the location of existing certificate and private key inside container.

Decode JWT header

If you specify the header that contains the JWT, the echo output will contain the decoded JWT. Use the JWT_HEADER environment variable for this.

docker run -e JWT_HEADER=Authentication -p 8080:8080 -p 8443:8443 --rm -it mendhak/http-https-echo:30

Now make your request with Authentication: eyJ... header (it should also work with the Authentication: Bearer eyJ... schema too):

 curl -k -H "Authentication: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" http://localhost:8080/

And in the output you should see a jwt section.

Disable ExpressJS log lines

In the log output set the environment variable DISABLE_REQUEST_LOGS to true, to disable the specific ExpressJS request log lines. The ones like ::ffff:172.17.0.1 - - [03/Jan/2022:21:31:51 +0000] "GET /xyz HTTP/1.1" 200 423 "-" "curl/7.68.0". The JSON output will still appear.

docker run --rm -e DISABLE_REQUEST_LOGS=true --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:30

Do not log specific path

Set the environment variable LOG_IGNORE_PATH to a path you would like to exclude from verbose logging to stdout. This can help reduce noise from healthchecks in orchestration/infrastructure like Swarm, Kubernetes, ALBs, etc.

 docker run -e LOG_IGNORE_PATH=/ping -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:30

With docker compose, this would be:

my-http-listener:
    image: mendhak/http-https-echo:30
    environment:
        - LOG_IGNORE_PATH=/ping
    ports:
        - "8080:8080"
        - "8443:8443"

JSON payloads and JSON output

If you submit a JSON payload in the body of the request, with Content-Type: application/json, then the response will contain the escaped JSON as well.

For example,

curl -X POST -H "Content-Type: application/json" -d '{"a":"b"}' http://localhost:8080/

Will contain a json property in the response/output.

    ...
    "xhr": false,
    "connection": {},
    "json": {
        "a": "b"
    }
}

No newlines

You can disable new lines in the log output by setting the environment variable LOG_WITHOUT_NEWLINE. For example,

docker run -e LOG_WITHOUT_NEWLINE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:30

Send an empty response

You can disable the JSON output in the response by setting the environment variable ECHO_BACK_TO_CLIENT. For example,

docker run -e ECHO_BACK_TO_CLIENT=false -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:30

Custom status code

Use x-set-response-status-code to set a custom status code.

You can send it as a header:

curl -v -H "x-set-response-status-code: 401" http://localhost:8080/

You can send it as a querystring parameter:

curl -v http://localhost:8080/some/path?x-set-response-status-code=401

That will cause the reponse status code to be:

 HTTP/1.1 401 Unauthorized

Set response Content-Type

Use x-set-response-content-type to set the Content-Type of the response.

You can send it as a header:

curl -H "X-Set-Response-Content-Type: text/plain" -kv https://localhost:8443/

You can send it as a querystring parameter:

curl  -kv https://localhost:8443/path?x-set-response-content-type=text/plain

This will cause the response content type to be:

< Content-Type: text/plain; charset=utf-8

Add a delay before response

Use x-set-response-delay-ms to set a custom delay in milliseconds. This will allow you to simulate slow responses.

You can send it as a header:

curl -v -H "x-set-response-delay-ms: 6000" http://localhost:8080/

You can send it as a querystring parameter:

curl -v http://localhost:8080/some/path?x-set-response-delay-ms=6000

Only return body in the response

Use the querystring parameter, response_body_only=true to get just the request body in the response, none of the associated metadata.

curl -s -k -X POST -d 'cauliflower' http://localhost:8080/a/b/c?response_body_only=true

The output will be 'cauliflower'.

Include environment variables in the response

You can have environment variables (that are visible to the echo server's process) added to the response body. Because this could contain sensitive information, it is not a default behavior.

Pass the ECHO_INCLUDE_ENV_VARS=1 environment variable in.

docker run -d --rm -e ECHO_INCLUDE_ENV_VARS=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:30

Then do a normal request via curl or browser, and you will see the env property in the response body.

Client certificate details (mTLS) in the response

To get client certificate details in the response body, start the container with MTLS_ENABLE=1 environment variable. When passing a client certificate, the details about that certificate can be echoed back in the response body. The client certificate will not be validated.

For example, invoke using curl, passing a certificate and key.

curl -k --cert cert.pem --key privkey.pem  https://localhost:8443/

The response body will contain details about the client certificate passed in.

If you browse to https://localhost:8443/ in Firefox, you won't get prompted to supply a client certificate unless you have an imported certificate by the same issuer as the server. If you need browser prompting to work, you'll need to follow the 'use your own certificates' section. Firefox needs the imported certificate to be in a PKCS12 format, so if you have a certificate and key already, you can combine them using

openssl pkcs12 -export -in cert.pem -inkey privkey.pem -out certpkcs12.pfx

Output

Curl output

curl

docker logs output

dockerlogs

Building

docker build -t mendhak/http-https-echo .

Run some tests to make sure features are working as expected.

./tests.sh

To create a new image on Docker Hub, I need to create a tag and push it.

git tag -s 16
git push --tags

Changelog

See the changelog

More Repositories

1

gpslogger

📡 Lightweight GPS Logging Application For Android.
Java
1,945
star
2

angular-intro.js

AngularJS directives for intro.js
JavaScript
503
star
3

waveshare-epaper-display

At-a-glance dashboard for Raspberry Pi with a Waveshare ePaper 7.5 Inch HAT. Date/Time, Weather, Alerts, Google/Outlook Calendar
Python
442
star
4

angular-performance

Directives for measuring and reporting perceived page performance
JavaScript
99
star
5

Airflow-MS-Teams-Operator

Airflow operator that can send messages to MS Teams
Python
78
star
6

teamcity-stash

TeamCity - Stash integration. Plugin for TeamCity which updates Stash with build statuses
Java
54
star
7

keepass-and-keeagent-setup

Security setup instructions for using KeePass with KeeAgent for SSH keypairs
47
star
8

grub-reboot-picker

Helps with dual booting. Ubuntu tray application to reboot into different OSes or UEFI/BIOS
Python
46
star
9

eleventy-satisfactory

Content-first eleventy blog template with basic layout and various features
JavaScript
21
star
10

docker-udp-listener

Python
18
star
11

Gradle-Travis-Colored-Output

Gradle script plugin which formats test output in a slightly colorful way (made for Travis CI but works in terminal)
16
star
12

xbox-controller-off

Shutdown script for XBox Wireless Controller for PCs
C#
15
star
13

Conscrypt-Provider

Conscrypt Provider app, which can be included from other applications (WIP)
Kotlin
13
star
14

trivy-template-output-to-sonarqube

Attempt at getting a Trivy output into Sonarqube's generic issue format
Smarty
13
star
15

selenium-grid-ecs

Selenium Grid in ECS using Fargate Spot Containers
HCL
13
star
16

Codeplex-Issues-Importer

This script imports issues (work items) from a Codeplex project into your github project
Python
11
star
17

teamcity-graphite

Teamcity plugin which sends various build, code and test metrics to Graphite.
Java
10
star
18

SeenFromSpace

A 'live' earth wallpaper which includes day/night phases, night lights, clouds and satellites in different projections
Python
10
star
19

gradle-crowdin-plugin

Build task plugin for downloading and uploading translations from Crowdin.com
Groovy
10
star
20

node-hashcat

hash, concat, minify, replace
JavaScript
9
star
21

bitbucket-all-pull-requests

Plugin to show all pull requests in Bitbucket Server.
Java
8
star
22

llm-cli-helper

CLI helper tool to lookup commands based on a description
Python
8
star
23

googledocs-upload-sample

Android sample code to authorize with OAuth2, upload a doc and update it.
Java
8
star
24

Kindle-Time-and-Weather

Time and Weather display for Kindle
Python
7
star
25

docker-openvpn-adblock

Docker containers setup with OpenVPN on TCP and UDP, with adblocking dnsmasq
Shell
6
star
26

docker-calibre-web-cloudflared

Example setup of a public facing Calibre Web server exposed through Cloudflare Tunnel
Python
6
star
27

Crowdin-Android-Importer

Python script to download translated language files from Crowdin.net and write to Android Project
Python
6
star
28

automated-wsl-dev-setup

Scripts to automate WSL, Ubuntu, Docker, Permissions/Tweaks setup
PowerShell
5
star
29

calibre-gdrive-fix

Script to fix broken Calibre paths caused by Google Drive
Python
5
star
30

aismapping

Places AIVDM NMEA data on Google Maps
Python
4
star
31

rpi-internet-radio

Internet radio using breadboard, mpc and mpd
Python
4
star
32

noodles

Instant Noodles 🍜 for the office (no cooking). Ratings and reviews.
HTML
3
star
33

Gradle-Github-Colored-Output

Colored test output for Github Actions when using Gradle
3
star
34

docker-arm32v6-influxdb

Influxdb image for Raspberry Pi Zero (ARM32v6)
Dockerfile
3
star
35

gpstracka

(Mirror) Windows Mobile 6.5 GPS Logging application
C#
3
star
36

mendhak.github.io

JavaScript
3
star
37

teambuildtray

Mirror for Team Build Tray
C#
2
star
38

raspberrypi-systeminfo

Python web page to display basic Raspberry Pi system info
Python
2
star
39

rhythmbox-gmusic-sync

Plugin to sync metadata from Rhythmbox to Google Music.
Python
2
star
40

gpsmapper

Java
2
star
41

docker-arm32v6-chronograf

Chronograf Docker image for Raspberry Pi Zero (ARM32v6)
Dockerfile
2
star
42

flickrsignature

Flickr signature generator with dynamic URLs. Currently on http://flkr.me
Python
2
star
43

firefox-flickr-new-tab

Firefox New Tab replacement, showcase mendhak photos from Flickr.
JavaScript
2
star
44

aws-elb-logster

Logster module for AWS Elastic Load Balancer access logs
Python
2
star
45

docs.fleetsearch.apiary.io

1
star
46

utils

Shell
1
star
47

angular-dynamic-configuration-with-auth0

Angular application. With dynamic configuration loaded from an API call. With Auth0 integration secured API requests.
TypeScript
1
star
48

flickrapi

Simple Python library for basic flickr method calls
Python
1
star
49

docker-unprivileged

WIP: Collection of unprivileged Docker samples for different languages and tools
1
star
50

expandable-textview-in-expandable-listview-problem

Demo code for https://github.com/Manabu-GT/ExpandableTextView/issues/25
Java
1
star
51

API-Gateway-Self-Hosted-Documentation

Sample repo for self hosted API Gateway documentation
HCL
1
star
52

javamail-android

[Mirror] Automatically exported from code.google.com/p/javamail-android
Java
1
star
53

docs.flightinternal.apiary.io

1
star
54

wintersmith-testing

CSS
1
star
55

android-gradle-test-sample

Sample test project created for http://stackoverflow.com/questions/23046259/is-there-a-way-to-only-run-a-specific-set-of-tests-in-an-android-gradle-project
Shell
1
star
56

curiosityfeeds

Google App Engine project for MSL Curiosity feeds
Python
1
star
57

hammer-api

1
star
58

gpslogger-support-files

Shell
1
star
59

android-file-dialog

Fork of original android-file-dialog from https://code.google.com/p/android-file-dialog
Java
1
star
60

GSF-archive

Bintray mirror for https://bintray.com/mendhak/maven/gpslogger-support-files
1
star
61

smashtest-tutorial

Sample repo for the writeup at
1
star
62

AskUbuntu-Dark-Theme

CSS
1
star
63

flickrbackground

View flickr photos on any color/magic background, or full browser width.
JavaScript
1
star
64

docker-spark-experimental

Experimental Spark master and worker with spark-shell and pyspark
1
star
65

Sheepy-Horn-Old

Productivity tool to assist with joke telling by playing the 'wah wah waah' sound.
Java
1
star
66

automated-wsl2-dev-setup

PowerShell
1
star
67

flickrsig.net

.NET version of flickrsignature - very old
JavaScript
1
star
68

steam-github-profile-status

Set your Github profile status with the game currently being played on Steam. Available as Docker image, Github Action or script.
JavaScript
1
star
69

buildbunny

Mirror of TeamCity Nabaztag plugin
Java
1
star