diff --git a/CHANGELOG.md b/CHANGELOG.md index adac21b1..3e428603 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Version 106: * Dynamic buffer input areas are mutable * Add flat_static_buffer::reset +HTTP: + +* Fix for basic_parser::skip(true) and docs + WebSocket: * websocket test improvements diff --git a/doc/qbk/05_http_examples.qbk b/doc/qbk/05_http_examples.qbk index 14343f4f..3620cf27 100644 --- a/doc/qbk/05_http_examples.qbk +++ b/doc/qbk/05_http_examples.qbk @@ -78,7 +78,11 @@ The [@https://tools.ietf.org/html/rfc7231#section-4.3.2 HEAD request] method indicates to the server that the client wishes to receive the entire header that would be delivered if the method was GET, except -that the body is omitted. +that the body is omitted. When a client wishes to receive the response +to a HEAD request, it is necessary to inform the parser not to expect +a body. This is done by calling +[link beast.ref.boost__beast__http__basic_parser.skip `basic_parser::skip`] +with the value `true`, as shown in this example: [example_http_do_head_request] diff --git a/example/doc/http_examples.hpp b/example/doc/http_examples.hpp index 4cd879ae..00f838f6 100644 --- a/example/doc/http_examples.hpp +++ b/example/doc/http_examples.hpp @@ -411,11 +411,18 @@ do_head_request( return {}; // Create a parser to read the response. - // Responses to HEAD requests MUST NOT include - // a body, so we use the `empty_body` type and - // only attempt to read the header. - parser p; - read_header(stream, buffer, p, ec); + // We use the `empty_body` type since + // a response to a HEAD request MUST NOT + // include a body. + response_parser p; + + // Inform the parser that there will be no body. + p.skip(true); + + // Read the message. Even though fields like + // Content-Length or Transfer-Encoding may be + // set, the message will not contain a body. + read(stream, buffer, p, ec); if(ec) return {}; diff --git a/include/boost/beast/http/impl/basic_parser.ipp b/include/boost/beast/http/impl/basic_parser.ipp index ee64b6b0..73810639 100644 --- a/include/boost/beast/http/impl/basic_parser.ipp +++ b/include/boost/beast/http/impl/basic_parser.ipp @@ -587,10 +587,8 @@ finish_header(error_code& ec, std::false_type) // treat the message as not having a body. // https://github.com/boostorg/beast/issues/692 state_ = state::complete; - return; } - - if(f_ & flagContentLength) + else if(f_ & flagContentLength) { if(len_ > body_limit_) { diff --git a/test/beast/http/basic_parser.cpp b/test/beast/http/basic_parser.cpp index 055b1a01..d8b94678 100644 --- a/test/beast/http/basic_parser.cpp +++ b/test/beast/http/basic_parser.cpp @@ -325,8 +325,8 @@ public: "GET / HTTP/1.1\r\n" "f: " + s + "\r\n" "\r\n"; - parsegrind>(m, - [&](parser const& p) + parsegrind>(m, + [&](request_parser const& p) { BEAST_EXPECT(p.get()["f"] == value); }); diff --git a/test/beast/http/read.cpp b/test/beast/http/read.cpp index fcaee3fa..2c6c4707 100644 --- a/test/beast/http/read.cpp +++ b/test/beast/http/read.cpp @@ -385,7 +385,7 @@ public: "0\r\n\r\n"; error_code ec; flat_buffer fb; - parser p; + response_parser p; read(c.server, fb, p, ec); BEAST_EXPECTS(! ec, ec.message()); }