Esempio n. 1
0
        public static WebRequest Parse(string requestString)
        {
            var webRequest = new WebRequest();

            webRequest.ParseRequestLine(requestString, out int requestLineLength);

            requestString      = requestString.Substring(requestLineLength);
            webRequest.Headers = WebMessageUtilities.ParseHeaderLines(requestString, out int totalHeadersLength);

            if (requestString.Length > totalHeadersLength)
            {
                webRequest.Body = new ArtifactContent
                {
                    Text = requestString.Substring(totalHeadersLength)
                };
            }

            if (Uri.TryCreate(webRequest.Target, UriKind.RelativeOrAbsolute, out Uri uri))
            {
                string query = GetQueryFromUri(uri);
                if (!string.IsNullOrEmpty(query))
                {
                    webRequest.Parameters = ParseParametersFromQueryString(query);
                }
            }

            return(webRequest);
        }
Esempio n. 2
0
        internal void ParseStatusLine(
            string responseString,
            out int length)
        {
            Match match = s_statusLineRegex.Match(responseString);

            if (!match.Success)
            {
                throw new ArgumentException($"Invalid status line: '{WebMessageUtilities.Truncate(responseString)}'", nameof(responseString));
            }

            this.Protocol     = match.Groups["protocol"].Value;
            this.Version      = match.Groups["version"].Value;
            this.StatusCode   = int.Parse(match.Groups["statusCode"].Value);
            this.ReasonPhrase = match.Groups["reasonPhrase"].Value;

            length = match.Length;
        }
Esempio n. 3
0
        internal void ParseRequestLine(
            string requestString,
            out int length)
        {
            Match match = s_requestLineRegex.Match(requestString);

            if (!match.Success)
            {
                throw new ArgumentException($"Invalid request line: '{WebMessageUtilities.Truncate(requestString)}'", nameof(requestString));
            }

            this.Method   = match.Groups["method"].Value;
            this.Target   = match.Groups["target"].Value;
            this.Protocol = match.Groups["protocol"].Value;
            this.Version  = match.Groups["version"].Value;

            length = match.Length;
        }
Esempio n. 4
0
        public static WebResponse Parse(string responseString)
        {
            var webResponse = new WebResponse();

            webResponse.ParseStatusLine(responseString, out int statusLineLength);

            responseString      = responseString.Substring(statusLineLength);
            webResponse.Headers = WebMessageUtilities.ParseHeaderLines(responseString, out int totalHeadersLength);

            if (responseString.Length > totalHeadersLength)
            {
                webResponse.Body = new ArtifactContent
                {
                    Text = responseString.Substring(totalHeadersLength)
                };
            }

            return(webResponse);
        }