コード例 #1
0
 private static void WriteResponseHeaders(HttpResponse response, HttpEntry record)
 {
     record.StatusCode      = response.StatusCode;
     record.ResponseHeaders = response.Headers.ToDictionary(
         kvp => kvp.Key,
         kvp => kvp.Value.ToArray()
         );
 }
コード例 #2
0
        private async Task OnSendingHeaders(HttpResponse response, HttpEntry record)
        {
            // adding the tracking id response header so that the user
            // of the API can correlate the call back to this entry

            response.Headers.Add(trackingIdPropertyName_, new[] { record.TrackingId.ToString("d"), });

            await Task.CompletedTask;
        }
コード例 #3
0
        private static void WriteRequestHeaders(HttpContext context, HttpEntry record)
        {
            var request = context.Request;

            record.Verb           = request.Method;
            record.RequestUri     = GetPath(context);
            record.RequestHeaders = request.Headers.ToDictionary(
                kvp => kvp.Key,
                kvp => kvp.Value.ToArray()
                );
        }
コード例 #4
0
 public void ConnectHttp(string route, int id, string username, string pwd, int operate)
 {
     try
     {
         WWWForm form = new WWWForm();
         form.AddField("id", id);
         form.AddField("userId", username);
         form.AddField("password", pwd);
         form.AddField("operate", operate);
         Debug.Log(("登录服务器地址:http://" + AppConst.SocketAddress + ":" + AppConst.SocketPort + "/" + route));
         this.StartCoroutine(HttpEntry.LSend("http://" + AppConst.SocketAddress + ":" + AppConst.SocketPort + "/" + route, form));
     }
     catch (Exception ex)
     {
         Debug.LogError("输入错误");
     }
 }
コード例 #5
0
        public async System.Threading.Tasks.Task InsertRecordAsync(HttpEntry record)
        {
            var path = Path.Combine(path_, record.TrackingId.ToString("d"));

            using (var stream = File.OpenWrite(path))
                using (var writer = new StreamWriter(stream))
                    await writer.WriteAsync(JsonConvert.SerializeObject(record));

            Console.WriteLine("Verb: {0}", record.Verb);
            Console.WriteLine("RequestUri: {0}", record.RequestUri);
            Console.WriteLine("Request: {0}", record.Request);
            Console.WriteLine("RequestLength: {0}", record.RequestLength);

            Console.WriteLine("StatusCode: {0}", record.StatusCode);
            Console.WriteLine("ReasonPhrase: {0}", record.ReasonPhrase);
            Console.WriteLine("Response: {0}", record.Response);
            Console.WriteLine("Content-Length: {0}", record.ResponseLength);

            Console.WriteLine("FILE {0} saved.", path);
        }
コード例 #6
0
        /// <summary>
        /// Processes the incoming HTTP call and capture details about
        /// the request, the response, the identity of the caller and the
        /// call duration to persistent storage.
        /// </summary>
        /// <param name="context">A reference to the Owin context.</param>
        /// <returns />
        public override async Task Invoke(IOwinContext context)
        {
            var request  = context.Request;
            var response = context.Response;

            // capture details about the caller identity

            var identity =
                request.User != null && request.User.Identity.IsAuthenticated ?
                request.User.Identity.Name :
                "(anonymous)"
            ;

            var record = new HttpEntry
            {
                CallerIdentity = identity,
            };

            string origin = request.Headers.ContainsKey("Origin") ? request.Headers.Get("Origin") : "";

            if (!String.IsNullOrEmpty(origin) && !origin.Contains("null"))
            {
                record.RequestOrigin = origin;
            }
            else
            {
                record.RequestOrigin = "*";
            }


            // replace the request stream in order to intercept downstream reads

            var requestBuffer = new MemoryStream();
            var requestStream = new ContentStream(requestBuffer, request.Body);

            request.Body = requestStream;

            // replace the response stream in order to intercept downstream writes

            var responseBuffer = new MemoryStream();
            var responseStream = new ContentStream(responseBuffer, response.Body);

            response.Body = responseStream;

            // add the "Http-Tracking-Id" response header

            context.Response.OnSendingHeaders(state =>
            {
                var ctx  = state as IOwinContext;
                var resp = ctx.Response;

                // adding the tracking id response header so that the user
                // of the API can correlate the call back to this entry

                resp.Headers.Add(trackingIdPropertyName_, new[] { record.TrackingId.ToString("d"), });
                resp.Headers.Add(AllowCorsPropertyName_, new[] { record.RequestOrigin, });
            }, context)
            ;

            // invoke the next middleware in the pipeline

            await Next.Invoke(context);

            // rewind the request and response buffers
            // and record their content

            WriteRequestHeaders(request, record);
            record.RequestLength = requestStream.ContentLength;
            record.Request       = await WriteContentAsync(requestStream, record.RequestHeaders, maxRequestLength_);

            WriteResponseHeaders(response, record);
            record.ResponseLength = responseStream.ContentLength;
            record.Response       = await WriteContentAsync(responseStream, record.ResponseHeaders, maxResponseLength_);

            // persist details of the call to durable storage

            await storage_.InsertRecordAsync(record);
        }
コード例 #7
0
 private static void WriteResponseHeaders(IOwinResponse response, HttpEntry record)
 {
     record.StatusCode      = response.StatusCode;
     record.ReasonPhrase    = response.ReasonPhrase;
     record.ResponseHeaders = response.Headers;
 }
コード例 #8
0
 private static void WriteRequestHeaders(IOwinRequest request, HttpEntry record)
 {
     record.Verb           = request.Method;
     record.RequestUri     = request.Uri;
     record.RequestHeaders = request.Headers;
 }
コード例 #9
0
        /// <summary>
        /// Processes the incoming HTTP call and capture details about
        /// the request, the response, the identity of the caller and the
        /// call duration to persistent storage.
        /// </summary>
        /// <param name="context">A reference to the HTTP context.</param>
        /// <returns />
        public async Task Invoke(HttpContext context)
        {
            var request  = context.Request;
            var response = context.Response;

            // capture details about the caller identity

            var identity =
                context.User != null && context.User.Identity.IsAuthenticated ?
                context.User.Identity.Name :
                "(anonymous)"
            ;

            var record = new HttpEntry
            {
                CallerIdentity = identity,
            };

            // replace the request stream in order to intercept downstream reads

            var requestBuffer = new MemoryStream();
            var requestStream = new ContentStream(requestBuffer, request.Body)
            {
                MaxRecordedLength = maxRequestLength_,
            };

            request.Body = requestStream;

            // replace the response stream in order to intercept downstream writes

            var responseBuffer = new MemoryStream();
            var responseStream = new ContentStream(responseBuffer, response.Body)
            {
                MaxRecordedLength = maxResponseLength_,
            };

            response.Body = responseStream;

            // add the "Http-Tracking-Id" response header

            context.Response.OnStarting(OnSendingHeaders, (response, record));

            // invoke the next middleware in the pipeline

            await next_.Invoke(context);

            // rewind the request and response buffers
            // and record their content

            WriteRequestHeaders(context, record);
            record.RequestLength = requestStream.ContentLength;
            record.Request       = await WriteContentAsync(requestStream, record.RequestHeaders, maxRequestLength_);

            WriteResponseHeaders(response, record);
            record.ResponseLength = responseStream.ContentLength;
            record.Response       = await WriteContentAsync(responseStream, record.ResponseHeaders, maxResponseLength_);

            // persist details of the call to durable storage

            await storage_.InsertRecordAsync(record);
        }