Browse Source

initial commit

master
Wesley Kerfoot 5 years ago
commit
9466883aed
  1. 4
      README.md
  2. 41
      server.sh
  3. 2
      start.sh

4
README.md

@ -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.

41
server.sh

@ -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"

2
start.sh

@ -0,0 +1,2 @@
#! /usr/bin/env bash
tcpserver -v 127.0.0.1 6001 ./server.sh
Loading…
Cancel
Save