Skip to content

Commit 5bd5e23

Browse files
authored
Expose ccf::http::parse_accept_header() (#6706)
1 parent c942ccb commit 5bd5e23

File tree

8 files changed

+46
-24
lines changed

8 files changed

+46
-24
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [6.0.0-dev10]
9+
10+
[6.0.0-dev10]: https://github.com/microsoft/CCF/releases/tag/6.0.0-dev10
11+
12+
### Added
13+
14+
- Expose `ccf:http::parse_accept_header()` and `ccf::http::AcceptHeaderField` (#6706).
15+
816
## [6.0.0-dev9]
917

1018
[6.0.0-dev9]: https://github.com/microsoft/CCF/releases/tag/6.0.0-dev9

doc/build_apps/api.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ HTTP Entity Tags Matching
166166
:project: CCF
167167
:members:
168168

169+
HTTP Accept Header Matching
170+
---------------------------
171+
172+
.. doxygenstruct:: ccf::http::AcceptHeaderField
173+
:project: CCF
174+
:members:
175+
176+
.. doxygenfunction:: ccf::http::parse_accept_header
177+
:project: CCF
178+
169179
COSE
170180
----
171181

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#include "ccf/ds/nonstd.h"
66
#include "ccf/http_status.h"
77
#include "ccf/odata_error.h"
8-
#include "node/rpc/rpc_exception.h"
8+
#include "ccf/rpc_exception.h"
99

1010
#include <string_view>
1111

12-
namespace http
12+
namespace ccf::http
1313
{
1414
struct AcceptHeaderField
1515
{

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "ccf"
7-
version = "6.0.0-dev9"
7+
version = "6.0.0-dev10"
88
authors = [
99
{ name="CCF Team", email="[email protected]" },
1010
]

src/endpoints/json_handler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include "ccf/json_handler.h"
44

55
#include "ccf/ds/logger.h"
6+
#include "ccf/http_accept.h"
67
#include "ccf/http_consts.h"
78
#include "ccf/odata_error.h"
89
#include "ccf/redirect.h"
910
#include "ccf/rpc_context.h"
10-
#include "http/http_accept.h"
11-
#include "node/rpc/rpc_exception.h"
11+
#include "ccf/rpc_exception.h"
1212

1313
#include <llhttp/llhttp.h>
1414

@@ -64,7 +64,7 @@ namespace ccf
6464
if (accept_it.has_value())
6565
{
6666
const auto accept_options =
67-
::http::parse_accept_header(accept_it.value());
67+
ccf::http::parse_accept_header(accept_it.value());
6868
bool matched = false;
6969
for (const auto& option : accept_options)
7070
{

src/http/test/http_test.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the Apache 2.0 License.
33

44
#include "ccf/crypto/key_pair.h"
5+
#include "ccf/http_accept.h"
56
#include "ccf/http_query.h"
6-
#include "http/http_accept.h"
77
#include "http/http_builder.h"
88
#include "http/http_parser.h"
99

@@ -565,12 +565,12 @@ DOCTEST_TEST_CASE("Query parser")
565565
DOCTEST_TEST_CASE("Parse Accept header")
566566
{
567567
{
568-
const auto fields = http::parse_accept_header("");
568+
const auto fields = ccf::http::parse_accept_header("");
569569
DOCTEST_REQUIRE(fields.empty());
570570
}
571571

572572
{
573-
const auto fields = http::parse_accept_header("foo/bar;q=0.25");
573+
const auto fields = ccf::http::parse_accept_header("foo/bar;q=0.25");
574574
DOCTEST_REQUIRE(fields.size() == 1);
575575
const auto& field = fields[0];
576576
DOCTEST_REQUIRE(field.mime_type == "foo");
@@ -581,7 +581,7 @@ DOCTEST_TEST_CASE("Parse Accept header")
581581
{
582582
// Shuffled and modified version of Firefox 91 default value, to test
583583
// sorting
584-
const auto fields = http::parse_accept_header(
584+
const auto fields = ccf::http::parse_accept_header(
585585
"image/webp;q=0.8, "
586586
"image/*;q=0.8, "
587587
"text/html, "
@@ -591,31 +591,35 @@ DOCTEST_TEST_CASE("Parse Accept header")
591591
"*/*;q=0.8");
592592
DOCTEST_REQUIRE(fields.size() == 7);
593593

594-
DOCTEST_REQUIRE(fields[0] == http::AcceptHeaderField{"text", "html", 1.0f});
595594
DOCTEST_REQUIRE(
596-
fields[1] == http::AcceptHeaderField{"image", "avif", 1.0f});
595+
fields[0] == ccf::http::AcceptHeaderField{"text", "html", 1.0f});
597596
DOCTEST_REQUIRE(
598-
fields[2] == http::AcceptHeaderField{"application", "xhtml+xml", 1.0f});
597+
fields[1] == ccf::http::AcceptHeaderField{"image", "avif", 1.0f});
599598
DOCTEST_REQUIRE(
600-
fields[3] == http::AcceptHeaderField{"application", "xml", 0.9f});
599+
fields[2] ==
600+
ccf::http::AcceptHeaderField{"application", "xhtml+xml", 1.0f});
601601
DOCTEST_REQUIRE(
602-
fields[4] == http::AcceptHeaderField{"image", "webp", 0.8f});
603-
DOCTEST_REQUIRE(fields[5] == http::AcceptHeaderField{"image", "*", 0.8f});
604-
DOCTEST_REQUIRE(fields[6] == http::AcceptHeaderField{"*", "*", 0.8f});
602+
fields[3] == ccf::http::AcceptHeaderField{"application", "xml", 0.9f});
603+
DOCTEST_REQUIRE(
604+
fields[4] == ccf::http::AcceptHeaderField{"image", "webp", 0.8f});
605+
DOCTEST_REQUIRE(
606+
fields[5] == ccf::http::AcceptHeaderField{"image", "*", 0.8f});
607+
DOCTEST_REQUIRE(fields[6] == ccf::http::AcceptHeaderField{"*", "*", 0.8f});
605608
}
606609

607610
{
608-
DOCTEST_REQUIRE_THROWS(http::parse_accept_header("not_a_mime_type"));
609-
DOCTEST_REQUIRE_THROWS(http::parse_accept_header("valid/mime;q=notnum"));
610-
DOCTEST_REQUIRE_THROWS(http::parse_accept_header(","));
611+
DOCTEST_REQUIRE_THROWS(ccf::http::parse_accept_header("not_a_mime_type"));
612+
DOCTEST_REQUIRE_THROWS(
613+
ccf::http::parse_accept_header("valid/mime;q=notnum"));
614+
DOCTEST_REQUIRE_THROWS(ccf::http::parse_accept_header(","));
611615
}
612616
}
613617

614618
DOCTEST_TEST_CASE("Accept header MIME matching")
615619
{
616-
const auto a = http::AcceptHeaderField{"foo", "bar", 1.0f};
617-
const auto b = http::AcceptHeaderField{"foo", "*", 1.0f};
618-
const auto c = http::AcceptHeaderField{"*", "*", 1.0f};
620+
const auto a = ccf::http::AcceptHeaderField{"foo", "bar", 1.0f};
621+
const auto b = ccf::http::AcceptHeaderField{"foo", "*", 1.0f};
622+
const auto c = ccf::http::AcceptHeaderField{"*", "*", 1.0f};
619623

620624
DOCTEST_REQUIRE(a.matches("foo/bar"));
621625
DOCTEST_REQUIRE_FALSE(a.matches("foo/baz"));

src/node/rpc/frontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "ccf/http_status.h"
77
#include "ccf/node_context.h"
88
#include "ccf/pal/locking.h"
9+
#include "ccf/rpc_exception.h"
910
#include "ccf/service/node_info_network.h"
1011
#include "ccf/service/signed_req.h"
1112
#include "ccf/service/tables/jwt.h"
@@ -20,7 +21,6 @@
2021
#include "kv/store.h"
2122
#include "node/endpoint_context_impl.h"
2223
#include "node/node_configuration_subsystem.h"
23-
#include "rpc_exception.h"
2424
#include "service/internal_tables_access.h"
2525

2626
#define FMT_HEADER_ONLY

0 commit comments

Comments
 (0)