Пример #1
0
        // Token: 0x060005F7 RID: 1527 RVA: 0x00021A78 File Offset: 0x0001FC78
        private void OnBeginRequest(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            CheckpointTracker.GetOrCreate(httpContext.Items).Add(FrontEndHttpProxyCheckpoints.ProxyModuleBeginRequest);
            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                LatencyTracker latencyTracker = new LatencyTracker();
                latencyTracker.StartTracking(LatencyTrackerKey.ProxyModuleLatency, false);
                AspNetHelper.AddTimestampHeaderIfNecessary(httpContext.Request.Headers, "X-FrontEnd-Begin");
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <string, Uri, int>((long)this.GetHashCode(), "[ProxyModule::OnBeginRequest]: Method {0}; Url {1}; Context {2};", httpContext.Request.HttpMethod, httpContext.Request.Url, httpContext.GetHashCode());
                }
                if (HealthCheckResponder.Instance.IsHealthCheckRequest(httpContext))
                {
                    HealthCheckResponder.Instance.CheckHealthStateAndRespond(httpContext);
                    return;
                }
                RequestDetailsLogger requestDetailsLogger = RequestDetailsLoggerBase <RequestDetailsLogger> .InitializeRequestLogger();
                requestDetailsLogger.LogCurrentTime("BeginRequest");
                httpContext.Items[Constants.TraceContextKey] = httpContext.GetHashCode();
                httpContext.Items[Constants.LatencyTrackerContextKeyName] = latencyTracker;
                requestDetailsLogger.ActivityScope.UpdateFromMessage(httpContext.Request);
                requestDetailsLogger.ActivityScope.SerializeTo(httpContext.Response);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SetCurrent(httpContext, requestDetailsLogger);
                httpContext.Items[typeof(ActivityScope)] = requestDetailsLogger.ActivityScope;
                httpContext.Items[Constants.RequestIdHttpContextKeyName] = requestDetailsLogger.ActivityScope.ActivityId;
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 6, HttpProxyGlobals.ProtocolType);
                requestDetailsLogger.SafeLogUriData(httpContext.Request.Url);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 6, httpContext.Request.HttpMethod);
                string requestCorrelationId = AspNetHelper.GetRequestCorrelationId(httpContext);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestDetailsLogger, "CorrelationID", requestCorrelationId);
                httpContext.Response.AppendToLog(Constants.CorrelationIdKeyForIISLogs + requestCorrelationId + ";");
                UrlUtilities.SaveOriginalRequestHostSchemePortToContext(SharedHttpContextWrapper.GetWrapper(httpContext));
                try
                {
                    this.OnBeginRequestInternal(httpApplication);
                }
                catch (Exception ex)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(requestDetailsLogger, "OnBeginRequestInternal", ex.ToString());
                    requestDetailsLogger.AsyncCommit(false, false);
                    throw;
                }
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
Пример #2
0
        // Token: 0x060005FA RID: 1530 RVA: 0x00021B74 File Offset: 0x0001FD74
        private void OnPreSendRequestHeaders(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            CheckpointTracker.GetOrCreate(httpContext.Items).Add(FrontEndHttpProxyCheckpoints.ProxyModulePreSendRequestHeaders);
            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                if (httpContext != null && httpContext.Response != null && httpContext.Response.Headers != null)
                {
                    AspNetHelper.AddTimestampHeaderIfNecessary(httpContext.Response.Headers, "X-FrontEnd-End");
                    RequestDetailsLogger current = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext);
                    if (current != null && !current.IsDisposed)
                    {
                        this.SetResponseHeaders(current, httpContext);
                    }
                    if (Extensions.IsProbeRequest(Extensions.GetHttpRequestBase(httpContext.Request)) && !RequestFailureContext.IsSetInResponse(SharedHttpContextWrapper.GetWrapper(httpContext).Response))
                    {
                        RequestFailureContext requestFailureContext = null;
                        if (httpContext.Items.Contains(RequestFailureContext.HttpContextKeyName))
                        {
                            requestFailureContext = (RequestFailureContext)httpContext.Items[RequestFailureContext.HttpContextKeyName];
                        }
                        else if (httpContext.Response.StatusCode >= 400 && httpContext.Response.StatusCode < 600)
                        {
                            LiveIdAuthResult?liveIdAuthResult = null;
                            LiveIdAuthResult value;
                            if (httpContext.Items.Contains("LiveIdBasicAuthResult") && Enum.TryParse <LiveIdAuthResult>((string)httpContext.Items["LiveIdBasicAuthResult"], true, out value))
                            {
                                liveIdAuthResult = new LiveIdAuthResult?(value);
                            }
                            requestFailureContext = new RequestFailureContext(1, httpContext.Response.StatusCode, httpContext.Response.StatusDescription, string.Empty, null, null, liveIdAuthResult);
                        }
                        if (requestFailureContext != null)
                        {
                            requestFailureContext.UpdateResponse(SharedHttpContextWrapper.GetWrapper(httpContext).Response);
                        }
                    }
                    ProxyRequestHandler proxyRequestHandler = httpContext.CurrentHandler as ProxyRequestHandler;
                    if (proxyRequestHandler != null)
                    {
                        proxyRequestHandler.ResponseHeadersSent = true;
                    }
                }
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
Пример #3
0
        // Token: 0x060005EF RID: 1519 RVA: 0x00020FF0 File Offset: 0x0001F1F0
        protected virtual void OnPostAuthorizeInternal(HttpApplication httpApplication)
        {
            HttpContext context = httpApplication.Context;

            if (NativeProxyHelper.CanNativeProxyHandleRequest(SharedHttpContextWrapper.GetWrapper(context)))
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(context), "ProxyRequestHandler", "NativeHttpProxy");

                return;
            }
            IHttpHandler httpHandler;

            if (context.Request.IsAuthenticated)
            {
                httpHandler = this.SelectHandlerForAuthenticatedRequest(context);
            }
            else
            {
                httpHandler = this.SelectHandlerForUnauthenticatedRequest(context);
            }
            if (httpHandler != null)
            {
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <Type, object>((long)this.GetHashCode(), "[ProxyModule::OnPostAuthorizeInternal]: The selected HttpHandler is {0}; Context {1};", httpHandler.GetType(), context.Items[Constants.TraceContextKey]);
                }
                PerfCounters.HttpProxyCountersInstance.TotalRequests.Increment();
                if (httpHandler is ProxyRequestHandler)
                {
                    ((ProxyRequestHandler)httpHandler).Run(context);
                }
                else
                {
                    context.RemapHandler(httpHandler);
                }
                long currentLatency = LatencyTracker.FromHttpContext(context).GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency);
                if (currentLatency > 100L)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(context), "RemapHandler", currentLatency);
                }
            }
        }
Пример #4
0
        // Token: 0x060005FB RID: 1531 RVA: 0x00021BD8 File Offset: 0x0001FDD8
        private void OnEndRequest(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            CheckpointTracker.GetOrCreate(httpContext.Items).Add(FrontEndHttpProxyCheckpoints.ProxyModuleEndRequest);
            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                if (!HostHeaderValidator.HasValidHostHeaderStatusDescription(new HttpContextWrapper(httpContext).Response) || httpContext.Items["AutodiscoverRedirectModule"] != null)
                {
                    return;
                }
                LatencyTracker latencyTracker = LatencyTracker.FromHttpContext(httpContext);
                RequestDetailsLogger current  = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext), GuardedSharedCacheExecution.Default.Key, GuardedSharedCacheExecution.Default.Guard.GetCurrentValue());
                int traceContext = httpContext.GetTraceContext();
                if (httpContext.Response != null && current != null)
                {
                    httpContext.Response.AppendToLog(Constants.RequestIdKeyForIISLogs + current.ActivityId.ToString() + ";");
                }
                if (HealthCheckResponder.Instance.IsHealthCheckRequest(httpContext))
                {
                    return;
                }
                if (httpContext.Response.StatusCode == 404 && httpContext.Response.SubStatusCode == 13)
                {
                    httpContext.Response.StatusCode = 507;
                }
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[ProxyModule::OnEndRequest]: Method {0}; Url {1}; Username {2}; Context {3};", new object[]
                    {
                        httpContext.Request.HttpMethod,
                        httpContext.Request.Url,
                        (httpContext.User == null) ? string.Empty : IIdentityExtensions.GetSafeName(httpContext.User.Identity, true),
                        traceContext
                    });
                }
                if (latencyTracker != null)
                {
                    long currentLatency = latencyTracker.GetCurrentLatency(LatencyTrackerKey.HandlerToModuleSwitchingLatency);
                    if (currentLatency >= 0L)
                    {
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(current, 5, currentLatency);
                    }
                }
                ProxyRequestHandler proxyRequestHandler = httpContext.CurrentHandler as ProxyRequestHandler;
                if (proxyRequestHandler != null && !proxyRequestHandler.IsDisposed)
                {
                    current.AppendGenericInfo("DisposeProxyRequestHandler", "ProxyModule::OnEndRequest");
                    proxyRequestHandler.Dispose();
                }
                ProxyModule.InspectNativeProxyFatalError(httpContext.Response, current);
                string text = httpContext.Items["AnonymousRequestFilterModule"] as string;
                if (!string.IsNullOrEmpty(text))
                {
                    current.AppendGenericInfo("AnonymousRequestFilterModule", text);
                }
                try
                {
                    this.OnEndRequestInternal(httpApplication);
                }
                finally
                {
                    if (current != null && !current.IsDisposed)
                    {
                        IActivityScope activityScope = current.ActivityScope;
                        if (activityScope != null)
                        {
                            if (!string.IsNullOrEmpty(activityScope.TenantId))
                            {
                                httpContext.Items["AuthenticatedUserOrganization"] = activityScope.TenantId;
                            }
                            ProxyModule.FinalizeRequestLatencies(httpContext, current, activityScope, latencyTracker, traceContext);
                        }
                        current.LogCurrentTime("EndRequest");
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(current, 0, DateTime.UtcNow);
                        current.AsyncCommit(false, NativeProxyHelper.WasProxiedByNativeProxyHandler(SharedHttpContextWrapper.GetWrapper(httpContext)));
                    }
                    if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                    {
                        ExTraceGlobals.VerboseTracer.TraceDebug(0L, "[ProxyModule::OnEndRequest]: Method {0}; Url {1}; OnEndRequestLatency {2}; Context {3};", new object[]
                        {
                            httpContext.Request.HttpMethod,
                            httpContext.Request.Url,
                            (latencyTracker != null) ? latencyTracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency).ToString() : "Unknown",
                            traceContext
                        });
                    }
                }
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
Пример #5
0
        // Token: 0x060005F2 RID: 1522 RVA: 0x00021190 File Offset: 0x0001F390
        private static void FinalizeRequestLatencies(HttpContext httpContext, RequestDetailsLogger requestDetailsLogger, IActivityScope activityScope, LatencyTracker tracker, int traceContext)
        {
            if (tracker == null)
            {
                return;
            }
            if (requestDetailsLogger == null)
            {
                throw new ArgumentNullException("requestDetailsLogger");
            }
            if (activityScope == null)
            {
                throw new ArgumentNullException("activityScope");
            }
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            HttpContextBase wrapper = SharedHttpContextWrapper.GetWrapper(httpContext);
            long            num     = tracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency);

            if (num >= 0L)
            {
                long num2 = 0L;
                long.TryParse(activityScope.GetProperty(6), out num2);
                long num3 = 0L;
                bool flag = requestDetailsLogger.TryGetLatency(37, ref num3);
                long num4 = requestDetailsLogger.GetLatency(34, 0L) + requestDetailsLogger.GetLatency(36, 0L) + num3 + requestDetailsLogger.GetLatency(39, 0L) + requestDetailsLogger.GetLatency(40, 0L);
                long num5 = num - num4;
                if (!NativeProxyHelper.WasProxiedByNativeProxyHandler(wrapper))
                {
                    PerfCounters.UpdateMovingAveragePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingAverageCasLatency, num5);
                }
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 43, num5);

                long num6 = num5 - num2;
                if (flag)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 42, Math.Max(num6, 0L));

                    string property = activityScope.GetProperty(13);
                    if (PerfCounters.RoutingLatenciesEnabled && !string.IsNullOrEmpty(property))
                    {
                        string empty = string.Empty;
                        Utilities.TryExtractForestFqdnFromServerFqdn(property, ref empty);
                        PercentilePerfCounters.UpdateRoutingLatencyPerfCounter(empty, (double)num6);
                        PerfCounters.GetHttpProxyPerForestCountersInstance(empty).TotalProxyWithLatencyRequests.Increment();
                    }
                }
                long val = num6 - requestDetailsLogger.GetLatency(35, 0L) - requestDetailsLogger.GetLatency(38, 0L);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 41, Math.Max(val, 0L));

                long currentLatency = tracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency);
                long num7           = currentLatency - num;
                num = currentLatency;
                if (num7 > 5L)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestDetailsLogger, "TotalRequestTimeDelta", num7);
                }
            }
            RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 16, num);
        }