Skip to content

Commit d00f25b

Browse files
committed
feat(http): 添加Router中的opt(),head(),trace()方法
1 parent db62bb0 commit d00f25b

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

modules/http/server/router.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void Router::handle(ContextSptr sp_ctx, const NextFunc &next)
4545
case Method::kPut: prefix = "put:"; break;
4646
case Method::kPost: prefix = "post:"; break;
4747
case Method::kDelete: prefix = "del:"; break;
48+
case Method::kOptions: prefix = "opt:"; break;
49+
case Method::kHead: prefix = "head:"; break;
50+
case Method::kTrace: prefix = "trace:"; break;
4851
default:;
4952
}
5053

@@ -82,6 +85,24 @@ Router& Router::del(const std::string &path, const RequestCallback &cb)
8285
return *this;
8386
}
8487

88+
Router& Router::opt(const std::string &path, const RequestCallback &cb)
89+
{
90+
d_->cbs_[std::string("opt:") + path] = cb;
91+
return *this;
92+
}
93+
94+
Router& Router::head(const std::string &path, const RequestCallback &cb)
95+
{
96+
d_->cbs_[std::string("head:") + path] = cb;
97+
return *this;
98+
}
99+
100+
Router& Router::trace(const std::string &path, const RequestCallback &cb)
101+
{
102+
d_->cbs_[std::string("trace:") + path] = cb;
103+
return *this;
104+
}
105+
85106
}
86107
}
87108
}

modules/http/server/router.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ class Router : public Middleware {
3333
~Router();
3434

3535
public:
36-
Router& get (const std::string &path, const RequestCallback &cb);
37-
Router& post(const std::string &path, const RequestCallback &cb);
38-
Router& put (const std::string &path, const RequestCallback &cb);
39-
Router& del (const std::string &path, const RequestCallback &cb);
36+
Router& get (const std::string &path, const RequestCallback &cb);
37+
Router& post (const std::string &path, const RequestCallback &cb);
38+
Router& put (const std::string &path, const RequestCallback &cb);
39+
Router& del (const std::string &path, const RequestCallback &cb);
40+
Router& opt (const std::string &path, const RequestCallback &cb);
41+
Router& head (const std::string &path, const RequestCallback &cb);
42+
Router& trace(const std::string &path, const RequestCallback &cb);
4043

4144
public:
4245
virtual void handle(ContextSptr sp_ctx, const NextFunc &next) override;

0 commit comments

Comments
 (0)