Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
9af5eddd
Commit
9af5eddd
authored
Mar 21, 2023
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename http::{ => request_}header
parent
d9255378
Changes
22
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
69 additions
and
61 deletions
+69
-61
examples/web_socket/echo.cpp
examples/web_socket/echo.cpp
+1
-1
examples/web_socket/quote-server.cpp
examples/web_socket/quote-server.cpp
+8
-8
examples/web_socket/stock-ticker.cpp
examples/web_socket/stock-ticker.cpp
+1
-1
libcaf_net/CMakeLists.txt
libcaf_net/CMakeLists.txt
+1
-1
libcaf_net/caf/detail/flow_bridge_base.hpp
libcaf_net/caf/detail/flow_bridge_base.hpp
+1
-1
libcaf_net/caf/net/fwd.hpp
libcaf_net/caf/net/fwd.hpp
+2
-1
libcaf_net/caf/net/http/request.hpp
libcaf_net/caf/net/http/request.hpp
+11
-6
libcaf_net/caf/net/http/request_header.hpp
libcaf_net/caf/net/http/request_header.hpp
+8
-7
libcaf_net/caf/net/http/server.hpp
libcaf_net/caf/net/http/server.hpp
+2
-8
libcaf_net/caf/net/http/server_factory.hpp
libcaf_net/caf/net/http/server_factory.hpp
+1
-1
libcaf_net/caf/net/http/upper_layer.hpp
libcaf_net/caf/net/http/upper_layer.hpp
+2
-1
libcaf_net/caf/net/prometheus/server.hpp
libcaf_net/caf/net/prometheus/server.hpp
+2
-1
libcaf_net/caf/net/web_socket/has_on_request.hpp
libcaf_net/caf/net/web_socket/has_on_request.hpp
+3
-2
libcaf_net/caf/net/web_socket/server.hpp
libcaf_net/caf/net/web_socket/server.hpp
+2
-2
libcaf_net/caf/net/web_socket/server_factory.hpp
libcaf_net/caf/net/web_socket/server_factory.hpp
+7
-5
libcaf_net/caf/net/web_socket/upper_layer.hpp
libcaf_net/caf/net/web_socket/upper_layer.hpp
+1
-1
libcaf_net/src/net/http/request_header.cpp
libcaf_net/src/net/http/request_header.cpp
+8
-7
libcaf_net/src/net/http/server_factory.cpp
libcaf_net/src/net/http/server_factory.cpp
+1
-1
libcaf_net/src/net/prometheus/server.cpp
libcaf_net/src/net/prometheus/server.cpp
+3
-2
libcaf_net/src/net/web_socket/server.cpp
libcaf_net/src/net/web_socket/server.cpp
+1
-1
libcaf_net/test/net/http/server.cpp
libcaf_net/test/net/http/server.cpp
+2
-2
libcaf_net/test/net/web_socket/server.cpp
libcaf_net/test/net/web_socket/server.cpp
+1
-1
No files found.
examples/web_socket/echo.cpp
View file @
9af5eddd
...
...
@@ -61,7 +61,7 @@ int caf_main(caf::actor_system& sys, const config& cfg) {
// Limit how many clients may be connected at any given time.
.
max_connections
(
max_connections
)
// Accept only requests for path "/".
.
on_request
([](
ws
::
acceptor
<>&
acc
,
const
http
::
header
&
hdr
)
{
.
on_request
([](
ws
::
acceptor
<>&
acc
,
const
http
::
request_
header
&
hdr
)
{
// The hdr parameter is a dictionary with fields from the WebSocket
// handshake such as the path.
auto
path
=
hdr
.
path
();
...
...
examples/web_socket/quote-server.cpp
View file @
9af5eddd
...
...
@@ -140,8 +140,8 @@ int caf_main(caf::actor_system& sys, const config& cfg) {
// Limit how many clients may be connected at any given time.
.
max_connections
(
max_connections
)
// Forward the path from the WebSocket request to the worker.
.
on_request
(
[](
ws
::
acceptor
<
caf
::
cow_string
>&
acc
,
const
http
::
header
&
hdr
)
{
.
on_request
(
[](
ws
::
acceptor
<
caf
::
cow_string
>&
acc
,
const
http
::
request_
header
&
hdr
)
{
// The hdr parameter is a dictionary with fields from the WebSocket
// handshake such as the path. This is only field we care about
// here. By passing the (copy-on-write) string to accept() here, we
...
...
examples/web_socket/stock-ticker.cpp
View file @
9af5eddd
...
...
@@ -185,7 +185,7 @@ int caf_main(caf::actor_system& sys, const config& cfg) {
// Limit how many clients may be connected at any given time.
.
max_connections
(
max_connections
)
// Add handler for incoming connections.
.
on_request
([](
ws
::
acceptor
<>&
acc
,
const
http
::
header
&
)
{
.
on_request
([](
ws
::
acceptor
<>&
acc
,
const
http
::
request_
header
&
)
{
// Ignore all header fields and accept the connection.
acc
.
accept
();
})
...
...
libcaf_net/CMakeLists.txt
View file @
9af5eddd
...
...
@@ -37,10 +37,10 @@ caf_add_component(
src/net/dsl/config_base.cpp
src/net/generic_lower_layer.cpp
src/net/generic_upper_layer.cpp
src/net/http/header.cpp
src/net/http/lower_layer.cpp
src/net/http/method.cpp
src/net/http/request.cpp
src/net/http/request_header.cpp
src/net/http/response.cpp
src/net/http/server.cpp
src/net/http/server_factory.cpp
...
...
libcaf_net/caf/detail/flow_bridge_base.hpp
View file @
9af5eddd
...
...
@@ -9,7 +9,7 @@
#include "caf/async/spsc_buffer.hpp"
#include "caf/fwd.hpp"
#include "caf/logger.hpp"
#include "caf/net/http/header.hpp"
#include "caf/net/http/
request_
header.hpp"
#include "caf/sec.hpp"
#include <utility>
...
...
libcaf_net/caf/net/fwd.hpp
View file @
9af5eddd
...
...
@@ -125,8 +125,9 @@ enum class status : uint16_t;
namespace
caf
::
net
::
http
{
class
header
;
class
lower_layer
;
class
request
;
class
request_header
;
class
server
;
class
upper_layer
;
...
...
libcaf_net/caf/net/http/request.hpp
View file @
9af5eddd
...
...
@@ -9,7 +9,7 @@
#include "caf/byte_span.hpp"
#include "caf/detail/net_export.hpp"
#include "caf/net/fwd.hpp"
#include "caf/net/http/header.hpp"
#include "caf/net/http/
request_
header.hpp"
#include "caf/net/http/response.hpp"
#include <cstdint>
...
...
@@ -20,11 +20,11 @@
namespace
caf
::
net
::
http
{
///
Handle type (implicitly shared)
that represents an HTTP client request.
///
Implicitly shared Handle type
that represents an HTTP client request.
class
CAF_NET_EXPORT
request
{
public:
struct
impl
{
header
hdr
;
request_
header
hdr
;
std
::
vector
<
std
::
byte
>
body
;
async
::
promise
<
response
>
prom
;
};
...
...
@@ -40,18 +40,23 @@ public:
// nop
}
/// Returns the HTTP header.
/// Returns the HTTP header
for the request
.
/// @pre `valid()`
const
header
&
hd
r
()
const
{
const
request_header
&
heade
r
()
const
{
return
pimpl_
->
hdr
;
}
/// Returns the HTTP body (payload).
/// Returns the HTTP body (payload)
for the request
.
/// @pre `valid()`
const_byte_span
body
()
const
{
return
make_span
(
pimpl_
->
body
);
}
/// @copydoc body
const_byte_span
payload
()
const
{
return
make_span
(
pimpl_
->
body
);
}
/// Sends an HTTP response message to the client. Automatically sets the
/// `Content-Type` and `Content-Length` header fields.
/// @pre `valid()`
...
...
libcaf_net/caf/net/http/header.hpp
→
libcaf_net/caf/net/http/
request_
header.hpp
View file @
9af5eddd
...
...
@@ -16,19 +16,20 @@
namespace
caf
::
net
::
http
{
class
CAF_NET_EXPORT
header
{
/// Encapsulates meta data for HTTP requests.
class
CAF_NET_EXPORT
request_header
{
public:
header
()
=
default
;
request_
header
()
=
default
;
header
(
header
&&
)
=
default
;
request_header
(
request_
header
&&
)
=
default
;
header
&
operator
=
(
header
&&
)
=
default
;
request_header
&
operator
=
(
request_
header
&&
)
=
default
;
header
(
const
header
&
);
request_header
(
const
request_
header
&
);
header
&
operator
=
(
const
header
&
);
request_header
&
operator
=
(
const
request_
header
&
);
void
assign
(
const
header
&
);
void
assign
(
const
request_
header
&
);
http
::
method
method
()
const
noexcept
{
return
method_
;
...
...
libcaf_net/caf/net/http/server.hpp
View file @
9af5eddd
...
...
@@ -11,9 +11,9 @@
#include "caf/error.hpp"
#include "caf/logger.hpp"
#include "caf/net/fwd.hpp"
#include "caf/net/http/header.hpp"
#include "caf/net/http/header_fields_map.hpp"
#include "caf/net/http/lower_layer.hpp"
#include "caf/net/http/request_header.hpp"
#include "caf/net/http/status.hpp"
#include "caf/net/http/upper_layer.hpp"
#include "caf/net/http/v1.hpp"
...
...
@@ -35,12 +35,6 @@ class CAF_NET_EXPORT server : public octet_stream::upper_layer,
public:
// -- member types -----------------------------------------------------------
using
header_fields_type
=
header_fields_map
;
using
status_code_type
=
status
;
using
header_type
=
header
;
enum
class
mode
{
read_header
,
read_payload
,
...
...
@@ -134,7 +128,7 @@ private:
upper_layer_ptr
up_
;
/// Buffer for re-using memory.
header
hdr_
;
request_
header
hdr_
;
/// Stores whether we are currently waiting for the payload.
mode
mode_
=
mode
::
read_header
;
...
...
libcaf_net/caf/net/http/server_factory.hpp
View file @
9af5eddd
...
...
@@ -75,7 +75,7 @@ public:
error
start
(
net
::
http
::
lower_layer
*
down
)
override
;
ptrdiff_t
consume
(
const
net
::
http
::
header
&
hdr
,
ptrdiff_t
consume
(
const
net
::
http
::
request_
header
&
hdr
,
const_byte_span
payload
)
override
;
static
auto
make
(
async
::
execution_context_ptr
loop
,
...
...
libcaf_net/caf/net/http/upper_layer.hpp
View file @
9af5eddd
...
...
@@ -27,7 +27,8 @@ public:
/// @returns The number of consumed bytes or a negative value to signal an
/// error.
/// @note Discarded data is lost permanently.
virtual
ptrdiff_t
consume
(
const
header
&
hdr
,
const_byte_span
payload
)
=
0
;
virtual
ptrdiff_t
consume
(
const
request_header
&
hdr
,
const_byte_span
payload
)
=
0
;
};
}
// namespace caf::net::http
libcaf_net/caf/net/prometheus/server.hpp
View file @
9af5eddd
...
...
@@ -63,7 +63,8 @@ public:
error
start
(
http
::
lower_layer
*
down
)
override
;
ptrdiff_t
consume
(
const
http
::
header
&
hdr
,
const_byte_span
payload
)
override
;
ptrdiff_t
consume
(
const
http
::
request_header
&
hdr
,
const_byte_span
payload
)
override
;
private:
explicit
server
(
scrape_state_ptr
state
)
:
state_
(
std
::
move
(
state
))
{
...
...
libcaf_net/caf/net/web_socket/has_on_request.hpp
View file @
9af5eddd
...
...
@@ -41,8 +41,9 @@ public:
"on_request must take an acceptor as 1st argument"
);
static_assert
(
std
::
is_same_v
<
arg1_t
,
acceptor_t
&>
,
"on_request must take the acceptor as mutable reference"
);
static_assert
(
std
::
is_same_v
<
arg2_t
,
const
http
::
header
&>
,
"on_request must take 'const http::header&' as 2nd argument"
);
static_assert
(
std
::
is_same_v
<
arg2_t
,
const
http
::
request_header
&>
,
"on_request must take 'const http::request_header&' as 2nd argument"
);
// Wrap the callback and return the factory object.
using
factory_t
=
typename
acceptor_t
::
template
server_factory_type
<
Trait
>;
auto
callback
=
make_shared_type_erased_callback
(
std
::
move
(
on_request
));
...
...
libcaf_net/caf/net/web_socket/server.hpp
View file @
9af5eddd
...
...
@@ -10,8 +10,8 @@
#include "caf/error.hpp"
#include "caf/logger.hpp"
#include "caf/net/fwd.hpp"
#include "caf/net/http/header.hpp"
#include "caf/net/http/method.hpp"
#include "caf/net/http/request_header.hpp"
#include "caf/net/http/status.hpp"
#include "caf/net/http/v1.hpp"
#include "caf/net/multiplexer.hpp"
...
...
@@ -47,7 +47,7 @@ public:
/// @param down A pointer to the lower layer that remains valid for the
/// lifetime of the upper layer.
/// @param hdr The HTTP request header from the client handshake.
virtual
error
start
(
lower_layer
*
down
,
const
http
::
header
&
hdr
)
=
0
;
virtual
error
start
(
lower_layer
*
down
,
const
http
::
request_
header
&
hdr
)
=
0
;
};
using
upper_layer_ptr
=
std
::
unique_ptr
<
upper_layer
>
;
...
...
libcaf_net/caf/net/web_socket/server_factory.hpp
View file @
9af5eddd
...
...
@@ -12,7 +12,7 @@
#include "caf/detail/ws_flow_bridge.hpp"
#include "caf/fwd.hpp"
#include "caf/net/dsl/server_factory_base.hpp"
#include "caf/net/http/header.hpp"
#include "caf/net/http/
request_
header.hpp"
#include "caf/net/http/server.hpp"
#include "caf/net/multiplexer.hpp"
#include "caf/net/octet_stream/transport.hpp"
...
...
@@ -36,7 +36,8 @@ public:
using
ws_acceptor_t
=
net
::
web_socket
::
acceptor
<
Ts
...
>
;
using
on_request_cb_type
=
shared_callback_ptr
<
void
(
ws_acceptor_t
&
,
const
net
::
http
::
header
&
)
>
;
=
shared_callback_ptr
<
void
(
ws_acceptor_t
&
,
//
const
net
::
http
::
request_header
&
)
>
;
using
accept_event
=
typename
Trait
::
template
accept_event
<
Ts
...>;
...
...
@@ -63,7 +64,7 @@ public:
}
error
start
(
net
::
web_socket
::
lower_layer
*
down_ptr
,
const
net
::
http
::
header
&
hdr
)
override
{
const
net
::
http
::
request_
header
&
hdr
)
override
{
CAF_ASSERT
(
down_ptr
!=
nullptr
);
super
::
down_
=
down_ptr
;
net
::
web_socket
::
acceptor_impl
<
Trait
,
Ts
...
>
acc
;
...
...
@@ -95,7 +96,8 @@ public:
using
ws_acceptor_t
=
net
::
web_socket
::
acceptor
<
Ts
...
>
;
using
on_request_cb_type
=
shared_callback_ptr
<
void
(
ws_acceptor_t
&
,
const
net
::
http
::
header
&
)
>
;
=
shared_callback_ptr
<
void
(
ws_acceptor_t
&
,
//
const
net
::
http
::
request_header
&
)
>
;
using
accept_event
=
typename
Trait
::
template
accept_event
<
Ts
...>;
...
...
@@ -155,7 +157,7 @@ public:
using
config_type
=
typename
super
::
config_type
;
using
on_request_cb_type
=
shared_callback_ptr
<
void
(
acceptor
<
Ts
...
>&
,
const
http
::
header
&
)
>
;
=
shared_callback_ptr
<
void
(
acceptor
<
Ts
...
>&
,
const
http
::
request_
header
&
)
>
;
server_factory
(
intrusive_ptr
<
config_type
>
cfg
,
on_request_cb_type
on_request
)
:
super
(
std
::
move
(
cfg
)),
on_request_
(
std
::
move
(
on_request
))
{
...
...
libcaf_net/caf/net/web_socket/upper_layer.hpp
View file @
9af5eddd
...
...
@@ -7,7 +7,7 @@
#include "caf/detail/net_export.hpp"
#include "caf/net/fwd.hpp"
#include "caf/net/generic_upper_layer.hpp"
#include "caf/net/http/header.hpp"
#include "caf/net/http/
request_
header.hpp"
namespace
caf
::
net
::
web_socket
{
...
...
libcaf_net/src/net/http/header.cpp
→
libcaf_net/src/net/http/
request_
header.cpp
View file @
9af5eddd
#include "caf/net/http/header.hpp"
#include "caf/net/http/
request_
header.hpp"
#include "caf/expected.hpp"
#include "caf/logger.hpp"
...
...
@@ -30,16 +30,16 @@ bool for_each_line(std::string_view input, F&& f) {
}
// namespace
header
::
header
(
const
header
&
other
)
{
request_header
::
request_header
(
const
request_
header
&
other
)
{
assign
(
other
);
}
header
&
header
::
operator
=
(
const
header
&
other
)
{
request_header
&
request_header
::
operator
=
(
const
request_
header
&
other
)
{
assign
(
other
);
return
*
this
;
}
void
header
::
assign
(
const
header
&
other
)
{
void
request_header
::
assign
(
const
request_
header
&
other
)
{
auto
remap
=
[](
const
char
*
base
,
std
::
string_view
src
,
const
char
*
new_base
)
{
auto
offset
=
std
::
distance
(
base
,
src
.
data
());
...
...
@@ -66,7 +66,8 @@ void header::assign(const header& other) {
}
}
std
::
pair
<
status
,
std
::
string_view
>
header
::
parse
(
std
::
string_view
raw
)
{
std
::
pair
<
status
,
std
::
string_view
>
request_header
::
parse
(
std
::
string_view
raw
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
raw
));
// Sanity checking and copying of the raw input.
using
namespace
literals
;
...
...
@@ -146,11 +147,11 @@ std::pair<status, std::string_view> header::parse(std::string_view raw) {
}
}
bool
header
::
chunked_transfer_encoding
()
const
{
bool
request_
header
::
chunked_transfer_encoding
()
const
{
return
field
(
"Transfer-Encoding"
).
find
(
"chunked"
)
!=
std
::
string_view
::
npos
;
}
std
::
optional
<
size_t
>
header
::
content_length
()
const
{
std
::
optional
<
size_t
>
request_
header
::
content_length
()
const
{
return
field_as
<
size_t
>
(
"Content-Length"
);
}
...
...
libcaf_net/src/net/http/server_factory.cpp
View file @
9af5eddd
...
...
@@ -51,7 +51,7 @@ error http_flow_adapter::start(net::http::lower_layer* down) {
return
none
;
}
ptrdiff_t
http_flow_adapter
::
consume
(
const
net
::
http
::
header
&
hdr
,
ptrdiff_t
http_flow_adapter
::
consume
(
const
net
::
http
::
request_
header
&
hdr
,
const_byte_span
payload
)
{
using
namespace
net
::
http
;
if
(
!
pending_
.
empty
())
{
...
...
libcaf_net/src/net/prometheus/server.cpp
View file @
9af5eddd
...
...
@@ -4,8 +4,8 @@
#include "caf/net/prometheus/server.hpp"
#include "caf/net/http/header.hpp"
#include "caf/net/http/lower_layer.hpp"
#include "caf/net/http/request_header.hpp"
using
namespace
std
::
literals
;
...
...
@@ -42,7 +42,8 @@ error server::start(http::lower_layer* down) {
return
caf
::
none
;
}
ptrdiff_t
server
::
consume
(
const
http
::
header
&
hdr
,
const_byte_span
payload
)
{
ptrdiff_t
server
::
consume
(
const
http
::
request_header
&
hdr
,
const_byte_span
payload
)
{
if
(
hdr
.
path
()
!=
"/metrics"
)
{
down_
->
send_response
(
http
::
status
::
not_found
,
"text/plain"
,
"Not found."
);
down_
->
shutdown
();
...
...
libcaf_net/src/net/web_socket/server.cpp
View file @
9af5eddd
...
...
@@ -89,7 +89,7 @@ void server::write_response(http::status code, std::string_view msg) {
bool
server
::
handle_header
(
std
::
string_view
http
)
{
using
namespace
std
::
literals
;
// Parse the header and reject invalid inputs.
http
::
header
hdr
;
http
::
request_
header
hdr
;
auto
[
code
,
msg
]
=
hdr
.
parse
(
http
);
if
(
code
!=
http
::
status
::
ok
)
{
write_response
(
code
,
msg
);
...
...
libcaf_net/test/net/http/server.cpp
View file @
9af5eddd
...
...
@@ -17,7 +17,7 @@ class app_t : public net::http::upper_layer {
public:
// -- member variables -------------------------------------------------------
net
::
http
::
header
hdr
;
net
::
http
::
request_
header
hdr
;
caf
::
byte_buffer
payload
;
...
...
@@ -66,7 +66,7 @@ public:
return
true
;
}
ptrdiff_t
consume
(
const
net
::
http
::
header
&
request_hdr
,
ptrdiff_t
consume
(
const
net
::
http
::
request_
header
&
request_hdr
,
const_byte_span
body
)
override
{
hdr
=
request_hdr
;
auto
content
=
"Hello world!"
sv
;
...
...
libcaf_net/test/net/web_socket/server.cpp
View file @
9af5eddd
...
...
@@ -33,7 +33,7 @@ public:
}
error
start
(
net
::
web_socket
::
lower_layer
*
down
,
const
net
::
http
::
header
&
hdr
)
override
{
const
net
::
http
::
request_
header
&
hdr
)
override
{
down
->
request_messages
();
// Store the request information in cfg to evaluate them later.
auto
&
ws
=
cfg
[
"web-socket"
].
as_dictionary
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment