Skip to content

Commit

Permalink
[FOLD] status_line
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Nov 18, 2021
1 parent 82c7082 commit 49db7cd
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 66 deletions.
2 changes: 1 addition & 1 deletion include/boost/http_proto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <boost/http_proto/bnf/number.hpp>
#include <boost/http_proto/bnf/range.hpp>
#include <boost/http_proto/bnf/sequence.hpp>
#include <boost/http_proto/bnf/status_line.hpp>
#include <boost/http_proto/bnf/token.hpp>
#include <boost/http_proto/bnf/transfer_encoding.hpp>
#include <boost/http_proto/bnf/transfer_param_list.hpp>
Expand All @@ -54,5 +53,6 @@
#include <boost/http_proto/mime/mime_types.hpp>

#include <boost/http_proto/rfc/request_line.hpp>
#include <boost/http_proto/rfc/status_line.hpp>

#endif
13 changes: 6 additions & 7 deletions include/boost/http_proto/impl/response_parser.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#define BOOST_HTTP_PROTO_IMPL_RESPONSE_PARSER_IPP

#include <boost/http_proto/response_parser.hpp>
#include <boost/http_proto/bnf/status_line.hpp>
#include <boost/http_proto/bnf/detail/rfc7230.hpp>
#include <boost/http_proto/rfc/status_line.hpp>

namespace boost {
namespace http_proto {
Expand All @@ -31,12 +31,11 @@ parse_start_line(
char const* const last,
error_code& ec)
{
bnf::status_line p;
auto it = p.parse(
first, last, ec);
status_line t;
auto it = t.parse(first, last, ec);
if(ec)
return first;
switch(p.value().version)
switch(t.version)
{
case 10:
m_.version = version::http_1_0;
Expand All @@ -46,8 +45,8 @@ parse_start_line(
m_.version = version::http_1_1;
break;
}
status_ = p.value().status_code;
status_ = t.status_code;

return first + (it - first);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
// Official repository: https://github.com/CPPAlliance/http_proto
//

#ifndef BOOST_HTTP_PROTO_BNF_IMPL_STATUS_LINE_IPP
#define BOOST_HTTP_PROTO_BNF_IMPL_STATUS_LINE_IPP
#ifndef BOOST_HTTP_PROTO_RFC_IMPL_STATUS_LINE_IPP
#define BOOST_HTTP_PROTO_RFC_IMPL_STATUS_LINE_IPP

#include <boost/http_proto/bnf/status_line.hpp>
#include <boost/http_proto/rfc/status_line.hpp>
#include <boost/http_proto/bnf/detail/rfc7230.hpp>

namespace boost {
namespace http_proto {
namespace bnf {

char const*
status_line::
Expand All @@ -31,23 +30,16 @@ parse(

// HTTP-version
{
char v;
it = detail::parse_http_version(
v, it, end, ec);
it = bnf::detail::parse_http_version(
version, it, end, ec);
if(ec.failed())
return start;
switch(v)
if( version != 10 &&
version != 11)
{
case 10:
case 11:
v_.version = v;
break;
default:
ec = error::bad_version;
break;
}
if(ec.failed())
return start;
}
}

// SP
Expand All @@ -69,36 +61,36 @@ parse(
ec = error::need_more;
return start;
}
if(! is_digit(*it))
if(! bnf::is_digit(*it))
{
ec = error::bad_status_code;
return start;
}
v_.status_code = 100 * (*it - '0');
status_code = 100 * (*it - '0');
++it;
if(it == end)
{
ec = error::need_more;
return start;
}
if(! is_digit(*it))
if(! bnf::is_digit(*it))
{
ec = error::bad_status_code;
return start;
}
v_.status_code += 10 * (*it - '0');
status_code += 10 * (*it - '0');
++it;
if(it == end)
{
ec = error::need_more;
return start;
}
if(! is_digit(*it))
if(! bnf::is_digit(*it))
{
ec = error::bad_status_code;
return start;
}
v_.status_code += 1 * (*it - '0');
status_code += 1 * (*it - '0');
++it;

// SP
Expand All @@ -118,7 +110,7 @@ parse(
bnf::qpchar_set qs;
start = it;
it = qs.skip(it, end);
v_.reason = string_view(
reason = string_view(
start, it - start);

// CRLF
Expand Down Expand Up @@ -148,7 +140,6 @@ parse(
return it;
}

} // bnf
} // http_proto
} // boost

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
// Official repository: https://github.com/CPPAlliance/http_proto
//

#ifndef BOOST_HTTP_PROTO_BNF_STATUS_LINE_HPP
#define BOOST_HTTP_PROTO_BNF_STATUS_LINE_HPP
#ifndef BOOST_HTTP_PROTO_RFC_STATUS_LINE_HPP
#define BOOST_HTTP_PROTO_RFC_STATUS_LINE_HPP

#include <boost/http_proto/detail/config.hpp>
#include <boost/http_proto/error.hpp>
#include <boost/http_proto/string_view.hpp>

namespace boost {
namespace http_proto {
namespace bnf {

/** BNF for status-line
Expand All @@ -37,31 +36,18 @@ namespace bnf {
class status_line
{
public:
struct value_type
{
char version; // 2 digits
short status_code;
string_view reason;
};

value_type const&
value() const noexcept
{
return v_;
}
char version; // 2 digits
short status_code;
string_view reason;

BOOST_HTTP_PROTO_DECL
char const*
parse(
char const* start,
char const* end,
error_code& ec);

private:
value_type v_;
};

} // bnf
} // http_proto
} // boost

Expand Down
2 changes: 1 addition & 1 deletion include/boost/http_proto/src.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ in a translation unit of the program.
#include <boost/http_proto/bnf/impl/header_fields.ipp>
#include <boost/http_proto/bnf/impl/number.ipp>
#include <boost/http_proto/bnf/impl/quoted_string.ipp>
#include <boost/http_proto/bnf/impl/status_line.ipp>
#include <boost/http_proto/bnf/impl/token.ipp>
#include <boost/http_proto/bnf/impl/transfer_encoding.ipp>
#include <boost/http_proto/bnf/impl/transfer_param_list.ipp>
Expand All @@ -66,6 +65,7 @@ in a translation unit of the program.
#include <boost/http_proto/mime/impl/mime_types.ipp>

#include <boost/http_proto/rfc/impl/request_line.ipp>
#include <boost/http_proto/rfc/impl/status_line.ipp>

// VFALCO These are tucked away here temporarily
#if 0
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ set(PFILES
bnf/quoted_string.cpp
bnf/range.cpp
bnf/sequence.cpp
bnf/status_line.cpp
bnf/test_bnf.hpp
bnf/token.cpp
bnf/transfer_encoding.cpp
Expand All @@ -62,6 +61,7 @@ set(PFILES
mime/mime_types.cpp
rfc/charsets.cpp
rfc/request_line.cpp
rfc/status_line.cpp
)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${PFILES})
Expand Down
2 changes: 1 addition & 1 deletion test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ local SOURCES =
bnf/quoted_string.cpp
bnf/range.cpp
bnf/sequence.cpp
bnf/status_line.cpp
bnf/test_bnf.hpp
bnf/token.cpp
bnf/transfer_encoding.cpp
Expand All @@ -64,6 +63,7 @@ local SOURCES =
mime/mime_types.cpp
rfc/charsets.cpp
rfc/request_line.cpp
rfc/status_line.cpp
;

for local f in $(SOURCES)
Expand Down
15 changes: 3 additions & 12 deletions test/bnf/status_line.cpp → test/rfc/status_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,20 @@
//

// Test that header file is self-contained.
#include <boost/http_proto/bnf/status_line.hpp>

#include <boost/http_proto/bnf/type_traits.hpp>
#include <boost/static_assert.hpp>
#include <boost/http_proto/rfc/status_line.hpp>

#include "test_suite.hpp"
#include "test_bnf.hpp"

namespace boost {
namespace http_proto {
namespace bnf {
namespace test {

BOOST_STATIC_ASSERT(
is_element<status_line>::value);

class status_line_test
{
public:
void
run()
{
#if 0
test::bad<status_line>(
"");
test::bad<status_line>(
Expand All @@ -38,14 +30,13 @@ class status_line_test
"HTTP/9.9 0 OK\r\n");
test::good<status_line>(
"HTTP/1.1 200 OK\r\n");
#endif
}
};

TEST_SUITE(
status_line_test,
"boost.http_proto.status_line");

} // test
} // bnf
} // http_proto
} // boost

0 comments on commit 49db7cd

Please sign in to comment.