Exemple #1
0
 public DuplexStream(InputStream inputStream, OutputStream outputStream)
 {
     _inputStream = inputStream;
     _outputStream = outputStream;
 }
Exemple #2
0
        private CallContext CreateCallContext()
        {
            _inputStream = new InputStream(() =>
            {
                var sender = new InputSender(_context.Services);
                _messageBody.Subscribe(sender.Push);
                return sender;
            });
            _outputStream = new OutputStream(OnWrite, OnFlush);
            _duplexStream = new DuplexStream(_inputStream, _outputStream);

            var remoteIpAddress = "127.0.0.1";
            var remotePort = "0";
            var localIpAddress = "127.0.0.1";
            var localPort = "80";
            var isLocal = false;

            if (_context.Socket != null)
            {
                var remoteEndPoint = _context.Socket.RemoteEndPoint as IPEndPoint;
                if (remoteEndPoint != null)
                {
                    remoteIpAddress = remoteEndPoint.Address.ToString();
                    remotePort = remoteEndPoint.Port.ToString(CultureInfo.InvariantCulture);
                }

                var localEndPoint = _context.Socket.LocalEndPoint as IPEndPoint;
                if (localEndPoint != null)
                {
                    localIpAddress = localEndPoint.Address.ToString();
                    localPort = localEndPoint.Port.ToString(CultureInfo.InvariantCulture);
                }

                if (remoteEndPoint != null && localEndPoint != null)
                {
                    isLocal = Equals(remoteEndPoint.Address, localEndPoint.Address);
                }
            }

            var callContext = new CallContext();
            var request = (IHttpRequestFeature)callContext;
            var response = (IHttpResponseFeature)callContext;
            //var lifetime = (IHttpRequestLifetimeFeature)callContext;
            request.Protocol = _httpVersion;
            request.Scheme = "http";
            request.Method = _method;
            request.Path = _path;
            request.PathBase = "";
            request.QueryString = _queryString;
            request.Headers = _requestHeaders;
            request.Body = _inputStream;
            response.Headers = _responseHeaders;
            response.Body = _outputStream;

            //var env = new Dictionary<string, object>();
            //env["owin.Version"] = "1.0";
            //env["owin.RequestProtocol"] = _httpVersion;
            //env["owin.RequestScheme"] = "http";
            //env["owin.RequestMethod"] = _method;
            //env["owin.RequestPath"] = _path;
            //env["owin.RequestPathBase"] = "";
            //env["owin.RequestQueryString"] = _queryString;
            //env["owin.RequestHeaders"] = _requestHeaders;
            //env["owin.RequestBody"] = _inputStream;
            //env["owin.ResponseHeaders"] = _responseHeaders;
            //env["owin.ResponseBody"] = _outputStream;
            //env["owin.CallCancelled"] = _cts.Token;
            //env["opaque.Upgrade"] = (Action<IDictionary<string, object>, Func<IDictionary<string, object>, Task>>)Upgrade;
            //env["opaque.Stream"] = _duplexStream;
            //env["server.RemoteIpAddress"] = remoteIpAddress;
            //env["server.RemotePort"] = remotePort;
            //env["server.LocalIpAddress"] = localIpAddress;
            //env["server.LocalPort"] = localPort;
            //env["server.IsLocal"] = isLocal;
            return callContext;
        }