Skip to content

Commit

Permalink
HTTP requests with /dev/tcp, #closes #126
Browse files Browse the repository at this point in the history
  • Loading branch information
rednafi committed Aug 9, 2024
1 parent 6b60595 commit 3f75f70
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions content/misc/http_requests_via_dev_tcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 3f75f70

Please sign in to comment.