public void CreateEnvironment()
        {
            // Note, simple or expensive fields are delay loaded internally.
            // e.g. the first access to _httpRequest.ServerVariables[...] is extremely slow
            _env = new AspNetDictionary(this);

            _env.OwinVersion = Constants.OwinVersion;

            _env.RequestPathBase = _requestPathBase;
            _env.RequestPath     = _requestPath;
            _env.RequestMethod   = _httpRequest.HttpMethod;
            _env.RequestHeaders  = new AspNetRequestHeaders(_httpRequest.Headers);

            _env.ResponseHeaders = new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase);

            _env.OnSendingHeaders = _sendingHeadersEvent.Register;
            _env.SendFileAsync    = SendFileAsync;

            _env.HostTraceOutput = TraceTextWriter.Instance;
            _env.HostAppName     = LazyInitializer.EnsureInitialized(ref _hostAppName,
                                                                     () => HostingEnvironment.SiteName ?? new Guid().ToString());

            _env.DisableResponseCompression = DisableResponseCompression;
            _env.ServerCapabilities         = _appContext.Capabilities;

            _env.RequestContext  = _requestContext;
            _env.HttpContextBase = _httpContext;

            _httpContext.Items[HttpContextItemKeys.OwinEnvironmentKey] = _env;
        }
Esempio n. 2
0
        public AspNetEnvironmentTests()
        {
            var appContext = new OwinAppContext();

            appContext.Initialize(_ => { });
            var             requestContext = new RequestContext(new FakeHttpContextEx(), new RouteData());
            OwinCallContext callContext    = appContext.CreateCallContext(requestContext, string.Empty, string.Empty, null, null);

            callContext.Execute();
            _env = _aspNetDictionary = callContext.Environment;
        }
Esempio n. 3
0
        private static string GetWebSocketSubProtocol(AspNetDictionary env, IDictionary <string, object> accpetOptions)
        {
            IDictionary <string, string[]> reponseHeaders = env.ResponseHeaders;

            // Remove the sub-protocol header, Accept will re-add it.
            string subProtocol = null;

            string[] subProtocols;
            if (reponseHeaders.TryGetValue(WebSocketConstants.SecWebSocketProtocol, out subProtocols) && subProtocols.Length > 0)
            {
                subProtocol = subProtocols[0];
                reponseHeaders.Remove(WebSocketConstants.SecWebSocketProtocol);
            }

            if (accpetOptions != null && accpetOptions.ContainsKey(WebSocketConstants.WebSocketSubProtocolKey))
            {
                subProtocol = accpetOptions.Get <string>(WebSocketConstants.WebSocketSubProtocolKey);
            }

            return(subProtocol);
        }
        public void CreateEnvironment()
        {
            // Mitigate double registered modules, and also allow the env to be shared between integrated pipeline and
            // owin based handlers.
            if (_httpContext.Items.Contains(HttpContextItemKeys.OwinEnvironmentKey))
            {
                _env = _httpContext.Items[HttpContextItemKeys.OwinEnvironmentKey] as AspNetDictionary;
                System.Diagnostics.Debug.Assert(_env != null, "Environment type mismatch, "
                                                + _httpContext.Items[HttpContextItemKeys.OwinEnvironmentKey]);
                return;
            }

            // Note, simple or expensive fields are delay loaded internally.
            // e.g. the first access to _httpRequest.ServerVariables[...] is extremely slow
            _env = new AspNetDictionary(this);

            _env.OwinVersion = Constants.OwinVersion;

            _env.RequestPathBase = _requestPathBase;
            _env.RequestPath     = _requestPath;
            _env.RequestMethod   = _httpRequest.HttpMethod;
            _env.RequestHeaders  = new AspNetRequestHeaders(_httpRequest);
            _env.ResponseHeaders = new AspNetResponseHeaders(_httpResponse);

            _env.OnSendingHeaders = _sendingHeadersEvent.Register;

            _env.HostTraceOutput = TraceTextWriter.Instance;
            _env.HostAppName     = LazyInitializer.EnsureInitialized(ref _hostAppName,
                                                                     () => HostingEnvironment.SiteName ?? new Guid().ToString());

            _env.DisableResponseCompression = DisableResponseCompression;
            _env.ServerCapabilities         = _appContext.Capabilities;

            _env.RequestContext  = _requestContext;
            _env.HttpContextBase = _httpContext;

            _httpContext.Items[HttpContextItemKeys.OwinEnvironmentKey] = _env;
        }
        public IDictionary <string, object> GetInitialEnvironment(HttpApplication application)
        {
            if (_state.CallContext != null)
            {
                return(_state.CallContext.Environment);
            }

            string requestPath = application.Request.AppRelativeCurrentExecutionFilePath.Substring(1) + application.Request.PathInfo;

            _state.CallContext = _blueprint.AppContext.CreateCallContext(
                application.Request.RequestContext,
                _blueprint.PathBase,
                requestPath,
                null,
                null);

            _state.CallContext.CreateEnvironment();

            AspNetDictionary environment = _state.CallContext.Environment;

            environment.IntegratedPipelineContext = this;
            return(environment);
        }