Пример #1
0
        /// <summary>
        /// Get a new resources with the supplied response.
        /// </summary>
        /// <param name="headers">The header list to search in.</param>
        /// <returns>The response resource.</returns>
        public static ResponseResource GetResponseResource(List <NameValue> headers)
        {
            ResponseResource resource = new ResponseResource();

            resource.ProtocolVersion = "HTTP/2";

            // For each header.
            foreach (NameValue item in headers)
            {
                // Get the status.
                if ((item.Name.Trim().ToLower().Equals("status")) || (item.Name.Trim().ToLower().Equals(":status")))
                {
                    // Try get code and sub code.
                    string[] codes = item.Value.Trim().Split(new char[] { '.' }, StringSplitOptions.None);
                    resource.Code = Int32.Parse(codes[0].Trim());

                    // Looking for subcode.
                    if (codes.Length > 1)
                    {
                        resource.Subcode = Int32.Parse(codes[1].Trim());
                    }
                }

                // Get the path.
                if ((item.Name.Trim().ToLower().Equals("description")) || (item.Name.Trim().ToLower().Equals(":description")))
                {
                    resource.Description = item.Value.Trim();
                }
            }

            // Return the resource.
            return(resource);
        }
Пример #2
0
 /// <summary>
 /// Read the response headers.
 /// </summary>
 /// <param name="headers">The header collection.</param>
 /// <param name="response">The response header.</param>
 public virtual void ReadNetResponseHeaders(List <NameValue> headers, string response)
 {
     // If headers exist.
     if (headers != null)
     {
         // Get the request method, query and version
         ResponseResource resource = Nequeo.Net.Utility.GetResponseResource(response);
         ReadNetResponseHeaders(headers, resource);
     }
 }
        public ResponseResource <IEnumerable <ArchiveSerialNumberResource> > Build(ResponseModel <IEnumerable <ArchiveSerialNumber> > archiveSerialNumbersModel)
        {
            var response = new ResponseResource <IEnumerable <ArchiveSerialNumberResource> >
            {
                ResponseData = archiveSerialNumbersModel.ResponseData.Select(
                    s => this.archiveSerialNumberResourceBuilder.Build(
                        new ResponseModel <ArchiveSerialNumber>(s, archiveSerialNumbersModel.Privileges))),
                Links = this.BuildLinks(archiveSerialNumbersModel).ToArray()
            };

            return(response);
        }
Пример #4
0
        /// <summary>
        /// Get a new resources with the supplied response.
        /// </summary>
        /// <param name="response">The response header.</param>
        /// <returns>The response resource.</returns>
        public static ResponseResource GetResponseResource(string response)
        {
            ResponseResource resource = new ResponseResource();

            resource.ProtocolVersion = "HTTP/2";

            // Split the request
            string[] requestItems = response.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

            // For each resources.
            foreach (string item in requestItems)
            {
                // Get the name value pair.
                string[] resourceNameValue = item.Split(new string[] { "=" }, StringSplitOptions.None);

                // Get the status.
                if (resourceNameValue[0].Trim().ToLower().Equals("status"))
                {
                    // Try get code and sub code.
                    string[] codes = requestItems[1].Trim().Split(new char[] { '.' }, StringSplitOptions.None);
                    resource.Code = Int32.Parse(codes[0].Trim());

                    // Looking for subcode.
                    if (codes.Length > 1)
                    {
                        resource.Subcode = Int32.Parse(codes[1].Trim());
                    }
                }

                // Get the description.
                if (resourceNameValue[0].Trim().ToLower().Equals("description"))
                {
                    resource.Description = resourceNameValue[1].Trim();
                }
            }

            // Return the resource.
            return(resource);
        }
Пример #5
0
        public override string ToString()
        {
            var responseType = ResponseResource?.GetType().ToString() ?? string.Empty;

            return($"OperationResult: type={GetType().Name}, statusCode={StatusCode} {responseType}");
        }
Пример #6
0
        /// <summary>
        /// Read the response headers.
        /// </summary>
        /// <param name="headers">The header collection.</param>
        /// <param name="response">The response header.</param>
        public virtual void ReadNetResponseHeaders(List <NameValue> headers, ResponseResource response)
        {
            // Get the original headers.
            OriginalHeaders = headers;

            // If headers exist.
            if (headers != null)
            {
                // Create the new header collection.
                NameValueCollection headersCol = new NameValueCollection();

                // For each header found.
                foreach (NameValue item in headers)
                {
                    // If the name value pair is a cookie header.
                    if (item.Name.Trim().ToLower().Contains("set-cookie"))
                    {
                        // Add the name value pair.
                        AddCookie(item);
                    }
                    else
                    {
                        // Assign the header collection.
                        headersCol.Add(item.Name, item.Value);
                    }
                }

                // Assign the headers.
                Headers           = headersCol;
                StatusCode        = response.Code;
                StatusSubcode     = response.Subcode;
                ProtocolVersion   = response.ProtocolVersion;
                StatusDescription = response.Description;

                // Get the content length
                if (!String.IsNullOrEmpty(headersCol["Content-Length"]))
                {
                    // Get the content length.
                    ContentLength = Int64.Parse(headersCol["Content-Length"].Trim());
                }

                // Get the content type
                if (!String.IsNullOrEmpty(headersCol["Content-Type"]))
                {
                    // Get the content type.
                    ContentType = headersCol["Content-Type"].Trim();
                }

                // Get the server
                if (!String.IsNullOrEmpty(headersCol["Server"]))
                {
                    // Get the server.
                    Server = headersCol["Server"].Trim();
                }

                // Get the Transfer-Encoding chuncked
                if (!String.IsNullOrEmpty(headersCol["Transfer-Encoding"]))
                {
                    // Get keep-alive indicator.
                    if (headersCol["Transfer-Encoding"].Trim().ToLower().Contains("chunked"))
                    {
                        SendChunked = true;
                    }
                    else
                    {
                        SendChunked = false;
                    }
                }

                // Get the Allow
                if (!String.IsNullOrEmpty(headersCol["Allow"]))
                {
                    // Get the Allow.
                    Allow = headersCol["Allow"].Trim();
                }

                // Get the Content Encoding
                if (!String.IsNullOrEmpty(headersCol["Content-Encoding"]))
                {
                    // Get the Content Encoding.
                    ContentEncoding = headersCol["Content-Encoding"].Trim();
                }

                // Get the Content Language
                if (!String.IsNullOrEmpty(headersCol["Content-Language"]))
                {
                    // Get the Content Language
                    ContentLanguage = headersCol["Content-Language"].Trim();
                }

                // Get the connection
                if (!String.IsNullOrEmpty(headersCol["Connection"]))
                {
                    // Get keep-alive indicator.
                    if (headersCol["Connection"].Trim().ToLower().Contains("keep-alive"))
                    {
                        KeepAlive = true;
                    }
                    else
                    {
                        KeepAlive = false;
                    }

                    // Get the upgrade indicator if it exists.
                    string connUpgrade = headersCol["Connection"];
                    UpgradeRequest = (connUpgrade.Trim().ToLower().Contains("upgrade") ? true : false);
                }

                // Get the upgrade
                if (!String.IsNullOrEmpty(headersCol["Upgrade"]))
                {
                    // Get the upgrade.
                    Upgrade = headersCol["Upgrade"].Trim();
                }

                // Get the Authorization Type
                if (!String.IsNullOrEmpty(headersCol["WWW-Authenticate"]))
                {
                    // Get the Authorization Type
                    AuthorizationType = headersCol["WWW-Authenticate"].Trim();
                }
            }
        }