public void TestCaseInsensitiveHeaders() { var builder = new HttpData.Builder(); builder.AddHeader("Content-Length", "20"); var data = builder.CreateAndClear(); Assert.Equal("20", data.Headers["Content-Length"]); Assert.Equal("20", data.Headers["content-length"]); Assert.Equal("20", data.Headers["content-LENGTH"]); Assert.Equal("20", data.Headers["CONTENT-LENGTH"]); Assert.Throws(typeof(KeyNotFoundException), delegate() { var x = data.Headers["ContentLength"]; }); }
void channel_RequestReceived(object sender, Netool.Network.DataEventArgs e) { var channel = sender as HttpServerChannel; if (channel == null) { return; } var data = new HttpData.Builder(); data.AddHeader("Transfer-Encoding", "chunked"); data.IsRequest = false; data.HttpVersion = "1.1"; data.ReasonPhrase = "OK"; data.StatusCode = 200; channel.Send(data.CreateAndClear(generateChunkedData(100 * 1024 * 1024))); }
public void TestStatusLine() { var builder = new HttpData.Builder(); builder.IsRequest = true; builder.Method = HttpRequestMethod.GET; builder.HttpVersion = "1.1"; builder.RequestTarget = "/index.html"; Assert.Equal("GET /index.html HTTP/1.1", builder.CreateAndClear().StatusLine); builder = new HttpData.Builder(); builder.IsRequest = false; builder.HttpVersion = "1.1"; builder.StatusCode = 200; builder.ReasonPhrase = "OK"; Assert.Equal("HTTP/1.1 200 OK", builder.CreateAndClear().StatusLine); }
/// <inheritdoc/> public IDataStream CreateMessage() { var key = new byte[16]; gen.NextBytes(key); var builder = new HttpData.Builder(); builder.IsRequest = true; builder.HttpVersion = "1.1"; builder.Method = HttpRequestMethod.GET; builder.RequestTarget = "/"; builder.AddHeader("Host", ""); builder.AddHeader("Upgrade", "websocket"); builder.AddHeader("Connection", "Upgrade"); builder.AddHeader("Sec-WebSocket-Version", "13"); builder.AddHeader("Sec-WebSocket-Key", Convert.ToBase64String(key)); return(builder.CreateAndClear()); }
/// <summary> /// Non-interactive interface for CreateMessage method /// </summary> /// <param name="SecWebsocketKey">null if you don't wish to add Sec-WebSocket-Accept header to the template</param> /// <returns></returns> public IDataStream CreateMessage(string SecWebsocketKey) { var builder = new HttpData.Builder(); builder.IsRequest = false; builder.HttpVersion = "1.1"; builder.StatusCode = 101; builder.ReasonPhrase = "Switching Protocols"; builder.AddHeader("Upgrade", "websocket"); builder.AddHeader("Connection", "Upgrade"); builder.AddHeader("Sec-WebSocket-Version", "13"); if (SecWebsocketKey != null) { var sha1 = new SHA1Managed(); var key = Convert.ToBase64String(sha1.ComputeHash(ASCIIEncoding.ASCII.GetBytes(SecWebsocketKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"))); builder.AddHeader("Sec-WebSocket-Accept", key); } return(builder.CreateAndClear()); }