private void HandleRequest(HttpListenerContext context) { #if NETSTANDARD1_5 bool isScrape = context.Request.RequestUri.AbsolutePath.StartsWith("/scrape", StringComparison.OrdinalIgnoreCase); BEncodedValue responseData = Handle(context.Request.RequestUri.AbsolutePath, context.Request.RemoteEndpoint.Address, isScrape); byte[] response = responseData.Encode(); context.Request.Headers["Content-Type"] = "text/plain"; context.Response.StatusCode = 200; context.Request.Headers["Content-Length"] = response.Length.ToString(); context.Response.OutputStream.Write(response, 0, response.Length); #else bool isScrape = context.Request.RawUrl.StartsWith("/scrape", StringComparison.OrdinalIgnoreCase); BEncodedValue responseData = Handle(context.Request.RawUrl, context.Request.RemoteEndPoint.Address, isScrape); byte[] response = responseData.Encode(); context.Response.ContentType = "text/plain"; context.Response.StatusCode = 200; context.Response.ContentLength64 = response.LongLength; context.Response.OutputStream.Write(response, 0, response.Length); #endif }
public static void Write(ref Span <byte> buffer, BEncodedValue value) { var array = value.Encode(); array.AsSpan().CopyTo(buffer); buffer = buffer.Slice(array.Length); }
private void HandleRequest(HttpListenerContext context) { bool isScrape = context.Request.RawUrl.StartsWith("/scrape", StringComparison.OrdinalIgnoreCase); BEncodedValue responseData = Handle(context.Request.RawUrl, context.Request.RemoteEndPoint.Address, isScrape); byte[] response = responseData.Encode(); context.Response.ContentType = "text/plain"; context.Response.StatusCode = 200; context.Response.ContentLength64 = response.LongLength; context.Response.OutputStream.Write(response, 0, response.Length); }
async void ProcessContextAsync(HttpListenerContext context, CancellationToken token) { using (context.Response) { bool isScrape = context.Request.RawUrl.StartsWith("/scrape", StringComparison.OrdinalIgnoreCase); BEncodedValue responseData = Handle(context.Request.RawUrl, context.Request.RemoteEndPoint.Address, isScrape); byte[] response = responseData.Encode(); context.Response.ContentType = "text/plain"; context.Response.StatusCode = 200; context.Response.ContentLength64 = response.LongLength; await context.Response.OutputStream.WriteAsync(response, 0, response.Length, token); } }
public static void Write(ref Span <byte> buffer, BEncodedValue value) { int written = value.Encode(buffer); buffer = buffer.Slice(written); }