commit
9466883aed
3 changed files with 47 additions and 0 deletions
@ -0,0 +1,4 @@ |
|||
## Bash Web Application Framework |
|||
|
|||
* Requires https://cr.yp.to/ucspi-tcp.html |
|||
* Simply run `./start.sh` to launch it, and then go to [http://127.0.0.1:6001/name/luigi](http://127.0.0.1:6001/name/luigi) to see it in action. |
@ -0,0 +1,41 @@ |
|||
#! /usr/bin/env bash |
|||
shopt -s extglob |
|||
|
|||
url_components=() |
|||
|
|||
function parse_url() { |
|||
IFS='/' read -r -a url_components <<< $1 |
|||
} |
|||
|
|||
function parse_request() { |
|||
read -u 0 request |
|||
method=$(echo "$request" | cut -d ' ' -f 1) |
|||
url=$(echo "$request" | cut -d ' ' -f 2) |
|||
echo "$url" |
|||
} |
|||
|
|||
parse_url $(parse_request) |
|||
|
|||
url_matcher="${url_components[@]}" |
|||
|
|||
case $url_matcher in |
|||
*home*) |
|||
data="Hello!" |
|||
;; |
|||
*name*) |
|||
data="Your name is ${url_components[-1]}" |
|||
;; |
|||
*) |
|||
data="it's something else, $url_matcher" |
|||
;; |
|||
esac |
|||
|
|||
response="<html>$data</html>" |
|||
content_length=$(( $(echo $response | wc -c) - 1)) |
|||
|
|||
printf "HTTP/1.1 200 OK\r\n" |
|||
printf "Server: ucspi\r\n" |
|||
printf "Content-Type: text/html; charset=UTF-8\r\n" |
|||
printf "Content-Length: $content_length\r\n" |
|||
printf "\r\n" |
|||
printf "$response" |
@ -0,0 +1,2 @@ |
|||
#! /usr/bin/env bash |
|||
tcpserver -v 127.0.0.1 6001 ./server.sh |
Loading…
Reference in new issue