Yuzem
November 6th, 2008, 12:52 AM
The bash web server is from this (http://paulbuchheit.blogspot.com/2007/04/webserver-in-bash.html) page.
The problem is that I can't use local pictures on the web pages that are generated.
To test it, run the scripts below and point your browser to "http://localhost:9000"
This shows "hello world"
#!/bin/bash
# web.sh -- http://localhost:9000/hello?world
RESP=/tmp/webresp
[ -p $RESP ] || mkfifo $RESP
while true ; do
( cat $RESP ) | nc -l -p 9000 | (
REQ=`while read L && [ " " "<" "$L" ] ; do echo "$L" ; done`
cat >$RESP <<EOF
HTTP/1.0 200 OK
Cache-Control: private
Content-Type: text/plain
Server: bash/2.0
Connection: Close
Content-Length: 1
Hello World
EOF
)
done
The next one shows a picture but it doesn't stop, it keeps trying to load the picture even if it is already loaded. (reeplace '/home/user/path/2/picture' with the path to a picture)
#!/bin/bash
# web.sh -- http://localhost:9000/hello?world
RESP=/tmp/webresp
[ -p $RESP ] || mkfifo $RESP
while true ; do
( cat $RESP ) | nc -l -p 9000 | (
REQ=`while read L && [ " " "<" "$L" ] ; do echo "$L" ; done`
cat '/home/user/path/2/picture' >$RESP
)
done
How to send images over the http protocol?
Thanks in advance!
The problem is that I can't use local pictures on the web pages that are generated.
To test it, run the scripts below and point your browser to "http://localhost:9000"
This shows "hello world"
#!/bin/bash
# web.sh -- http://localhost:9000/hello?world
RESP=/tmp/webresp
[ -p $RESP ] || mkfifo $RESP
while true ; do
( cat $RESP ) | nc -l -p 9000 | (
REQ=`while read L && [ " " "<" "$L" ] ; do echo "$L" ; done`
cat >$RESP <<EOF
HTTP/1.0 200 OK
Cache-Control: private
Content-Type: text/plain
Server: bash/2.0
Connection: Close
Content-Length: 1
Hello World
EOF
)
done
The next one shows a picture but it doesn't stop, it keeps trying to load the picture even if it is already loaded. (reeplace '/home/user/path/2/picture' with the path to a picture)
#!/bin/bash
# web.sh -- http://localhost:9000/hello?world
RESP=/tmp/webresp
[ -p $RESP ] || mkfifo $RESP
while true ; do
( cat $RESP ) | nc -l -p 9000 | (
REQ=`while read L && [ " " "<" "$L" ] ; do echo "$L" ; done`
cat '/home/user/path/2/picture' >$RESP
)
done
How to send images over the http protocol?
Thanks in advance!