Exemplo n.º 1
0
        internal OwinHttpListenerContext(RequestContext requestContext,
                                         string basePath, string path, string query, DisconnectHandler disconnectHandler)
        {
            _requestContext    = requestContext;
            _environment       = new CallEnvironment(this);
            _owinRequest       = new OwinHttpListenerRequest(_requestContext.Request, basePath, path, query, _environment);
            _owinResponse      = new OwinHttpListenerResponse(_requestContext, _environment);
            _disconnectHandler = disconnectHandler;

            _environment.OwinVersion = Constants.OwinVersion;

            SetServerUser(_requestContext.User);
            _environment.RequestContext = _requestContext;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OwinHttpListenerRequest"/> class.
        /// Uses the given request object to populate the OWIN standard keys in the environment IDictionary.
        /// Most values are copied so that they can be mutable, but the headers collection is only wrapped.
        /// </summary>
        internal OwinHttpListenerRequest(Request request, string basePath, string path, string query, CallEnvironment environment)
        {
            Contract.Requires(request != null);

            _request     = request;
            _environment = environment;

            _environment.RequestProtocol    = GetProtocol(request.ProtocolVersion);
            _environment.RequestScheme      = request.IsHttps ? Uri.UriSchemeHttps : Uri.UriSchemeHttp;
            _environment.RequestMethod      = request.Method;
            _environment.RequestPathBase    = basePath;
            _environment.RequestPath        = path;
            _environment.RequestQueryString = query;
            //_environment.RequestId = request.RequestTraceIdentifier.ToString();

            _environment.RequestHeaders = new RequestHeadersDictionary(request);

            if (_request.IsHttps)
            {
                // TODO: Add delay sync load for folks that directly access the client cert key
                _environment.LoadClientCert = (Func <Task>)LoadClientCertAsync;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OwinHttpListenerResponse"/> class.
        /// Sets up the Environment with the necessary request state items.
        /// </summary>
        internal OwinHttpListenerResponse(RequestContext context, CallEnvironment environment)
        {
            Contract.Requires(context != null);
            Contract.Requires(environment != null);
            _context     = context;
            _response    = _context.Response;
            _environment = environment;

            _requestState = RequestInProgress;

            // Provide the default status code for consistency with SystemWeb, even though it's optional.
            _environment.ResponseStatusCode = (int)HttpStatusCode.OK; // 200

            var outputStream = new HttpListenerStreamWrapper(_response.Body);

            outputStream.OnFirstWrite(s_responseBodyStarted, this);
            _environment.ResponseBody = outputStream;

            _environment.ResponseHeaders = new ResponseHeadersDictionary(_response);

            _onSendingHeadersActions      = new List <Tuple <Action <object>, object> >();
            _environment.OnSendingHeaders = RegisterForOnSendingHeaders;
        }