pike.git / lib / modules / Tools.pmod / Standalone.pmod / httpserver.pike

version» Context lines:

pike.git/lib/modules/Tools.pmod/Standalone.pmod/httpserver.pike:52:    foreach( get_dir( dir ); int i; string fn )    {    Stdio.Stat s = file_stat( combine_path(dir, fn) );    if( !s )    continue;       string t = s->isdir?"":Protocols.HTTP.Server.filename_to_type(fn);    if( t == "application/octet-stream" )    t = "<span style='color:darkgrey'>unknown</span>";    -  fn = Parser.encode_html_entities(fn); +     res +=    sprintf("<tr class='%s'><td><a href='%s%s'>%s%[2]s</a></td>"    "<td align='right'>%s</td>"    "<td align='right'>%s</td></tr>\n",    (i&1?"odd":"even"), -  fn, s->isdir?"/":"", fn, t, +  Protocols.HTTP.uri_encode(fn), s->isdir?"/":"", +  Parser.encode_html_entities(fn), t,    s->isdir?"":String.int2size(s->size));    }    return res+"</table></body></html>\n";   }      string file_not_found(string fname)   {    return    "<html><body><h1>File not found</h1>\n"    "<tt>" + Parser.encode_html_entities(fname) + "</tt><br />\n"    "</body></html>\n";   }      void handle_request(Protocols.HTTP.Server.Request request)   {    string file = "."+combine_path("/",request->not_query); -  +  file = Protocols.HTTP.uri_decode(file);    Stdio.Stat s = file_stat( file );    if( !s )    request->response_and_finish( (["data":    file_not_found(request->not_query),    "type":"text/html",    "error":404]) );    else if( s->isdir )    request->response_and_finish( ([ "data":dirlist(file),    "type":"text/html" ]) );    else    request->response_and_finish( ([ "file":Stdio.File(file),    "type":Protocols.HTTP.Server.    filename_to_type(file) ]) );   }