Exemple #1
0
        public OwinContext(
            PeerCast peerCast,
            HttpRequest req,
            ConnectionStream stream,
            IPEndPoint localEndPoint,
            IPEndPoint remoteEndPoint,
            AccessControlInfo accessControlInfo)
        {
            Environment      = new OwinEnvironment();
            ConnectionStream = stream;
            RequestBody      = new OwinRequestBodyStream(this, ConnectionStream);
            ResponseBody     = new OwinResponseBodyStream(this, ConnectionStream);
            Environment.Environment[OwinEnvironment.Owin.Version]     = "1.0.1";
            Environment.Environment[OwinEnvironment.Host.TraceOutput] = TextWriter.Null;
            Environment.Environment[OwinEnvironment.Owin.RequestBody] = RequestBody;
            var requestHeaders = req.Headers.ToDictionary();

            if (!requestHeaders.TryGetValue("Host", out var values) || values.Length == 0 || String.IsNullOrEmpty(values[0]))
            {
                requestHeaders["Host"] = new string[] { localEndPoint.ToString() };
            }
            Environment.Environment[OwinEnvironment.Owin.RequestHeaders]               = requestHeaders;
            Environment.Environment[OwinEnvironment.Owin.RequestPath]                  = req.Path;
            Environment.Environment[OwinEnvironment.Owin.RequestPathBase]              = "";
            Environment.Environment[OwinEnvironment.Owin.RequestProtocol]              = req.Protocol;
            Environment.Environment[OwinEnvironment.Owin.RequestQueryString]           = req.QueryString;
            Environment.Environment[OwinEnvironment.Owin.RequestScheme]                = "http";
            Environment.Environment[OwinEnvironment.Owin.RequestMethod]                = req.Method;
            Environment.Environment[OwinEnvironment.Owin.ResponseBody]                 = ResponseBody;
            Environment.Environment[OwinEnvironment.Owin.ResponseHeaders]              = new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase);
            Environment.Environment[OwinEnvironment.Server.RemoteIpAddress]            = remoteEndPoint.Address.ToString();
            Environment.Environment[OwinEnvironment.Server.RemotePort]                 = remoteEndPoint.Port.ToString();
            Environment.Environment[OwinEnvironment.Server.IsLocal]                    = remoteEndPoint.Address.GetAddressLocality() == 0;
            Environment.Environment[OwinEnvironment.Server.LocalIpAddress]             = localEndPoint.Address.ToString();
            Environment.Environment[OwinEnvironment.Server.LocalPort]                  = localEndPoint.Port.ToString();
            Environment.Environment[OwinEnvironment.Server.OnSendingHeaders]           = new Action <Action <object>, object>(OnSendingHeaders.Add);
            Environment.Environment[OwinEnvironment.PeerCastStation.PeerCast]          = peerCast;
            Environment.Environment[OwinEnvironment.PeerCastStation.AccessControlInfo] = accessControlInfo;
            Environment.Environment[OwinEnvironment.PeerCastStation.GetRecvRate]       = new Func <float>(() => stream.ReadRate);
            Environment.Environment[OwinEnvironment.PeerCastStation.GetSendRate]       = new Func <float>(() => stream.WriteRate);
            Environment.Environment[OwinEnvironment.Opaque.Upgrade]                    = new Action <IDictionary <string, object>, Func <IDictionary <string, object>, Task> >(OpaqueUpgrade);
        }
Exemple #2
0
 public DeferredResponseStream(OwinResponseBodyStream owner, ResponseStream baseStream)
 {
     Owner      = owner;
     BaseStream = baseStream;
 }