Skip to content

Instantly share code, notes, and snippets.

@felegy
Last active September 22, 2022 13:25
Show Gist options
  • Save felegy/763db2729288df41beb0a1e298b9fc53 to your computer and use it in GitHub Desktop.
Save felegy/763db2729288df41beb0a1e298b9fc53 to your computer and use it in GitHub Desktop.
Poor man's `CURL` or `WGET`
#!/usr/bin/env sh
#
# Usage: http-get.sh [PATH PORT HOST]
#
# Environment variables
# REQUEST_PATH - path of the request, default value `/`
# REQUEST_PORT - http port, default value `80`
# REQUEST_HOST - host of the request, default value `localhost`
REQUEST_PATH=${1:-${REQUEST_PATH-/}}
REQUEST_PORT=${2:-${REQUEST_PORT-80}}
REQUEST_HOST=${3:-${REQUEST_HOST-localhost}}
exec 5<> /dev/tcp/$REQUEST_HOST/$REQUEST_PORT
cat <&5 &
printf "GET $REQUEST_PATH HTTP/1.0\r\n\r\n" >&5
cat <&5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment