@brief class with a method that responses to requests. */
| 22 | @brief class with a method that responses to requests. |
| 23 | */ |
| 24 | class TRequestServer { |
| 25 | public: |
| 26 | TRequestServer(std::function<void(const IRequestRef&)> f = [](const IRequestRef& req) { |
| 27 | TDataSaver responseData; |
| 28 | Sleep(TDuration::MilliSeconds(FromString<int>(req->Data()))); |
| 29 | responseData << req->Data(); |
| 30 | auto* httpReq = dynamic_cast<IHttpRequest*>(req.Get()); |
| 31 | TString headers = "\r\nContent-Type: text/plain"; |
| 32 | httpReq->SendReply(responseData, headers); |
| 33 | }) |
| 34 | : F_(f) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | void ServeRequest(const IRequestRef& req) { |
| 39 | F_(req); |
| 40 | // Cerr << "SendReply:" << req->Data() << Endl; |
| 41 | } |
| 42 | private: |
| 43 | std::function<void(const IRequestRef&)> F_; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | @brief Auxiliary struct for tests with info about running services. |