Sign inSign up

yanickxia/recho

By yanickxia

•Updated almost 2 years ago

Image
0

3.7K

yanickxia/recho repository overview

⁠Rust Echo

inspire by Echo-Server⁠

Available:

Artifact Hub

  • GET / POST / PUT / PATCH / DELETE
  • Request (Query, Body, IPs, Host, Urls...)
  • Request Headers / Response Headers
  • Environment variables
  • Control via Headers/Query
  • Folders and Files
  • Monitoring

⁠Configuration

HTTP & Metrics Server Always Enabled

EnvironmentHelmDefaultDesc
HTTP_PORTconfigmap.http.port80http listen port
HTTP_METRICSconfigmap.metrics.port9091http metrics port
HTTPS_PORTconfigmap.https.port443https listen port
HTTPS_PRIVATE_KEY_FILEconfigmap.https.private_key_fileconfig/key.pemhttps tls private key file
HTTPS_CERTIFICATE_CHAIN_FILEconfigmap.https.certificate_chain_fileconfig/cert.pemhttps tls certificate file
GRPC_PORTconfigmap.grpc.port5001grpc plaintext port
GRPC_TLS_PORTconfigmap.grpc.TLS.port5002grpc tls port
GRPC_TLS_PRIVATE_KEY_FILEconfigmap.grpc.TLS.portconfig/key.pemgrpc tls private key file
GRPC_TLS_CERTIFICATE_CHAIN_FILEconfigmap.grpc.TLS.portconfig/cert.pemgrpc tls certificate file
Module Enable
ENABLE_HOSTconfigmap.enable.hosttruehttp(s)/grpc(tls): return Host info
ENABLE_HTTPconfigmap.enable.httptruehttp(s): return http info
ENABLE_REQUESTconfigmap.enable.requesttruehttp(s): return request info
ENABLE_HEADERconfigmap.enable.headertruehttp(s): return headers
ENABLE_ENVIRONMENTconfigmap.enable.environmenttruehttp(s)/grpc(tls): return env info
ENABLE_FILEconfigmap.enable.filetruehttp(s): support return file
ENABLE_HTTPSconfigmap.enable.httpstrueenable https server
ENABLE_GRPC_TLSconfigmap.enable.grpc_tlstrueenable grpc plaintext server
ENABLE_GRPCconfigmap.enable.grpctrueenable grpc tls server
⁠Custom responses
QueryHeaderContentConditions
?echo_code=X-ECHO-CODEHTTP code 200, 404 ,404-401 or 200-500-301200 <= CODE <= 599
?echo_body=X-ECHO-BODYBody message
?echo_env_body=X-ECHO-ENV-BODYThe key of environment variableEnable environment true
?echo_header=X-ECHO-HEADERResponse Header Lang: en-USEnable header true
?echo_time=X-ECHO-TIMEWait time in ms0 < TIME <= 30s
?echo_file=X-ECHO-FILEPath of Directory or FileEnable file true
⁠Custom HTTP Status Code
➜ curl -I --header 'X-ECHO-CODE: 404' localhost:8080
➜ curl -I localhost:8080/?echo_code=404

HTTP/1.1 404 Not Found
➜ curl -I --header 'X-ECHO-CODE: 404-300' localhost:8080
➜ curl -I localhost:8080/?echo_code=404-300

HTTP/1.1 404 Not Found
HTTP/1.1 300 Multiple Choices
➜ for i in {1..10}
➜ do
➜    curl -I localhost:8080/?echo_code=200-400-500
➜ done

HTTP/1.1 500 Internal Server Error
HTTP/1.1 400 Bad Request
HTTP/1.1 200 OK
HTTP/1.1 500 Internal Server Error
HTTP/1.1 200 OK
HTTP/1.1 500 Internal Server Error
⁠Custom Body
➜ curl --header 'X-ECHO-BODY: amazing' localhost:8080
➜ curl localhost:8080/?echo_body=amazing

"amazing"
⁠Custom Body with Environment variable value
➜ curl --header 'X-ECHO-ENV-BODY: HOSTNAME' localhost:8080
➜ curl localhost:8080/?echo_env_body=HOSTNAME

"c53a9ed79fa2"
➜ for i in {1..10}
➜ do
➜    curl localhost:8080/?echo_env_body=HOSTNAME
➜ done

"c53a9ed79fa2"
"f10c3af61e40"
"c53a9ed79fa2"
"f10c3af61e40"
"c53a9ed79fa2"
⁠Custom Headers
➜ curl --header 'X-ECHO-HEADER: One:1' localhost:8080
➜ curl localhost:8080/?echo_header=One:1

HTTP/1.1 200 OK
One: 1
➜ curl --header 'X-ECHO-HEADER: One:1, Two:2' localhost:8080
➜ curl "localhost:8080/?echo_header=One:1,%20Two:2"

HTTP/1.1 200 OK
One: 1
Two: 2
⁠Custom response latency
➜ curl --header 'X-ECHO-TIME: 5000' localhost:8080
➜ curl "localhost:8080/?echo_time=5000"

⏳... 5000 ms

⁠GRPC

⁠ProtoBuf
FieldDesc
messagerelay same message
delayhow time delay to relay
⁠plaintext
➜ grpcurl -plaintext -use-reflection  -d '{"message": "1234"}' localhost:5001 echo.Echo/Echo
{
  "message": "1234"
}
⁠TLS
➜ grpcurl -insecure -use-reflection  -d '{"message": "1234", "delay": 1000 }' localhost:5001 echo.Echo/Echo # delay after 1s
{
  "message": "1234"
}

⁠Metrics

default metrics port 9091, path /metrics

➜ curl localhost:9091/metrics
# HELP http_requests Number of HTTP requests received.
# TYPE http_requests counter
http_requests_total{method="GET",path="/foo",protocol="http",status_code="200"} 1
http_requests_total{method="GET",path="/foo",protocol="https",status_code="200"} 2
http_requests_total{method="GET",path="/bar",protocol="http",status_code="200"} 1
http_requests_total{method="GET",path="/bar",protocol="https",status_code="200"} 2
# HELP http_requests Number of HTTP requests received.
# TYPE http_requests counter
# HELP grpc_requests Number of GRPC requests received.
# TYPE grpc_requests counter
grpc_requests_total{method="/echo.Echo/Echo",protocol="tls"} 4
grpc_requests_total{method="/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo",protocol="plaintext"} 3
grpc_requests_total{method="/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo",protocol="tls"} 4
grpc_requests_total{method="/echo.Echo/Echo",protocol="plaintext"} 3

⁠Setting up

⁠Docker
docker run -p 8080:80 yanickxia/recho
⁠Docker-Compose

Sample

services:
    recho:
        image: yanickxia/recho
        environment:
            HTTP_PORT: 8080
        ports:
            - 8080:8080
⁠Kubernetes
curl -sL https://raw.githubusercontent.com/yanickxia/recho/master/docs/examples/kube.yaml | kubectl apply -f -
⁠Kubernetes with Helm

recho: echo service

— Open in Artifact Hub⁠
helm repo add recho https://yanickxia.github.io/recho/
helm repo update
helm install my-recho recho/recho

Tag summary

Content type

Image

Digest

sha256:117516fc2…

Size

69.1 MB

Last updated

almost 2 years ago

docker pull yanickxia/recho