├── LICENSE ├── README.md └── burl /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Marc Falzon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bURL - A pure Bash HTTP client 2 | 3 | **Caveat: this is a toy project, not meant to be used for serious purposes. The code is trivial and ugly – is anything else possible when written in shell script? – and probably buggy.** 4 | 5 | ## Usage 6 | 7 | ``` 8 | Usage: ./burl [options] URL 9 | 10 | Options: 11 | -h display usage help 12 | -i include the HTTP header in the output 13 | -p use alternative port number (default: 80) 14 | 15 | ``` 16 | 17 | ``` 18 | $ burl http://tools.ietf.org/html/rfc2616 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 40 | 41 | 42 | 43 | 44 | RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1 45 | ... 46 | ``` 47 | 48 | ## Limitations 49 | 50 | Basically, everything beyond fetching a HTTP – no HTTPS, obviously – resource accessible without redirection and with authentication. 51 | -------------------------------------------------------------------------------- /burl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | INCLUDE_HEADERS=0 4 | HTTP_PORT=80 5 | 6 | burl() { 7 | shopt -s extquote 8 | 9 | export LC_ALL=C 10 | unset headers_read 11 | 12 | host=${1%%/*} 13 | path=${1#*/} 14 | 15 | [[ $path == $host ]] && path="" 16 | 17 | exec 3<>/dev/tcp/${host}/${HTTP_PORT} 18 | 19 | printf "GET /${path} HTTP/1.1\r\nHost: ${host}\r\nUser-Agent: bURL/Bash ${BASH_VERSION}\r\n\r\n" >&3 20 | 21 | IFS= 22 | while read -r -t 1 line 0<&3; do 23 | line=${line//$'\r'} 24 | 25 | if [[ ! -v headers_read && $INCLUDE_HEADERS -eq 0 ]]; then 26 | [[ -z $line ]] && headers_read=yes 27 | continue 28 | fi 29 | 30 | echo "$line" 31 | done 32 | 33 | exec 3<&- 34 | } 35 | 36 | usage() { 37 | cat < use alternative port number (default: 80) 44 | EOF 45 | } 46 | 47 | if [[ $# -eq 0 ]]; then 48 | usage 49 | exit 1 50 | fi 51 | 52 | while getopts 'hip:' option; do 53 | case "$option" in 54 | h) 55 | usage 56 | exit 0 57 | ;; 58 | 59 | i) 60 | INCLUDE_HEADERS=1 61 | ;; 62 | 63 | p) 64 | HTTP_PORT=$OPTARG 65 | ;; 66 | 67 | *) 68 | usage 69 | exit 1 70 | ;; 71 | esac 72 | done 73 | shift $(( $OPTIND - 1)) 74 | 75 | burl ${1/http:\/\/} 76 | 77 | # vim: ft=sh ts=4 et 78 | --------------------------------------------------------------------------------