Skip to content

Commit

Permalink
http: clarify the ownership in the router's doxygen comment
Browse files Browse the repository at this point in the history
Emphasize pointer ownership and deletion responsibility for each of methods which work with raw pointers

Closes #2423
  • Loading branch information
kreuzerkrieg authored and xemul committed Sep 19, 2024
1 parent 0b752bb commit f44a799
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions include/seastar/http/routes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct path_description;
/**
* routes object do the request dispatching according to the url.
* It uses two decision mechanism exact match, if a url matches exactly
* (an optional leading slash is permitted) it is choosen
* (an optional leading slash is permitted) it is chosen
* If not, the matching rules are used.
* matching rules are evaluated by their insertion order
*/
Expand All @@ -89,7 +89,11 @@ public:
* adding a handler as an exact match
* @param url the url to match (note that url should start with /)
* @param handler the desire handler
* @return it self
* @return itself
* @attention If successful, this method takes ownership of the handler
pointer. It will be automatically deleted when the routes instance is
destroyed. However, if the method throws, the caller is responsible
for deleting the handler pointer.
*/
routes& put(operation_type type, const sstring& url, handler_base* handler);

Expand All @@ -107,7 +111,9 @@ public:
* First in higher priority
* @param rule a rule to add
* @param type the operation type
* @return it self
* @return itself
* @attention This method takes ownership of the match_rule pointer. It will be automatically deleted when the
* routes instance is destroyed.
*/
routes& add(match_rule* rule, operation_type type = GET) {
_rules[type][_rover++] = rule;
Expand All @@ -121,6 +127,8 @@ public:
* @param url
* @param handler
* @return
* @attention This method takes ownership of the handler's pointer.It will be automatically deleted when the routes
* instance is destroyed.
*/
routes& add(operation_type type, const url& url, handler_base* handler);

Expand All @@ -129,6 +137,7 @@ public:
* Example routes.add_default_handler(handler);
* @param handler
* @return
* @attention The caller must keep the @c handler active as long as the route instance is active.
*/
routes& add_default_handler(handler_base* handler);

Expand All @@ -137,7 +146,7 @@ public:
* the general handler calls this method with the request
* the method takes the headers from the request and find the
* right handler.
* It then call the handler with the parameters (if they exists) found in the url
* It then calls the handler with the parameters (if they exist) found in the url
* @param path the url path found
* @param req the http request
* @param rep the http reply
Expand Down Expand Up @@ -169,7 +178,6 @@ private:
* Normalize the url to remove the last / if exists
* and get the parameter part
* @param url the full url path
* @param param_part will hold the string with the parameters
* @return the url from the request without the last /
*/
sstring normalize_url(const sstring& url);
Expand Down Expand Up @@ -225,6 +233,8 @@ public:
* @param rule a rule to add
* @param type the operation type
* @return a cookie using which the rule can be removed
* @attention This method takes ownership of the match_rule pointer. It will be automatically deleted when the
* routes instance is destroyed.
*/
rule_cookie add_cookie(match_rule* rule, operation_type type) {
auto pos = _rover++;
Expand All @@ -237,6 +247,7 @@ public:
* @param cookie a cookie returned previously by add_cookie
* @param type the operation type
* @return the pointer to the rule
* @attention Ownership of the pointer is returned to the caller.
*/
match_rule* del_cookie(rule_cookie cookie, operation_type type);
};
Expand Down

0 comments on commit f44a799

Please sign in to comment.