コード例 #1
0
        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
        }
コード例 #2
0
ファイル: Message.cs プロジェクト: gweffect/monotorrent
        public static void Write(ref Span <byte> buffer, BEncodedValue value)
        {
            var array = value.Encode();

            array.AsSpan().CopyTo(buffer);
            buffer = buffer.Slice(array.Length);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        public static void Write(ref Span <byte> buffer, BEncodedValue value)
        {
            int written = value.Encode(buffer);

            buffer = buffer.Slice(written);
        }