All Projects → eexit → mirror-http-server

eexit / mirror-http-server

Licence: MIT license
A dummy HTTP server that responds whatever you told it to

Programming Languages

javascript
184084 projects - #8 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to mirror-http-server

Proxy.py
⚡⚡⚡Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging
Stars: ✭ 1,291 (+3588.57%)
Mutual labels:  docker-container, http-server
docker-iot-dashboard
A complete IoT server for LoRaWAN IoT projects: node-red + influxdb + grafana + ssl + let's encrypt using docker-compose.
Stars: ✭ 79 (+125.71%)
Mutual labels:  docker-container
alpine-qbittorrent-openvpn
qBittorrent docker container with OpenVPN client running as unprivileged user on alpine linux
Stars: ✭ 230 (+557.14%)
Mutual labels:  docker-container
wine
A lightweight and flexible framework to help build elegant web API
Stars: ✭ 39 (+11.43%)
Mutual labels:  http-server
play-docker-aws-tutorial
101 tutorial: How to deploy Play application to Amazon Lightsail (AWS) using Docker
Stars: ✭ 25 (-28.57%)
Mutual labels:  docker-container
pyrex
Seamless container setup for developing with OpenEmbedded/Yocto Project
Stars: ✭ 27 (-22.86%)
Mutual labels:  docker-container
docker-tutorial
2DAW Tutorial de Docker para el desarrollo avanzado de código y despliegue de aplicaciones con distintos ejemplos prácticos. Aprende a usar Docker Files y Docker Compose.
Stars: ✭ 26 (-25.71%)
Mutual labels:  docker-container
docker-nginx-mainline
Devilbox's Nginx mainline (based on official Nginx Docker) [multi-arch]
Stars: ✭ 15 (-57.14%)
Mutual labels:  docker-container
docker-compose-laravel
A Docker Compose setup for Laravel projects.
Stars: ✭ 23 (-34.29%)
Mutual labels:  docker-container
wordvector be
Web服务:使用腾讯 800 万词向量模型和 spotify annoy 引擎得到相似关键词
Stars: ✭ 92 (+162.86%)
Mutual labels:  http-server
ws-qvh
Server for streaming the screen of iOS devices over WebSocket.
Stars: ✭ 17 (-51.43%)
Mutual labels:  mirroring
docker-pivpn
A secure docker container that sets up PiVPN in a virtual environment.
Stars: ✭ 82 (+134.29%)
Mutual labels:  docker-container
nanoinit
A small, proper, init process for docker containers.
Stars: ✭ 43 (+22.86%)
Mutual labels:  docker-container
matador
Take your appclication by the horns
Stars: ✭ 59 (+68.57%)
Mutual labels:  http-server
WebServer
High-performance multi-threaded tcp network server in c++11
Stars: ✭ 58 (+65.71%)
Mutual labels:  http-server
cpp-rest-api
RESTFul Web service by C++, implemented basic REST endpoints and RESTVerbs (GET,POST,PUT,DELETE).
Stars: ✭ 13 (-62.86%)
Mutual labels:  http-server
ModelicaInAction
Modelica In Action
Stars: ✭ 39 (+11.43%)
Mutual labels:  docker-container
HttpServerLite
TCP-based simple HTTP and HTTPS server, written in C#.
Stars: ✭ 44 (+25.71%)
Mutual labels:  http-server
backend-server
📠 The backend of the Fairfield Programming Association website.
Stars: ✭ 26 (-25.71%)
Mutual labels:  http-server
Jarvis
APL-based web service framework supporting JSON or REST
Stars: ✭ 17 (-51.43%)
Mutual labels:  http-server

logo

Mirror HTTP Server DockerHub Firebase function

A dummy HTTP server that responds whatever you told it to.

Testing URL: https://mirror-http-server.web.app

Built to play with HTTP or test your API. Make a HTTP call to the dummy server with the specified headers you want the server responds with.

Usage

Pull the Docker container:

docker pull eexit/mirror-http-server

Start the container:

$ docker run -itp 8080:8080 eexit/mirror-http-server
2015-11-05T20:59:57.353Z]  INFO: mirror-http-server/17 on ccc867df5980: Listening on http://0.0.0.0:8080

For this README examples, I use the great HTTPie tool.

Send request against it:

http :8080
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 0
Date: Wed, 13 Mar 2019 12:38:07 GMT
X-Powered-By: Express

You can use any HTTP verbs with any path, any request body and any header.

Server behavioural request headers

You can change the server response code and body by setting specific X-Mirror-* headers to your request.

X-Mirror-Code

Change the server response status code.

Examples that simulates a 301 redirection and a Content-Type change:

http :8080 \
    X-Mirror-Code:301 \
    X-Mirror-Location:http://www.eexit.net \
    X-Mirror-Content-Type:"text/plain; charset=ISO-8859-1"
HTTP/1.1 301 Moved Permanently
Connection: keep-alive
Content-Length: 0
Content-Type: text/plain; charset=ISO-8859-1
Date: Wed, 13 Mar 2019 12:41:35 GMT
Location: http://www.eexit.net
X-Powered-By: Express

If you add the --follow option, it will output my website HTML source.

If you check the container logs:

[2019-03-13T12:41:35.567Z]  INFO: mirror-http-server/18 on f9c1a773d75a:
    request: {
      "ip": "172.17.0.1",
      "ips": [],
      "method": "GET",
      "url": "/",
      "headers": {
        "host": "localhost",
        "user-agent": "HTTPie/1.0.2",
        "accept-encoding": "gzip, deflate",
        "accept": "*/*",
        "connection": "keep-alive",
        "x-mirror-code": "301",
        "x-mirror-location": "http://www.eexit.net",
        "x-mirror-content-type": "text/plain; charset=ISO-8859-1"
      },
      "body": {}
    }

X-Mirror-Delay

If you need to test timeouts or errors handling like 503 HTTP responses, you can pass the X-Mirror-Delay header with a number in milliseconds before the server responds.

time http :8080 X-Mirror-Code:503 X-Mirror-Delay:2000
HTTP/1.1 503 Service Unavailable
Connection: keep-alive
Content-Length: 0
Date: Fri, 20 May 2022 09:52:04 GMT
Keep-Alive: timeout=5
X-Powered-By: Express



http :8080 X-Mirror-Code:503 X-Mirror-Delay:2000  0.12s user 0.03s system 7% cpu 2.163 total

X-Mirror-Request

If you can't access to the container log or want to exploit what's logged under the hood, set the X-Mirror-Request to receive the logged entry (as JSON):

$ http POST :80/resource \
    X-Mirror-Code:201 \
    X-Mirror-Request:true \
    key1=value1 key2=value2
HTTP/1.1 201 Created
Connection: keep-alive
Content-Length: 371
Content-Type: application/json; charset=utf-8
Date: Wed, 13 Mar 2019 12:43:02 GMT
ETag: W/"173-rgXpQ/N7aKeAq+URc1y3vQypNZk"
X-Powered-By: Express

{
    "request": {
        "body": {
            "key1": "value1",
            "key2": "value2"
        },
        "headers": {
            "accept": "application/json, */*",
            "accept-encoding": "gzip, deflate",
            "connection": "keep-alive",
            "content-length": "36",
            "content-type": "application/json",
            "host": "localhost",
            "user-agent": "HTTPie/1.0.2",
            "x-mirror-code": "201",
            "x-mirror-request": "true"
        },
        "ip": "172.17.0.1",
        "ips": [],
        "method": "POST",
        "url": "/resource"
    }
}

Note: if you don't specify the true value for the header, it'll ignored.

X-Mirror-Body

Instead, if you wish the dummy server to return you the body you sent to it, set the X-Mirror-Body header.

Note: the X-Mirror-Request header will override X-Mirror-Body header.

$ http PUT :80/resource \
    X-Mirror-Code:400 \
    X-Mirror-Body:true \
    key1=value1 key2=value2
HTTP/1.1 400 Bad Request
Connection: keep-alive
Content-Length: 33
Content-Type: application/json; charset=utf-8
Date: Wed, 13 Mar 2019 12:43:45 GMT
ETag: W/"21-SWsq4vawbQc/koBuf3CC1L6ssws"
X-Powered-By: Express

{
    "key1": "value1",
    "key2": "value2"
}

Note: if you don't specify the true value for the header, it'll ignored.

Works with any headers

Aside to the previous three special headers, you can set your wanted response header by prepending your header name by X-Mirror-.

In the request:

Content-Type: application/json
X-Mirror-Content-Type: text/html

You'll get in your response:

Content-Type: text/html

You can even override Express headers or any other default header:

X-Mirror-X-Powered-By: eexit-engine
X-Mirror-Date: some date

Will turn into:

X-Powered-By: eexit-engine
Date: some date

Development

You can either use Docker to run the server locally or emulate the function using Firebase CLI:

In one terminal, run this command:

firebase emulators:start

In another terminal, test it:

http http://localhost:5001/mirror-http-server/us-central1/mirror X-Mirror-Body:true message="Hello world\!"
HTTP/1.1 200 OK
connection: keep-alive
content-length: 26
content-type: application/json; charset=utf-8
date: Sun, 06 Nov 2022 10:56:21 GMT
etag: W/"1a-T7vCLEZV7pLSyUzkr9XBdG32YU8"
keep-alive: timeout=5
x-powered-by: Express

{
    "message": "Hello world!"
}

Deployment

This service is host as Google Clound Platform Cloud Function.

firebase deploy --only functions

Todo

  • Functional testing
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].