Ejemplo n.º 1
0
 public static void simple_error(Websvc w, string msg)
 {
     Web.any_header(w, "text/plain", "200 Ok");
     Web.wp(w, "{0}\n", (object)msg);
     w.body_send();
     w.chan.EndConnection();
 }
Ejemplo n.º 2
0
 public static bool send_file(
     Websvc w,
     SimpleStream ss,
     string fname,
     bool attached,
     bool andbody)
 {
     if (ss == null || !ss.isopen)
     {
         string x = "Send:File not found " + fname;
         w.chan.write(string.Format("HTTP/1.1 500 FILE NOT FOUND\r\nContent-Length: {0}\r\n\r\n", (object)x.Length));
         w.chan.write(x);
         return(false);
     }
     if (!andbody)
     {
         Web.any_header(w, clib.content_type(fname), "200 Ok", 0, false);
         WebFile.send_file_headers(w, ss);
         w.body_send();
         return(true);
     }
     if (w.ifmodified == ss.lastmodified().ToHttpDate())
     {
         Web.any_header(w, clib.content_type(fname), "304 Not modified", 0, false);
         w.body_send();
         return(true);
     }
     Web.any_header(w, clib.content_type(fname), "200 Ok", -1, true);
     WebFile.send_file_headers(w, ss);
     if (attached)
     {
         w.chan.write(string.Format("Content-Disposition: attachment; filename=\"{0}\"\r\n", (object)clib.fileonly(fname)));
     }
     w.chan.write("\r\n");
     while (true)
     {
         int    sz       = 10000;
         byte[] numArray = new byte[sz];
         int    count    = ss.read(numArray, 0, sz);
         if (count > 0)
         {
             w.chan.write(string.Format("{0:x}\r\n", (object)count));
             w.chan.Write(numArray, 0, count);
             w.chan.write("\r\n");
         }
         else
         {
             break;
         }
     }
     w.chan.write("0\r\n\r\n");
     return(true);
 }
Ejemplo n.º 3
0
 public static void start(Websvc w)
 {
     Web.any_header(w, "text/html", "200 Ok");
     Web.wp(w, "<HTML>\n");
     Web.wp(w, "<HEAD>\n");
     Web.wp(w, "<LINK REL=\"shortcut icon\"  HREF=\"/img/favicon.ico\">");
     Web.wp(w, "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"/web/free.css\">");
     Web.wp(w, "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"/web/all.css\">");
     if (!w.isie)
     {
         Web.wp(w, "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"/web/buttons.css\">");
     }
     else
     {
         Web.wp(w, "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"/web/buttons_ie.css\">");
     }
     Web.wp(w, "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"/web/files.css\">");
     Web.wp(w, "<script language=\"javascript\" type=\"text/javascript\" src=\"/web/all.js\"></script>");
 }
Ejemplo n.º 4
0
        public static void need_auth(Websvc w)
        {
            Random random = new Random();

            byte[] numArray = new byte[10];
            random.NextBytes(numArray);
            Web.any_header(w, "text/plain", "401 Authorization required");
            Web.wh(w, "WWW-Authenticate: Basic realm=\"{0}\"\r\n", (object)MyMain.realm());
            Web.wh(w, "WWW-Authenticate: Digest");
            Web.wh(w, " realm=\"{0}\",", (object)MyMain.realm());
            Web.wh(w, " qop=\"auth\",");
            Web.wh(w, " nonce=\"{0}\",", (object)clib.byte_to_hex(numArray, ((IEnumerable <byte>)numArray).Count <byte>()));
            Web.wh(w, " opaque=\"placeholder\"\r\n");
            Web.wp(w, "Authorization required");
            w.body_send();
            if (!Ini.istrue(En.debug_http))
            {
                return;
            }
            clib.imsg("http: requesting authentication");
        }
Ejemplo n.º 5
0
 public static void any_header(Websvc w, string content, string reason)
 {
     Web.any_header(w, content, reason, -1, false);
 }