public bool write(string x) { if (Ini.istrue(En.debug_http)) { this.imsg("http: write: {0}", (object)x); } return(this.chan.write(x)); }
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; } }
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"); }
private void process_header(string header) { this.head.Clear(); this.content_type = ""; this.content_len = 0; this.imsg("content_mystery, process_header started {0}", (object)this.content_len); this.depth = 2; string[] strArray = clib.string_lines(header); string rline = strArray[0]; this.save_request = rline; if (Ini.istrue(En.debug_http)) { this.imsg("http: ===< Request: {0}", (object)rline); } foreach (string str1 in strArray) { int length = str1.IndexOf(":"); if (length >= 0) { string str2 = str1.Substring(0, length); string str3 = str1.Substring(length + 1); if (str3.Length > 0 && str3.StartsWith(" ")) { str3 = str3.Substring(1); } if (Ini.istrue(En.debug_http)) { this.imsg("http: {0}: {1}", (object)str2, (object)str3); } try { this.head.Add(str2.ToLower(), str3); } catch { } } } this.isgzip = this.head_get("Content-Encoding").Contains("gzip"); if (this.isgzip) { this.inmem = true; this.mem_body = new MyBuffer(); } this.isie = this.head_get("User-Agent").Contains("MSIE"); this.was_content = false; this.content_len = clib.atoi(this.head_get("Content-Length")); if (this.content_len > 0) { this.was_content = true; } this.imsg("do_headers: mystery content_len is {0} {1}", (object)this.content_len, (object)rline); this.in_chunked = false; string str4 = this.head_get("Timeout"); if (str4 != null) { int num = str4.IndexOf("Second-"); this.h_timeout = num < 0 ? 3600 : clib.atoi(str4.Substring(num + "Second-".Length)); } string str5 = this.head_get("Transfer-Encoding"); if (str5 != null && str5.ToLower().Contains("chunked")) { this.in_chunked = true; this.chunk_len = 0; } this.do_continue = false; if (this.head_get("Expect").Contains("100-continue")) { this.do_continue = true; } if (this.do_continue) { this.imsg("Sending: HTTP/1.1 100 Continue\n"); this.chan.write("HTTP/1.1 100 Continue\r\n\r\n"); } this.destination = this.head_get("Destination"); this.destination = clib.url_decode(this.destination); this.imsg("decoded dest is now {0}", (object)this.destination); this.overwrite = true; string str6 = this.head_get("Overwrite"); if (str6 != null) { if (str6.ToLower().Contains("t")) { this.overwrite = true; } if (str6.ToLower().Contains("f")) { this.overwrite = false; } } string lower = (this.head_get("Depth") ?? "2").Trim().ToLower(); if (lower.Length == 0) { this.depth = 2; } else if (lower == "0") { this.depth = 0; } else if (lower == "1") { this.depth = 1; } else if (lower == "infinity") { this.depth = 2; } this.imsg("Depth is {0}", (object)this.depth); this.cookie = this.head_get("Cookie"); this.imsg("Main request: {0} {1}", (object)this.content_len, (object)rline); if (!this.decode_request(rline)) { this.imsg("decode_request failed - close link"); this.imsg("decode_request failed - close link"); this.chan.EndConnection(); } else { this.imsg("decode_request worked okk"); } }