Skip to main content

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

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums