internal HttpListenerRequest(WebSocketSharp.Net.HttpListenerContext context) { this._context = context; this._contentLength = (long)-1; this._headers = new WebSocketSharp.Net.WebHeaderCollection(); this._identifier = Guid.NewGuid(); }
public ChunkStream(WebSocketSharp.Net.WebHeaderCollection headers) { this._headers = headers; this._chunkSize = -1; this._chunks = new List <Chunk>(); this._saved = new StringBuilder(); }
public void CopyFrom(WebSocketSharp.Net.HttpListenerResponse templateResponse) { if (templateResponse == null) { throw new ArgumentNullException("templateResponse"); } if (templateResponse._headers != null) { if (this._headers != null) { this._headers.Clear(); } this.Headers.Add(templateResponse._headers); } else if (this._headers != null) { this._headers = null; } this._contentLength = templateResponse._contentLength; this._statusCode = templateResponse._statusCode; this._statusDescription = templateResponse._statusDescription; this._keepAlive = templateResponse._keepAlive; this._version = templateResponse._version; }
public ChunkStream(byte[] buffer, int offset, int count, WebSocketSharp.Net.WebHeaderCollection headers) : this(headers) { this.Write(buffer, offset, count); }
internal WebSocketSharp.Net.WebHeaderCollection WriteHeadersTo(MemoryStream destination) { WebSocketSharp.Net.WebHeaderCollection webHeaderCollection = new WebSocketSharp.Net.WebHeaderCollection(HttpHeaderType.Response, true); if (this._headers != null) { webHeaderCollection.Add(this._headers); } if (this._contentType != null) { webHeaderCollection.InternalSet("Content-Type", (this._contentType.IndexOf("charset=", StringComparison.Ordinal) != -1 || this._contentEncoding == null ? this._contentType : string.Format("{0}; charset={1}", this._contentType, this._contentEncoding.WebName)), true); } if (webHeaderCollection["Server"] == null) { webHeaderCollection.InternalSet("Server", "websocket-sharp/1.0", true); } CultureInfo invariantCulture = CultureInfo.InvariantCulture; if (webHeaderCollection["Date"] == null) { DateTime utcNow = DateTime.UtcNow; webHeaderCollection.InternalSet("Date", utcNow.ToString("r", invariantCulture), true); } if (this._sendChunked) { webHeaderCollection.InternalSet("Transfer-Encoding", "chunked", true); } else { webHeaderCollection.InternalSet("Content-Length", this._contentLength.ToString(invariantCulture), true); } bool flag = (!this._context.Request.KeepAlive || !this._keepAlive || this._statusCode == 400 || this._statusCode == 408 || this._statusCode == 411 || this._statusCode == 413 || this._statusCode == 414 || this._statusCode == 500 ? true : this._statusCode == 503); int reuses = this._context.Connection.Reuses; if ((flag ? false : reuses < 100)) { webHeaderCollection.InternalSet("Keep-Alive", string.Format("timeout=15,max={0}", 100 - reuses), true); if (this._context.Request.ProtocolVersion < WebSocketSharp.Net.HttpVersion.Version11) { webHeaderCollection.InternalSet("Connection", "keep-alive", true); } } else { webHeaderCollection.InternalSet("Connection", "close", true); } if (this._location != null) { webHeaderCollection.InternalSet("Location", this._location, true); } if (this._cookies != null) { foreach (WebSocketSharp.Net.Cookie _cooky in this._cookies) { webHeaderCollection.InternalSet("Set-Cookie", _cooky.ToResponseString(), true); } } Encoding @default = this._contentEncoding ?? Encoding.Default; StreamWriter streamWriter = new StreamWriter(destination, @default, 256); streamWriter.Write("HTTP/{0} {1} {2}\r\n", this._version, this._statusCode, this._statusDescription); streamWriter.Write(webHeaderCollection.ToStringMultiValue(true)); streamWriter.Flush(); destination.Position = (long)((int)@default.GetPreamble().Length); return(webHeaderCollection); }