Thread: I need help with a simple HTTP server in bash.
i have simple http server in bash , works great html content when trying send images first 1 displayed on browser.
idea problem be?
here code:
code:# web.sh -- http://localhost:9009/ #folder=folder_with_imges cd $folder resp=/tmp/webresp [ -p $resp ] || mkfifo $resp while true ; ( cat $resp ) | nc -l -p 9009 | ( req=$(while read l && [ " " "<" "$l" ] ; echo "$l" ; done) echo "$req" echo "[`date '+%y-%m-%d %h:%m:%s'`] ${req%%$'\n'*}" req=${req#* } req=${req% http*} if [[ $req = *png ]]; file=.$req size=$(find $file -printf '%s') { echo http/1.0 200 ok echo cache-control: private echo content-type: image/jpeg echo connection: close echo content-length: $size echo cat $file echo } > $resp else page=$( for in movies books music pictures; echo "<img src='$i.png'></div>" done ) { echo http/1.0 200 ok echo cache-control: private echo content-type: html echo server: bash/2.0 echo connection: close echo content-length: ${#page} echo echo "$page" } > $resp fi ) done
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk I need help with a simple HTTP server in bash.
Ubuntu
Comments
Post a Comment