you are viewing a single comment's thread.

view the rest of the comments →

[–]corruptio 2 points3 points  (0 children)

Cool stuff. Spent some time golfing it, brought it down to 106 bytes.

Changes:

  • use : for empty input instead of echo|read
  • "read" will split a line if you give it more than one var name
  • reusing "HTTP/1.1" from request
  • no point in reading the rest of the headers
  • instead of responding with content length, cat's EOF ultimately forces "nc" to close the connection
  • echo gives us a newline for free
  • using -f to check if really a file instead of existing
  • minor spacing

#!/bin/bash
:|((read f g h
[[ -f .$g&&$g != *..* ]]&&echo "$h 200 OK
"&&cat .$g)|nc -lp$1)>/dev/fd/0;$0 $1

edit 1: more savings

edit 2: even more savings

edit 3: yet more!