| 24 | } |
| 25 | |
| 26 | bool Reply(void* /*tsr*/) override { |
| 27 | if (!ProcessHeaders()) { |
| 28 | return true; |
| 29 | } |
| 30 | |
| 31 | // Check that function will not hang on |
| 32 | Input().ReadAll(); |
| 33 | |
| 34 | // "lo" is for "local" |
| 35 | if (RD.ServerName() == "yandex.lo") { |
| 36 | // do redirect |
| 37 | Output() << "HTTP/1.1 301 Moved permanently\r\n" |
| 38 | "Location: http://www.yandex.lo\r\n" |
| 39 | "\r\n"; |
| 40 | } else if (RD.ServerName() == "www.yandex.lo") { |
| 41 | Output() << "HTTP/1.1 200 Ok\r\n" |
| 42 | "\r\n"; |
| 43 | } else { |
| 44 | Output() << "HTTP/1.1 200 Ok\r\n\r\n"; |
| 45 | if (Buf.Size()) { |
| 46 | Output().Write(Buf.AsCharPtr(), Buf.Size()); |
| 47 | } else { |
| 48 | Output() << Parent_->Res_; |
| 49 | } |
| 50 | } |
| 51 | Output().Finish(); |
| 52 | |
| 53 | Parent_->LastRequestSentSize_ = Output().SentSize(); |
| 54 | |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | TTestHttpServer* Parent_ = nullptr; |