Beispiel #1
0
            private bool ParseRequestLine()
            {
                _continuation = false;
                var maybeLine = NextLine(ResponseStatus.BadRequest.GetDescription(),
                                         "\n\nRequest line is required.");

                if (!maybeLine.IsPresent)
                {
                    return(true);
                }

                var line = maybeLine.Get();

                var parts = line.Split(' ');

                try
                {
                    _method  = Method.From(ParseSpecificRequestLinePart(parts, 1, "Method"));
                    _uri     = ParseSpecificRequestLinePart(parts, 2, "URI/path").ToMatchableUri();
                    _version = Version.From(ParseSpecificRequestLinePart(parts, 3, "HTTP/version"));

                    return(NextStep());
                }
                catch (Exception e)
                {
                    throw new ArgumentException(
                              $"{ResponseStatus.BadRequest.GetDescription()}\n\nParsing exception: {e.Message}", e);
                }
            }
Beispiel #2
0
            private bool ParseStatusLine()
            {
                if (_bodyOnly)
                {
                    _version = Version.Http1_1;
                    _status  = ResponseStatus.Ok;
                    NextStep();
                    return(false);
                }

                _continuation = false;
                var maybeLine = NextLine(false, "Response status line is required.");

                if (!maybeLine.IsPresent)
                {
                    return(true);
                }

                var line       = maybeLine.Get();
                var spaceIndex = line.IndexOf(' ');

                try
                {
                    _version = Version.From(line.Substring(0, spaceIndex).Trim());
                    _status  = line.Substring(spaceIndex + 1).Trim().ConvertToResponseStatus();

                    return(NextStep());
                }
                catch (Exception ex)
                {
                    throw new ArgumentException($"Response status line parsing exception:{ex.Message}", ex);
                }
            }
Beispiel #3
0
            private void ParseStatusLine()
            {
                _continuation = false;
                var line       = NextLine(false, "Response status line is required.");
                var spaceIndex = line.IndexOf(' ');

                try
                {
                    _version = Version.From(line.Substring(0, spaceIndex).Trim());
                    _status  = line.Substring(spaceIndex + 1).Trim().ConvertToResponseStatus();

                    NextStep();
                }
                catch (Exception ex)
                {
                    throw new ArgumentException($"Response status line parsing exception:{ex.Message}", ex);
                }
            }
Beispiel #4
0
            private void ParseRequestLine()
            {
                _continuation = false;
                var line  = NextLine(Response.ResponseStatus.BadRequest.GetDescription(), "\n\nRequest line is required.");
                var parts = line.Split(' ');

                try
                {
                    _method  = Method.From(ParseSpecificRequestLinePart(parts, 1, "Method"));
                    _uri     = new Uri(ParseSpecificRequestLinePart(parts, 2, "URI/path"));
                    _version = Version.From(ParseSpecificRequestLinePart(parts, 3, "HTTP/version"));

                    NextStep();
                }
                catch (Exception e)
                {
                    throw new ArgumentException($"{Response.ResponseStatus.BadRequest.GetDescription()}\n\nParsing exception: {e.Message}", e);
                }
            }