internal void SendHeaders(bool closing, MemoryStream ms) { Encoding @default = this.content_encoding; if (@default == null) { @default = Encoding.Default; } if (this.content_type != null) { if (this.content_encoding != null && this.content_type.IndexOf("charset=") == -1) { string webName = this.content_encoding.WebName; this.headers.SetInternal("Content-Type", this.content_type + "; charset=" + webName); } else { this.headers.SetInternal("Content-Type", this.content_type); } } if (this.headers["Server"] == null) { this.headers.SetInternal("Server", "Mono-HTTPAPI/1.0"); } CultureInfo invariantCulture = CultureInfo.InvariantCulture; if (this.headers["Date"] == null) { this.headers.SetInternal("Date", DateTime.UtcNow.ToString("r", invariantCulture)); } if (!this.chunked) { if (!this.cl_set && closing) { this.cl_set = true; this.content_length = 0L; } if (this.cl_set) { this.headers.SetInternal("Content-Length", this.content_length.ToString(invariantCulture)); } } Version protocolVersion = this.context.Request.ProtocolVersion; if (!this.cl_set && !this.chunked && protocolVersion >= HttpVersion.Version11) { this.chunked = true; } bool flag = this.status_code == 400 || this.status_code == 408 || this.status_code == 411 || this.status_code == 413 || this.status_code == 414 || this.status_code == 500 || this.status_code == 503; if (!flag) { flag = (this.context.Request.Headers["connection"] == "close"); flag |= (protocolVersion <= HttpVersion.Version10); } if (!this.keep_alive || flag) { this.headers.SetInternal("Connection", "close"); } if (this.chunked) { this.headers.SetInternal("Transfer-Encoding", "chunked"); } int chunkedUses = this.context.Connection.ChunkedUses; if (chunkedUses >= 100) { this.force_close_chunked = true; if (!flag) { this.headers.SetInternal("Connection", "close"); } } if (this.location != null) { this.headers.SetInternal("Location", this.location); } if (this.cookies != null) { foreach (object obj in this.cookies) { Cookie cookie = (Cookie)obj; this.headers.SetInternal("Set-Cookie", cookie.ToClientString()); } } StreamWriter streamWriter = new StreamWriter(ms, @default); streamWriter.Write("HTTP/{0} {1} {2}\r\n", this.version, this.status_code, this.status_description); string value = this.headers.ToStringMultiValue(); streamWriter.Write(value); streamWriter.Flush(); int num = @default.GetPreamble().Length; if (this.output_stream == null) { this.output_stream = this.context.Connection.GetResponseStream(); } ms.Position = (long)num; this.HeadersSent = true; }