Skip to content

Commit 5bcc2ca

Browse files
committed
Move example router to examples
1 parent 182e5fa commit 5bcc2ca

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎coroio/http/httpd.hpp‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,6 @@ struct IRouter {
197197
virtual TFuture<void> HandleRequest(TRequest& request, TResponse& response) = 0;
198198
};
199199

200-
class THelloWorldRouter : public IRouter {
201-
public:
202-
TFuture<void> HandleRequest(TRequest& request, TResponse& response) override {
203-
if (request.Uri().Path() == "/") {
204-
response.SetStatus(200);
205-
response.SetHeader("Content-Type", "text/plain");
206-
response.SetHeader("Connection", "close");
207-
co_await response.SendHeaders();
208-
co_await response.WriteBodyFull("Hello, World!");
209-
} else {
210-
response.SetStatus(404);
211-
response.SetHeader("Content-Type", "text/plain");
212-
response.SetHeader("Connection", "close");
213-
co_await response.SendHeaders();
214-
co_await response.WriteBodyFull("Not Found");
215-
}
216-
}
217-
};
218-
219200
/**
220201
* @brief HTTP/1.1 server that accepts connections and dispatches to a router.
221202
*

‎examples/hello_httpd.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77

88
using namespace NNet;
99

10+
class THelloWorldRouter : public IRouter {
11+
public:
12+
TFuture<void> HandleRequest(TRequest& request, TResponse& response) override {
13+
if (request.Uri().Path() == "/") {
14+
response.SetStatus(200);
15+
response.SetHeader("Content-Type", "text/plain");
16+
response.SetHeader("Connection", "close");
17+
co_await response.SendHeaders();
18+
co_await response.WriteBodyFull("Hello, World!");
19+
} else {
20+
response.SetStatus(404);
21+
response.SetHeader("Content-Type", "text/plain");
22+
response.SetHeader("Connection", "close");
23+
co_await response.SendHeaders();
24+
co_await response.WriteBodyFull("Not Found");
25+
}
26+
}
27+
};
28+
1029
int main(int argc, char** argv) {
1130
NNet::TInitializer init;
1231
int port = 8080;

0 commit comments

Comments
 (0)