Skip to content

Commit e92e356

Browse files
committed
Remove obsolete route results and trim old APIs
1 parent 392d58d commit e92e356

6 files changed

Lines changed: 4 additions & 380 deletions

File tree

include/boost/http/server/route_handler.hpp

Lines changed: 1 addition & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <boost/http/serializer.hpp> // VFALCO forward declare?
2121
#include <boost/url/url_view.hpp>
2222
#include <boost/system/error_code.hpp>
23-
#include <functional>
2423
#include <memory>
2524

2625
namespace boost {
@@ -75,16 +74,6 @@ struct BOOST_HTTP_SYMBOL_VISIBLE
7574
*/
7675
capy::datastore session_data;
7776

78-
/** The suspender for this session.
79-
80-
This can be used to suepend from the router and resume routing later.
81-
*/
82-
suspender suspend;
83-
84-
/** Executor associated with the session.
85-
*/
86-
capy::any_executor_ref ex;
87-
8877
/** Destructor
8978
*/
9079
BOOST_HTTP_DECL
@@ -114,161 +103,9 @@ struct BOOST_HTTP_SYMBOL_VISIBLE
114103
route_params&
115104
set_body(std::string s);
116105

117-
/** Read the request body and receive a value.
118-
119-
This function reads the entire request body into the specified sink.
120-
When the read operation completes, the given callback is invoked with
121-
the result.
122-
123-
The @p callback parameter must be a function object with this
124-
equivalent signature, where `T` is the type produced by the value sink:
125-
@code
126-
void ( T&& t );
127-
@endcode
128-
129-
@par Example
130-
@code
131-
rp.read_body(
132-
capy::string_body_sink(),
133-
[]( std::string s )
134-
{
135-
// body read successfully
136-
});
137-
@endcode
138-
139-
If an error or an exception occurs during the read, it is propagated
140-
through the router to the next error or exception handler.
141-
142-
@param sink The body sink to read into.
143-
@param callback The function to call when the read completes.
144-
@return The route result, which must be returned immediately
145-
from the route handler.
146-
*/
147-
template<
148-
class ValueSink,
149-
class Callback>
150-
auto
151-
read_body(
152-
ValueSink&& sink,
153-
Callback&& callback) ->
154-
route_result;
155-
156-
#ifdef BOOST_HTTP_HAS_CORO
157-
158-
/** Spawn a coroutine for this route.
159-
160-
This function is used to spawn a coroutine
161-
for the route handler. The coroutine is
162-
passed a reference to the route_params object,
163-
and when it returns, the returned route_result
164-
is returned from this function.
165-
166-
@par Example
167-
@code
168-
auto handler =
169-
[]( route_params& rp ) -> route_result
170-
{
171-
return rp.spawn(
172-
[]( route_params& rp ) -> capy::task<route_result>
173-
{
174-
co_return route_result::next;
175-
});
176-
};
177-
@endcode
178-
@param coro The coroutine to spawn.
179-
@return The route result, which must be returned immediately
180-
from the route handler.
181-
*/
182-
BOOST_HTTP_DECL
183-
auto spawn(
184-
capy::task<route_result> coro) ->
185-
route_result;
186-
187-
#endif
188-
189-
protected:
190-
std::function<void(void)> finish_;
106+
//http::route_task capy::task<http::route_result>
191107
};
192108

193-
//-----------------------------------------------
194-
195-
template<
196-
class ValueSink,
197-
class Callback>
198-
auto
199-
route_params::
200-
read_body(
201-
ValueSink&& sink,
202-
Callback&& callback) ->
203-
route_result
204-
{
205-
using T = typename std::decay<ValueSink>::type;
206-
207-
struct on_finish
208-
{
209-
T& sink;
210-
resumer resume;
211-
typename std::decay<Callback>::type cb;
212-
213-
on_finish(
214-
T& sink_,
215-
resumer resume_,
216-
Callback&& cb_)
217-
: sink(sink_)
218-
, resume(resume_)
219-
, cb(std::forward<Callback>(cb_))
220-
{
221-
}
222-
223-
void operator()()
224-
{
225-
resume(std::move(cb)(sink.release()));
226-
}
227-
};
228-
229-
return suspend(
230-
[&](resumer resume)
231-
{
232-
finish_ = on_finish(
233-
this->parser.set_body<T>(
234-
std::forward<ValueSink>(sink)),
235-
resume,
236-
std::forward<Callback>(callback));
237-
});
238-
}
239-
240-
//-----------------------------------------------
241-
242-
#ifdef BOOST_HTTP_HAS_CORO
243-
244-
/** Create a route handler from a coroutine function
245-
246-
This is a convenience function for creating
247-
route handlers from coroutine functions.
248-
249-
@par Signature
250-
The coroutine function must have this signature:
251-
@code
252-
capy::task<route_result>( route_params& rp );
253-
@endcode
254-
255-
@param f The coroutine function to invoke.
256-
@return A route handler object.
257-
*/
258-
inline
259-
auto
260-
co_route(std::function<
261-
capy::task<route_result>(route_params&)> f)
262-
{
263-
return
264-
[f_ = std::move(f)]( route_params& rp )
265-
{
266-
return rp.spawn(f_(rp));
267-
};
268-
}
269-
270-
#endif
271-
272109
} // http
273110
} // boost
274111

include/boost/http/server/router_types.hpp

Lines changed: 1 addition & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,6 @@ using route_result = system::error_code;
4242
*/
4343
enum class route
4444
{
45-
/** The handler requests that the connection be closed.
46-
47-
No further requests will be processed. The caller should
48-
close the connection once the current response, if any,
49-
has been sent.
50-
*/
51-
close = 1,
52-
53-
/** The handler completed the request.
54-
55-
The response has been fully transmitted, and no further
56-
handlers or routes will be invoked. The caller should continue
57-
by either reading the next request on a persistent connection
58-
or closing the session if it is not keep-alive.
59-
*/
60-
complete,
61-
62-
/** The handler is suspending the route.
63-
64-
When the handler returns this value, the router is placed into
65-
a suspended state which can later be reactivated by invoking
66-
@ref router::resume. Depending on the implementation,
67-
this might detach the handler from the session until it is
68-
resumed.
69-
*/
70-
suspend,
71-
7245
/** The handler declined to process the request.
7346
7447
The handler chose not to generate a response. The caller
@@ -88,15 +61,7 @@ enum class route
8861
caller stops invoking handlers in this route and resumes
8962
evaluation with the next candidate route.
9063
*/
91-
next_route,
92-
93-
/** The request was handled.
94-
95-
The route handler processed the request and prepared
96-
the response serializer. The caller will send the response
97-
before reading the next request or closing the connection.
98-
*/
99-
send
64+
next_route
10065
};
10166

10267
//------------------------------------------------
@@ -152,160 +117,6 @@ inline bool is_route_result(
152117

153118
//------------------------------------------------
154119

155-
class resumer;
156-
157-
/** Function to suspend a route handler from its session
158-
159-
This holds an reference to an implementation
160-
which suspends the router which dispatched the handler.
161-
*/
162-
class suspender
163-
{
164-
public:
165-
/** Base class of the implementation
166-
*/
167-
struct BOOST_HTTP_SYMBOL_VISIBLE
168-
owner
169-
{
170-
BOOST_HTTP_DECL
171-
virtual resumer do_suspend();
172-
virtual void do_resume(route_result const&) = 0;
173-
virtual void do_resume(std::exception_ptr) = 0;
174-
};
175-
176-
suspender() = default;
177-
suspender(suspender const&) = default;
178-
suspender& operator=(suspender const&) = default;
179-
180-
explicit
181-
suspender(
182-
owner& who) noexcept
183-
: p_(&who)
184-
{
185-
}
186-
187-
/** Suspend and invoke the given function
188-
189-
The function will be invoked with this equivalent signature:
190-
@code
191-
void( resumer );
192-
@endcode
193-
194-
@return A @ref route_result equal to @ref route::suspend
195-
*/
196-
template<class F>
197-
route_result
198-
operator()(F&& f);
199-
200-
private:
201-
friend resumer;
202-
// Clang doesn't consider uninstantiated templates
203-
// when checking for unused private fields.
204-
owner* p_
205-
#if defined(__clang__)
206-
__attribute__((unused))
207-
#endif
208-
= nullptr;
209-
};
210-
211-
//------------------------------------------------
212-
213-
/** Function to resume a suspended route.
214-
215-
This holds a reference to an implementation which resumes the handler's
216-
session. The resume function is typically obtained at the time the
217-
route is suspended.
218-
*/
219-
class resumer
220-
{
221-
public:
222-
/** Constructor
223-
224-
Default constructed resume functions will
225-
be empty. An exception is thrown when
226-
attempting to invoke an empty object.
227-
*/
228-
resumer() = default;
229-
230-
/** Constructor
231-
232-
Copies of resume functions behave the same
233-
as the original
234-
*/
235-
resumer(resumer const&) = default;
236-
237-
/** Assignment
238-
239-
Copies of resume functions behave the same
240-
as the original
241-
*/
242-
resumer& operator=(resumer const&) = default;
243-
244-
/** Constructor
245-
*/
246-
explicit
247-
resumer(
248-
suspender::owner& who) noexcept
249-
: p_(&who)
250-
{
251-
}
252-
253-
/** Resume the session
254-
255-
When a session is resumed, routing continues as if the handler
256-
had returned the @ref route_result contained in @p rv.
257-
258-
@param rv The route result to resume with.
259-
260-
@throw std::invalid_argument If the object is empty.
261-
*/
262-
void operator()(
263-
route_result const& rv) const
264-
{
265-
if(! p_)
266-
detail::throw_invalid_argument();
267-
p_->do_resume(rv);
268-
}
269-
270-
/** Resume the session with an exception
271-
272-
When a session is resumed with an exception, the exception
273-
is propagated through the router's error handling mechanism.
274-
275-
@param ep The exception to propagate.
276-
277-
@throw std::invalid_argument If the object is empty.
278-
*/
279-
void operator()(
280-
std::exception_ptr ep) const
281-
{
282-
if(! p_)
283-
detail::throw_invalid_argument();
284-
p_->do_resume(ep);
285-
}
286-
287-
private:
288-
suspender::owner* p_
289-
#if defined(__clang__)
290-
__attribute__((unused))
291-
#endif
292-
= nullptr;
293-
};
294-
295-
template<class F>
296-
auto
297-
suspender::
298-
operator()(F&& f) ->
299-
route_result
300-
{
301-
if(! p_)
302-
detail::throw_logic_error();
303-
std::forward<F>(f)(p_->do_suspend());
304-
return route::suspend;
305-
}
306-
307-
//------------------------------------------------
308-
309120
namespace detail {
310121
class router_base;
311122
} // detail

0 commit comments

Comments
 (0)