Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OwinHttpListenerResponse"/> class.
        /// Sets up the Environment with the necessary request state items.
        /// </summary>
        internal OwinHttpListenerResponse(HttpListenerContext context, CallEnvironment environment)
        {
            _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.OutputStream);

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

            _environment.ResponseHeaders = new ResponseHeadersDictionary(_response);

            _onSendingHeadersActions      = new List <Tuple <Action <object>, object> >();
            _environment.OnSendingHeaders = RegisterForOnSendingHeaders;
        }
Exemplo n.º 2
0
        /// <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(HttpListenerContext context, string basePath, string path, string query, CallEnvironment environment)
        {
            Contract.Requires(context != null);

            _context = context;
            _request = context.Request;
            _environment = environment;

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

            _environment.RequestHeaders = new RequestHeadersDictionary(_request);

            if (_request.IsSecureConnection)
            {
                // TODO: Add delay sync load for folks that directly access the client cert key
                _environment.LoadClientCert = (Func<Task>)LoadClientCert;
            }
        }