8000 GitHub - markwainwright/log-server: HTTP/HTTPS/TCP debug server that logs incoming requests in a human-readable way, and allows response behaviour to be customized
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

HTTP/HTTPS/TCP debug server that logs incoming requests in a human-readable way, and allows response behaviour to be customized

License

Notifications You must be signed in to change notification settings

markwainwright/log-server

Repository files navigation

log-server

A Node.js HTTP, HTTPS, or TCP server that:

  • logs incoming connections and requests in a readable way
  • allows response behaviour to be customized per request (see below)

Screenshot

The second column is a counter of TCP connections, making it easier to reason about which data came in over which connection.

Install

npm ci

Enable HTTPS support (optional)

  1. Install mkcert

  2. Create local CA:

    mkcert -install
  3. Create a certificate:

    cd certs
    mkcert localhost 127.0.0.1

Run

npm start -- [http|https|tcp] [port]
  • Mode defaults to http
  • Port defaults to 8080 in http mode, 8443 in https mode, or 4444 in tcp mode

Docker

HTTPS_PORT=443 docker compose run log-server-https

Customizing response behaviour

http and https modes

Request query parameter Response behaviour
?status={code} Set response status code
?header={name}:{value} Add response header. Can be specified multiple times to add multiple headers.
?delay-headers={duration} Delay (in milliseconds) before sending response headers
?delay-body={duration} Delay (in milliseconds) before sending response body
?body={message} Set response body
?echo Send response body equal to request body, chunkwise
Note: delay-headers and delay-body are ignored when this is enabled

Also supports compressed responses (br, gzip, deflate) according to Accept-Encoding request header.

e.g.

$ curl -i "http://localhost:8080/?delay-headers=2000&delay-body=1000&status=503&body=Oh%20no!"

tcp mode

Each newline-separated command will be queued and executed in order:

Command Behaviour
sleep :duration Sleep for :duration milliseconds before running the next command
print :message Send :message back to the client
fin Close the connection
rst Forcibly reset the connection

e.g.

$ printf "print hello\nsleep 2000\nprint  world\nsleep 1000\nfin" | nc localhost 4444

Development

Run and restart when files change:

npm run start:watch

Check types:

npm run check

Build to dist/:

npm run build

Testing

Enable HTTPS server tests:

export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"

Run tests:

npm test

Run tests and watch for changes:

npm run test:watch

Run tests, generate coverage report, and exit with non-zero status if coverage is below 100%:

npm run test:coverage

About

HTTP/HTTPS/TCP debug server that logs incoming requests in a human-readable way, and allows response behaviour to be customized

Resources

License

Stars

Watchers

Forks

0