예제 #1
0
        internal MSearchResponse(IHttpResponse response)
        {
            try
            {
                ResponseCastMethod = Convert.GetCastMetod(response);
                HostIp             = response.RemoteAddress;
                HostPort           = response.RemotePort;
                StatusCode         = response.StatusCode;
                ResponseReason     = response.ResponseReason;
                CacheControl       = TimeSpan.FromSeconds(Convert.GetMaxAge(response.Headers));
                Location           = Convert.UrlToUri(Convert.GetHeaderValue(response.Headers, "LOCATION"));
                Date           = Convert.ToRfc2616Date(Convert.GetHeaderValue(response.Headers, "DATE"));
                Ext            = response.Headers.ContainsKey("EXT");
                Server         = Convert.ConvertToServer(Convert.GetHeaderValue(response.Headers, "SERVER"));
                ST             = Convert.GetHeaderValue(response.Headers, "ST");
                USN            = Convert.GetHeaderValue(response.Headers, "USN");
                BOOTID         = Convert.GetHeaderValue(response.Headers, "BOOTID.UPNP.ORG");
                CONFIGID       = Convert.GetHeaderValue(response.Headers, "CONFIGID.UPNP.ORG");
                SEARCHPORT     = Convert.GetHeaderValue(response.Headers, "SEARCHPORT.UPNP.ORG");
                SECURELOCATION = Convert.GetHeaderValue(response.Headers, "SECURELOCATION.UPNP.ORG");

                Headers = HeaderHelper.SingleOutAdditionalHeaders(new List <string>
                {
                    "HOST", "CACHE-CONTROL", "LOCATION", "DATE", "EXT", "SERVER", "ST", "USN",
                    "BOOTID.UPNP.ORG", "CONFIGID.UPNP.ORG", "SEARCHPORT.UPNP.ORG", "SECURELOCATION.UPNP.ORG"
                }, response.Headers);
            }
            catch (Exception)
            {
                InvalidRequest = true;
            }
        }
예제 #2
0
        internal MSearchResponse(IHttpResponse response, ILogger logger = null)
        {
            try
            {
                LocalIpEndPoint  = response.LocalIpEndPoint;
                RemoteIpEndPoint = response.RemoteIpEndPoint;
                HasParsingError  = response.HasParsingErrors;
                TransportType    = Convert.GetCastMetod(response);
                StatusCode       = response.StatusCode;
                ResponseReason   = response.ResponseReason;
                CacheControl     = TimeSpan.FromSeconds(Convert.GetMaxAge(response.Headers));
                Location         = Convert.UrlToUri(Convert.GetHeaderValue(response.Headers, "LOCATION"));
                Date             = Convert.ToRfc2616Date(Convert.GetHeaderValue(response.Headers, "DATE"));
                Ext            = response.Headers.ContainsKey("EXT");
                Server         = Convert.ConvertToServer(Convert.GetHeaderValue(response.Headers, "SERVER"));
                ST             = new ST(Convert.GetHeaderValue(response.Headers, "ST"), ignoreError: true);
                USN            = new USN(Convert.GetHeaderValue(response.Headers, "USN")); Convert.GetHeaderValue(response.Headers, "USN");
                BOOTID         = int.TryParse(Convert.GetHeaderValue(response.Headers, "BOOTID.UPNP.ORG"), out var b) ? b : 0;
                CONFIGID       = int.TryParse(Convert.GetHeaderValue(response.Headers, "CONFIGID.UPNP.ORG"), out var c) ? c : 0;
                SEARCHPORT     = int.TryParse(Convert.GetHeaderValue(response.Headers, "SEARCHPORT.UPNP.ORG"), out var s) ? s : 0;
                SECURELOCATION = Convert.GetHeaderValue(response.Headers, "SECURELOCATION.UPNP.ORG");

                Headers = HeaderHelper.SingleOutAdditionalHeaders(new List <string>
                {
                    "HOST", "CACHE-CONTROL", "LOCATION", "DATE", "EXT", "SERVER", "ST", "USN",
                    "BOOTID.UPNP.ORG", "CONFIGID.UPNP.ORG", "SEARCHPORT.UPNP.ORG", "SECURELOCATION.UPNP.ORG"
                }, response.Headers);

                RemoteIpEndPoint = response.RemoteIpEndPoint;
            }
            catch (Exception ex)
            {
                logger?.Error(ex);
                InvalidRequest = true;
            }
        }