This is an HTTP echo server based on OpenResty, designed to display detailed information about HTTP requests.
When developing and debugging network applications, understanding the details of HTTP requests is crucial. Echo Server provides a simple way to view request headers, request body, environment variables, and other information, helping developers diagnose problems and understand request flows.
- Display detailed request information, including:
- Request method (GET, POST, etc.)
- Request path
- Query parameters
- Request headers
- Request body
- Client IP address
- Display server environment information, including:
- Hostname
- Pod information (if running in a Kubernetes environment)
- Nginx and Lua versions
- Provide a long connection test endpoint (/hang)
docker run -p 8080:80 ghcr.io/echo-server/echo-server:main
The pre-built image supports both ARM and x86 CPU architectures, no need to build it yourself.
- Clone the repository
git clone https://github.com/echo-server/echo-server.git
cd echo-server
- Build the Docker image
docker build -t echo-server .
- Run the container
docker run -p 8080:80 echo-server
Now, Echo Server will be running at http://localhost:8080.
Access the server's root path to view request information:
curl http://localhost:8080
Or use a browser to visit http://localhost:8080
curl -X POST -d "Hello World" http://localhost:8080
curl -H "X-Custom-Header: CustomValue" http://localhost:8080
curl http://localhost:8080/hang
This endpoint keeps the connection open, sending a newline character every 5 seconds.
Echo Server can be deployed in a Kubernetes cluster, and it will automatically display Pod-related information (if environment variables are available).
Using pre-built image:
ghcr.io/echo-server/echo-server:main
Deployment example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo-server
spec:
replicas: 1
selector:
matchLabels:
app: echo-server
template:
metadata:
labels:
app: echo-server
spec:
containers:
- name: echo-server
image: ghcr.io/echo-server/echo-server:main
ports:
- containerPort: 80
env:
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
---
apiVersion: v1
kind: Service
metadata:
name: echo-server
spec:
selector:
app: echo-server
ports:
- port: 80
targetPort: 80
type: ClusterIP
These environment variables will be displayed by the echo server, helping to debug and understand the Pod's runtime environment.
- OpenResty: A high-performance web platform based on Nginx and Lua
- lua-resty-template: Lua template engine
Issues and pull requests are welcome!
Please see the LICENSE file in the project.