Skip to content

Commit 342c58f

Browse files
author
Sylvain DUARTE
committed
Add the possibility to disable JSON output
1 parent 943ea85 commit 342c58f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ Will contain a `json` property in the response/output.
115115
}
116116
}
117117

118+
## Send an empty response
119+
120+
You can disable the JSON output in the response by setting the environment variable `ECHO_BACK_TO_CLIENT`. For example,
121+
122+
```bash
123+
docker run -e ECHO_BACK_TO_CLIENT=false -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:20
124+
```
125+
118126
## Custom status code
119127

120128
Use `x-set-response-status-code` to set a custom status code. For example,

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ app.all('*', (req, res) => {
6666
const sleepTime = parseInt(req.headers["x-set-response-delay-ms"], 0)
6767
sleep(sleepTime).then(() => {
6868

69-
res.json(echo);
69+
if (process.env.ECHO_BACK_TO_CLIENT == "" || process.env.ECHO_BACK_TO_CLIENT == "true"){
70+
res.json(echo);
71+
} else {
72+
res.end();
73+
}
7074

7175
if (process.env.LOG_IGNORE_PATH != req.path) {
7276
console.log('-----------------')

0 commit comments

Comments
 (0)