Advertisement
MasWag

httpd.awk

Jan 1st, 2015
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.66 KB | None | 0 0
  1. BEGIN {
  2.     root = "./"
  3.     sock = "/inet4/tcp/8080/0/0";
  4.     while(1) {
  5.     print "listennig..."
  6.     while ((sock |& getline) > 0) {
  7.         print;
  8.         if ($0 ~ /^\s*$/) {
  9.         print "connection closed";
  10.         break;
  11.         }
  12.         # GET以外はしらない
  13.         if ( $1 == "GET") {
  14.         first = 1;
  15.         print "type is GET";
  16.         path = root $2;
  17.         print "path is" path;
  18.         while ((getline < path) > 0) {
  19.             if (first) {
  20.             printf "HTTP/1.1 200 OK\r\n\r\n" |& sock;
  21.             }
  22.             print |& sock;
  23.             first = 0;
  24.         }
  25.         close (path);
  26.         if (first) {
  27.             printf "HTTP/1.1 404 Not Found\r\n\r\n" |& sock;
  28.         }
  29.         }
  30.     }
  31.         close(sock);
  32.     }
  33.     print |& sock;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement