예제 #1
0
 public static void any_header(
     Websvc w,
     string content,
     string reason,
     int content_len,
     bool ischunked)
 {
     w.out_chunked = false;
     w.need_length = false;
     if (Ini.istrue(En.debug_http))
     {
         clib.imsg("http: response: {0}", (object)reason);
     }
     Web.imsg("http: response: {0}", (object)reason);
     Web.wh(w, string.Format("HTTP/1.{0} {1}\r\n", (object)w.httpversion, (object)reason));
     Web.wh(w, "Server: DManager\r\n");
     Web.wh(w, "MIME-version: 1.0\r\n");
     if (w.isdav)
     {
         Web.wh(w, "DAV: 1,2\r\n");
         Web.wh(w, "Allow: GET, PUT, DELETE, MKCOL, OPTIONS, COPY, MOVE, PROPFIND, PROPPATCH, LOCK, UNLOCK\r\n");
         Web.wh(w, "Connection: keep-alive\r\n");
         Web.wh(w, "Pragma: no-cache\r\n");
         Web.wh(w, "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\n");
     }
     if (content.Contains("text/html"))
     {
         content += "; charset=utf-8";
     }
     Web.wh(w, "Content-Type: {0}\r\n", (object)content);
     w.need_length = true;
     w.need_blank  = true;
     if (content_len >= 0)
     {
         Web.wh(w, "Content-Length: {0}\r\n", (object)content_len);
         w.need_length = false;
     }
     else if (w.httpversion == 1 && ischunked)
     {
         Web.wh(w, "Transfer-Encoding: chunked\r\n");
         w.out_chunked = true;
     }
 }
예제 #2
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");
        }
예제 #3
0
 public static void cookie_set(Websvc w, string var, string val)
 {
     Web.wh(w, "Set-Cookie: {0}={1};\r\n", (object)var, (object)val);
 }