예제 #1
0
        /// <summary>
        /// Collects the request specific attributes.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <param name="rollbarHttpAttributes">
        /// The rollbar HTTP attributes.
        /// </param>
        private static void Collect(Request request, RollbarHttpAttributes rollbarHttpAttributes)
        {
            request.Url =
                rollbarHttpAttributes.RequestHost.Value + rollbarHttpAttributes.RequestPath;
            request.QueryString =
                rollbarHttpAttributes.RequestQuery.Value;
            request.Params = null;
            request.Method = rollbarHttpAttributes.RequestMethod;
            if (rollbarHttpAttributes.RequestHeaders?.Count > 0)
            {
                request.Headers =
                    new Dictionary <string, string>(rollbarHttpAttributes.RequestHeaders.Count);
                foreach (var header in rollbarHttpAttributes.RequestHeaders)
                {
                    if (header.Value.Count == 0)
                    {
                        continue;
                    }

                    request.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", "));
                }
            }
            if (!string.IsNullOrWhiteSpace(rollbarHttpAttributes.RequestBody))
            {
                request.PostBody = rollbarHttpAttributes.RequestBody;
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarHttpAttributes" /> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public RollbarHttpAttributes(HttpContext?context)
        {
            // as we learned from a field issue,
            // apparently a middleware can be invoked without a valid HttPContext:
            if (context == null)
            {
                return;
            }

            this._httpContext = context;

            this.RequestID = context.Features?
                             .Get <IHttpRequestIdentifierFeature>()?
                             .TraceIdentifier;

            if (context.Request != null)
            {
                this.RequestHost     = context.Request.Host;
                this.RequestPath     = context.Request.Path;
                this.RequestHeaders  = context.Request.Headers;
                this.RequestMethod   = context.Request.Method;
                this.RequestQuery    = context.Request.QueryString;
                this.RequestProtocol = context.Request.Protocol;
                this.RequestScheme   = context.Request.Scheme;
                this.RequestBody     = RollbarHttpAttributes.CaptureRequestBody(context.Request);
            }

            if (context.Response != null)
            {
                this.ResponseStatusCode = context.Response.StatusCode;
                this.ResponseHeaders    = context.Response.Headers;
            }
        }
예제 #3
0
        /// <summary>
        /// Collects the response specific attributes.
        /// </summary>
        /// <param name="response">
        /// The response.
        /// </param>
        /// <param name="rollbarHttpAttributes">
        /// The rollbar HTTP attributes.
        /// </param>
        private static void Collect(Response response, RollbarHttpAttributes rollbarHttpAttributes)
        {
            response.StatusCode = rollbarHttpAttributes.ResponseStatusCode;
            if (rollbarHttpAttributes.ResponseHeaders?.Count > 0)
            {
                response.Headers =
                    new Dictionary <string, string>(rollbarHttpAttributes.ResponseHeaders.Count);
                foreach (var header in rollbarHttpAttributes.ResponseHeaders)
                {
                    if (header.Value.Count == 0)
                    {
                        continue;
                    }

                    response.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", "));
                }
            }
            if (!string.IsNullOrWhiteSpace(rollbarHttpAttributes.ResponseBody))
            {
                response.Body = rollbarHttpAttributes.ResponseBody;
            }
        }