From 3f75f7031bea60c8cfc67329e2068ab14e2a5b27 Mon Sep 17 00:00:00 2001 From: rednafi Date: Fri, 9 Aug 2024 05:09:31 +0200 Subject: [PATCH] HTTP requests with /dev/tcp, #closes #126 --- content/misc/http_requests_via_dev_tcp.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/content/misc/http_requests_via_dev_tcp.md b/content/misc/http_requests_via_dev_tcp.md index 8555d65..0df4226 100644 --- a/content/misc/http_requests_via_dev_tcp.md +++ b/content/misc/http_requests_via_dev_tcp.md @@ -83,11 +83,16 @@ exec 3<>"/dev/tcp/${HOST}/${PORT}" # Send the HTTP GET request to the server echo -e \ - "GET ${HEALTH_PATH} HTTP/1.1\r\nHost: ${HOST}\r\nConnection: close\r\n\r\n" >&3 + "GET ${HEALTH_PATH} HTTP/1.1\r\nHost: ${HOST}\r\nConnection: close\r\n\r\n" \ + >&3 # Read the HTTP status from the server's response read -r HTTP_RESPONSE <&3 -HTTP_STATUS=$(echo "${HTTP_RESPONSE}" | grep -o "HTTP/1.1 [0-9]*" | cut -d ' ' -f 2) +HTTP_STATUS=$( + echo "${HTTP_RESPONSE}" \ + | grep -o "HTTP/1.1 [0-9]*" \ + | cut -d ' ' -f 2 +) if [[ "${HTTP_STATUS}" == "200" ]]; then echo "Service is healthy."