-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expect handles presence of request content
- Loading branch information
Showing
4 changed files
with
190 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// | ||
// Copyright (c) 2019 Vinnie Falco ([email protected]) | ||
// Copyright (c) 2024 Christian Mazakas | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
@@ -8,6 +9,7 @@ | |
// | ||
|
||
#include <boost/http_proto/detail/header.hpp> | ||
#include <boost/http_proto/error.hpp> | ||
#include <boost/http_proto/field.hpp> | ||
#include <boost/http_proto/fields_view_base.hpp> | ||
#include <boost/http_proto/header_limits.hpp> | ||
|
@@ -24,7 +26,6 @@ | |
#include <boost/assert.hpp> | ||
#include <boost/assert/source_location.hpp> | ||
#include <boost/static_assert.hpp> | ||
#include <string> | ||
#include <utility> | ||
|
||
namespace boost { | ||
|
@@ -524,6 +525,11 @@ on_insert_content_length( | |
// one value | ||
md.content_length.ec = {}; | ||
md.content_length.value = *rv; | ||
if( md.expect.ec == error::expect_needs_content ) | ||
{ | ||
md.expect.ec = {}; | ||
md.expect.is_100_continue = true; | ||
} | ||
update_payload(); | ||
return; | ||
} | ||
|
@@ -548,16 +554,25 @@ on_insert_expect( | |
++md.expect.count; | ||
if(kind != detail::kind::request) | ||
return; | ||
if(md.expect.ec.failed()) | ||
return; | ||
|
||
// VFALCO Should we allow duplicate | ||
// Expect fields that have 100-continue? | ||
|
||
// TODO: we need to add content checks | ||
// i.e. does the request have either `content-length` | ||
// or a `transfer-encoding: chunked`. | ||
// https://datatracker.ietf.org/doc/html/rfc9110#section-10.1.1-10 | ||
// https://datatracker.ietf.org/doc/html/rfc9110#section-10.1.1-11.1 | ||
// A client MUST NOT generate a 100-continue expectation in a | ||
// request that does not include content. | ||
auto const has_content = [&] | ||
{ | ||
auto const has_content_length = | ||
md.content_length.count > 0 && | ||
!md.content_length.ec.failed(); | ||
|
||
auto const is_chunked = | ||
md.transfer_encoding.is_chunked; | ||
|
||
return has_content_length || | ||
is_chunked; | ||
}(); | ||
|
||
if( md.expect.count > 1 || | ||
! grammar::ci_is_equal(v, | ||
|
@@ -569,6 +584,16 @@ on_insert_expect( | |
md.expect.is_100_continue = false; | ||
return; | ||
} | ||
|
||
if(! has_content ) | ||
{ | ||
md.expect.ec = | ||
BOOST_HTTP_PROTO_ERR( | ||
error::expect_needs_content); | ||
md.expect.is_100_continue = false; | ||
return; | ||
} | ||
|
||
md.expect.is_100_continue = true; | ||
} | ||
|
||
|
@@ -606,7 +631,14 @@ on_insert_transfer_encoding() | |
if(! md.transfer_encoding.is_chunked) | ||
{ | ||
if(t.id == transfer_coding::chunked) | ||
{ | ||
md.transfer_encoding.is_chunked = true; | ||
if( md.expect.ec == error::expect_needs_content ) | ||
{ | ||
md.expect.ec = {}; | ||
md.expect.is_100_continue = true; | ||
} | ||
} | ||
continue; | ||
} | ||
if(t.id == transfer_coding::chunked) | ||
|
@@ -758,7 +790,7 @@ on_erase_expect() | |
return; | ||
*/ | ||
// reset and re-insert | ||
auto n = md.expect.count; | ||
auto n = count; | ||
auto const p = cbuf + prefix; | ||
auto const* e = &tab()[0]; | ||
md.expect = {}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters