public LogRequest(string message, string logger, string level, DateTime utcDate, string jsonMessage, LogRequestBase logRequestBase) : base(logRequestBase) { Message = message; Logger = logger; Level = level; UtcDate = utcDate; JsonMessage = jsonMessage; }
public LogRequestBase(LogRequestBase other) { UserAgent = other.UserAgent; UserHostAddress = other.UserHostAddress; RequestId = other.RequestId; Url = other.Url; QueryParameters = other.QueryParameters; Cookies = other.Cookies; Headers = other.Headers; }
private void ProcessRequest(HttpContext context) { var headers = ToDictionary(context.Request.Headers); string urlReferrer = headers.SafeGet("Referer"); string url = context.Request.GetDisplayUrl(); var logRequestBase = new LogRequestBase( userAgent: headers.SafeGet("User-Agent"), userHostAddress: context.GetUserIp(), requestId: context.GetLogRequestId(), url: (urlReferrer ?? url).ToString(), queryParameters: ToDictionary(context.Request.Query), cookies: ToDictionary(context.Request.Cookies), headers: headers); DateTime serverSideTimeUtc = DateTime.UtcNow; string httpMethod = context.Request.Method; string origin = headers.SafeGet("Origin"); Encoding encoding = HttpHelpers.GetEncoding(headers.SafeGet("Content-Type")); string json; using (var reader = new StreamReader(context.Request.Body, encoding)) { json = reader.ReadToEnd(); } var response = new LogResponse(); LoggerProcessor.ProcessLogRequest(json, logRequestBase, serverSideTimeUtc, httpMethod, origin, response); // Send dummy response. That way, the log request will not remain "pending" // in eg. Chrome dev tools. // // This must be given a MIME type of "text/plain" // Otherwise, the browser may try to interpret the empty string as XML. // When the user uses Firefox, and right clicks on the page and chooses "Inspect Element", // then in that debugger's console it will say "no element found". // See // http://www.acnenomor.com/307387p1/how-do-i-setup-my-ajax-post-request-to-prevent-no-element-found-on-empty-response // http://stackoverflow.com/questions/975929/firefox-error-no-element-found/976200#976200 ToAspNet5Response(response, context.Response); context.Response.ContentType = "text/plain"; context.Response.ContentLength = 0; }
private void ProcessRequest(IOwinContext context) { var headers = ToDictionary(context.Request.Headers); string urlReferrer = headers.SafeGet("Referer"); string url = context.Request.Uri.OriginalString; var logRequestBase = new LogRequestBase( userAgent: headers.SafeGet("User-Agent"), userHostAddress: context.Request.RemoteIpAddress, requestId: headers.GetLogRequestId(), url: (urlReferrer ?? url).ToString(), queryParameters: ToDictionary(context.Request.Query), cookies: Utils.ToDictionary(context.Request.Cookies), headers: headers); DateTime serverSideTimeUtc = DateTime.UtcNow; string httpMethod = context.Request.Method; string origin = headers.SafeGet("Origin"); Encoding encoding = HttpHelpers.GetEncoding(headers.SafeGet("Content-Type")); string json; using (var reader = new StreamReader(context.Request.Body, encoding)) { json = reader.ReadToEnd(); } var response = new LogResponse(); LoggerProcessor.ProcessLogRequest(json, logRequestBase, serverSideTimeUtc, httpMethod, origin, response); // Send dummy response. That way, the log request will not remain "pending" // in eg. Chrome dev tools. // // This must be given a MIME type of "text/plain" // Otherwise, the browser may try to interpret the empty string as XML. // When the user uses Firefox, and right clicks on the page and chooses "Inspect Element", // then in that debugger's console it will say "no element found". // See // http://www.acnenomor.com/307387p1/how-do-i-setup-my-ajax-post-request-to-prevent-no-element-found-on-empty-response // http://stackoverflow.com/questions/975929/firefox-error-no-element-found/976200#976200 ToOwinResponse(response, context.Response); context.Response.ContentType = "text/plain"; context.Response.ContentLength = 0; }
public void ProcessRequest(HttpContext context) { var logRequestBase = new LogRequestBase( userAgent: context.Request.UserAgent, userHostAddress: context.GetUserIp(), requestId: context.GetLogRequestId(), url: (context.Request.UrlReferrer ?? context.Request.Url).ToString(), queryParameters: Utils.ToDictionary(context.Request.QueryString), cookies: ToDictionary(context.Request.Cookies), headers: Utils.ToDictionary(context.Request.Headers)); DateTime serverSideTimeUtc = DateTime.UtcNow; string httpMethod = context.Request.HttpMethod; string origin = context.Request.Headers["Origin"]; string json; using (var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding)) { json = reader.ReadToEnd(); } var logResponse = new LogResponse(); LoggerProcessor.ProcessLogRequest(json, logRequestBase, serverSideTimeUtc, httpMethod, origin, logResponse); // Send dummy response. That way, the log request will not remain "pending" // in eg. Chrome dev tools. // // This must be given a MIME type of "text/plain" // Otherwise, the browser may try to interpret the empty string as XML. // When the user uses Firefox, and right clicks on the page and chooses "Inspect Element", // then in that debugger's console it will say "no element found". // See // http://www.acnenomor.com/307387p1/how-do-i-setup-my-ajax-post-request-to-prevent-no-element-found-on-empty-response // http://stackoverflow.com/questions/975929/firefox-error-no-element-found/976200#976200 HttpResponse httpResponse = context.Response; ToHttpResponse(logResponse, httpResponse); httpResponse.ContentType = "text/plain"; httpResponse.ClearContent(); httpResponse.Write(""); }