public HTTPResponse( string protocol, HttpStatusCode status, IDictionary <string, string> headers, string body) { this.Protocol = protocol; this.Status = (int)status; this.ReasonPhrase = HTTPUtils.GetReasonPhrase(this.Status); this.Headers = new Dictionary <string, string>(headers, StringComparer.OrdinalIgnoreCase); var mem = new MemoryStream(); using (var writer = new StreamWriter(mem)) { writer.Write(body); } this.Body = mem.ToArray(); if (!Headers.ContainsKey("Content-Type")) { Headers.Add("Content-Type", "text/plain"); } if (status == HttpStatusCode.Unauthorized && !Headers.ContainsKey("WWW-Authenticate")) { Headers.Add("WWW-Authenticate", "Basic realm=\"PeerCastStation\""); } }
public HTTPResponse( string protocol, int status, string reason_phrase, IDictionary <string, string> headers, byte[] body) { this.Protocol = protocol; this.Status = status; this.ReasonPhrase = reason_phrase ?? HTTPUtils.GetReasonPhrase(status); this.Headers = new Dictionary <string, string>(headers, StringComparer.OrdinalIgnoreCase); this.Body = body; }
public HTTPResponse( string protocol, HttpStatusCode status) { this.Protocol = protocol; this.Status = (int)status; this.ReasonPhrase = HTTPUtils.GetReasonPhrase(this.Status); this.Headers = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); this.Body = null; if (status == HttpStatusCode.Unauthorized && !Headers.ContainsKey("WWW-Authenticate")) { Headers.Add("WWW-Authenticate", "Basic realm=\"PeerCastStation\""); } }