private void SnapProperties(HttpRequestMessage httpRequest, IRollbarConfig rollbarConfig) { Assumption.AssertNotNull(httpRequest, nameof(httpRequest)); this.Url = httpRequest.RequestUri?.AbsoluteUri; this.QueryString = httpRequest.RequestUri?.Query; this.Params = null; this.Headers = new Dictionary <string, string>(httpRequest.Headers.Count()); foreach (var header in httpRequest.Headers) { this.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } this.Method = httpRequest.Method.Method; switch (this.Method.ToUpperInvariant()) { case "POST": var task = httpRequest.Content.ReadAsStringAsync(); task.Wait(); this.PostBody = task.Result; this.PostParams = null; break; case "GET": this.GetParams = null; break; default: System.Diagnostics.Trace.WriteLine( $"No-op processing {this.Method.ToUpperInvariant()} HTTP method." ); break; } #if (NETFX) string userIP = null; const string HttpContextProperty = "MS_HttpContext"; const string RemoteEndpointMessagePropery = "System.ServiceModel.Channels.RemoteEndpointMessageProperty"; if (httpRequest.Properties.ContainsKey(HttpContextProperty)) { HttpContextBase ctx = httpRequest.Properties[HttpContextProperty] as HttpContextBase; if (ctx != null) { userIP = ctx.Request.UserHostAddress; } } else if (httpRequest.Properties.ContainsKey(RemoteEndpointMessagePropery)) { RemoteEndpointMessageProperty remoteEndpoint = httpRequest.Properties[RemoteEndpointMessagePropery] as RemoteEndpointMessageProperty; if (remoteEndpoint != null) { userIP = remoteEndpoint.Address; } } this.UserIp = Request.DecideCollectableUserIPValue(userIP, rollbarConfig.IpAddressCollectionPolicy); #endif }
/// <summary> /// Decorates the specified rollbar data. /// </summary> /// <param name="rollbarData">The rollbar data.</param> protected override void Decorate(Data?rollbarData) { if (rollbarData == null) { return; } if (this._httpResponse == null) { return; // nothing to decorate with... } if (rollbarData.Response == null) { rollbarData.Response = new Response(); } rollbarData.Response.StatusCode = this._httpResponse.StatusCode; if (this._httpResponse.Headers?.Count > 0) { rollbarData.Response.Headers = new Dictionary <string, string>(this._httpResponse.Headers.Count); foreach (var header in this._httpResponse.Headers) { rollbarData.Response.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } } AssignResponseBody(rollbarData.Response); }
/// <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; } }
/// <summary> /// Decorates the specified rollbar data. /// </summary> /// <param name="rollbarData">The rollbar data.</param> protected override void Decorate(Data rollbarData) { if (this._httpRequest == null) { return; // nothing to decorate with... } if (rollbarData.Request == null) { rollbarData.Request = new Request(); } rollbarData.Request.Url = this._httpRequest.Host.Value + this._httpRequest.Path; rollbarData.Request.QueryString = this._httpRequest.QueryString.Value; if (!string.IsNullOrWhiteSpace(this._httpRequest.Path)) { rollbarData.Request.Params = new Dictionary <string, object>(); rollbarData.Request.Params["path"] = this._httpRequest.Path; } if (this._httpRequest.Headers?.Count > 0) { rollbarData.Request.Headers = new Dictionary <string, string>(this._httpRequest.Headers.Count); foreach (var header in this._httpRequest.Headers) { rollbarData.Request.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } } rollbarData.Request.Method = this._httpRequest.Method; switch (rollbarData.Request.Method.ToUpper()) { case "POST": AssignRequestBody(rollbarData); break; case "GET": if (this._httpRequest.Query?.Count > 0) { rollbarData.Request.GetParams = new Dictionary <string, object>(this._httpRequest.Query.Count); foreach (var kv in this._httpRequest.Query) { rollbarData.Request.GetParams[kv.Key] = kv.Value; } } break; default: // nothing to do... break; } }
private void SnapProperties(HttpRequest httpRequest) { Assumption.AssertNotNull(httpRequest, nameof(httpRequest)); this.Url = httpRequest.Host.Value + httpRequest.Path; this.QueryString = httpRequest.QueryString.Value; this.Params = null; this.Headers = new Dictionary <string, string>(httpRequest.Headers.Count()); foreach (var header in httpRequest.Headers) { this.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } this.Method = httpRequest.Method; }
private void SnapProperties(RollbarHttpAttributes httpContext) { Assumption.AssertNotNull(httpContext, nameof(httpContext)); this.Url = httpContext.Host.Value + httpContext.Path; this.QueryString = httpContext.Query.Value; this.Params = null; this.Headers = new Dictionary <string, string>(httpContext.Headers.Count()); foreach (var header in httpContext.Headers) { if (header.Value.Count() == 0) { continue; } this.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } this.Method = httpContext.Method; }
/// <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; } }
/// <summary> /// Decorates the specified rollbar data. /// </summary> /// <param name="rollbarData">The rollbar data.</param> protected override void Decorate(Data rollbarData) { if (this._httpRequest == null) { return; // nothing to decorate with... } if (rollbarData.Request == null) { rollbarData.Request = new Request(); } rollbarData.Request.Url = this._httpRequest.Host.Value + this._httpRequest.Path; rollbarData.Request.QueryString = this._httpRequest.QueryString.Value; rollbarData.Request.Params = null; rollbarData.Request.Headers = new Dictionary <string, string>(this._httpRequest.Headers.Count); foreach (var header in this._httpRequest.Headers) { rollbarData.Request.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } rollbarData.Request.Method = this._httpRequest.Method; switch (rollbarData.Request.Method.ToUpper()) { case "POST": this._httpRequest.Body.Seek(0, SeekOrigin.Begin); rollbarData.Request.PostBody = GetBodyAsString(this._httpRequest); break; case "GET": default: // nothing to do... break; } }
/// <summary> /// Decorates the specified rollbar data. /// </summary> /// <param name="rollbarData">The rollbar data.</param> protected override void Decorate(Data rollbarData) { if (this._httpRequestMessage == null) { return; // there is nothing to decorate with... } if (rollbarData.Request == null) { rollbarData.Request = new Request(this._arbitraryKeyValuePairs); } rollbarData.Request.Url = this._httpRequestMessage.RequestUri?.AbsoluteUri; rollbarData.Request.QueryString = this._httpRequestMessage.RequestUri?.Query; rollbarData.Request.Params = null; rollbarData.Request.Headers = new Dictionary <string, string>(this._httpRequestMessage.Headers.Count()); foreach (var header in this._httpRequestMessage.Headers) { rollbarData.Request.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } rollbarData.Request.Method = this._httpRequestMessage.Method.Method; switch (rollbarData.Request.Method.ToUpperInvariant()) { case "POST": var task = this._httpRequestMessage.Content.ReadAsStringAsync(); task.Wait(); rollbarData.Request.PostBody = task.Result; rollbarData.Request.PostParams = null; break; case "GET": rollbarData.Request.GetParams = null; break; default: traceSource.TraceInformation( $"No-op processing {rollbarData.Request.Method.ToUpperInvariant()} HTTP method." ); break; } #if (NETFX) if (this._rollbarConfig == null) { return; } string userIP = null; const string HttpContextProperty = "MS_HttpContext"; const string RemoteEndpointMessagePropery = "System.ServiceModel.Channels.RemoteEndpointMessageProperty"; if (this._httpRequestMessage.Properties.ContainsKey(HttpContextProperty)) { HttpContextBase ctx = this._httpRequestMessage.Properties[HttpContextProperty] as HttpContextBase; if (ctx != null) { userIP = ctx.Request.UserHostAddress; } } else if (this._httpRequestMessage.Properties.ContainsKey(RemoteEndpointMessagePropery)) { RemoteEndpointMessageProperty remoteEndpoint = this._httpRequestMessage.Properties[RemoteEndpointMessagePropery] as RemoteEndpointMessageProperty; if (remoteEndpoint != null) { userIP = remoteEndpoint.Address; } } rollbarData.Request.UserIp = HttpRequestMessagePackageDecorator.DecideCollectableUserIPValue(userIP, this._rollbarConfig.IpAddressCollectionPolicy); #endif }
/// <summary> /// Decorates the specified rollbar data. /// </summary> /// <param name="rollbarData">The rollbar data.</param> protected override void Decorate(Data rollbarData) { if (this._rollbarHttpContext == null) { return; //nothing to decorate with... } Dictionary <string, object> customRequestFields = null; if (this._rollbarHttpContext != null) { customRequestFields = new Dictionary <string, object>(); customRequestFields.Add("httpRequestTimestamp", this._rollbarHttpContext.Timestamp); if (this._rollbarHttpContext.HttpAttributes != null) { customRequestFields.Add("httpRequestID", this._rollbarHttpContext.HttpAttributes.RequestID); customRequestFields.Add("statusCode", this._rollbarHttpContext.HttpAttributes.StatusCode); customRequestFields.Add("scheme", this._rollbarHttpContext.HttpAttributes.Scheme); customRequestFields.Add("protocol", this._rollbarHttpContext.HttpAttributes.Protocol); } } if (customRequestFields != null && customRequestFields.Count > 0) { if (rollbarData.Request == null) { rollbarData.Request = new Request(customRequestFields); } else { foreach (var item in customRequestFields) { rollbarData.Request.Add(item); } } } if (this._rollbarHttpContext.HttpAttributes != null) { if (rollbarData.Request == null) { rollbarData.Request = new Request(); } rollbarData.Request.Url = this._rollbarHttpContext.HttpAttributes.Host.Value + this._rollbarHttpContext.HttpAttributes.Path; rollbarData.Request.QueryString = this._rollbarHttpContext.HttpAttributes.Query.Value; rollbarData.Request.Params = null; rollbarData.Request.Headers = new Dictionary <string, string>(this._rollbarHttpContext.HttpAttributes.Headers.Count); foreach (var header in this._rollbarHttpContext.HttpAttributes.Headers) { if (header.Value.Count == 0) { continue; } rollbarData.Request.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } rollbarData.Request.Method = this._rollbarHttpContext.HttpAttributes.Method; } }
private static string DetectTargetFrameworks() { var targetFrameworks = RuntimeEnvironmentUtility.GetAssemblyTargetFrameworks(typeof(Data)); return(StringUtility.Combine(targetFrameworks, "; ")); }