| 19 | } |
| 20 | |
| 21 | void THttpResponse::OutTo(IOutputStream& os) const { |
| 22 | TVector<IOutputStream::TPart> parts; |
| 23 | const size_t FIRST_LINE_PARTS = 3; |
| 24 | const size_t HEADERS_PARTS = Headers.Count() * 4; |
| 25 | const size_t CONTENT_PARTS = 5; |
| 26 | parts.reserve(FIRST_LINE_PARTS + HEADERS_PARTS + CONTENT_PARTS); |
| 27 | |
| 28 | // first line |
| 29 | parts.push_back(IOutputStream::TPart(TStringBuf("HTTP/1.1 "))); |
| 30 | parts.push_back(IOutputStream::TPart(HttpCodeStrEx(Code))); |
| 31 | parts.push_back(IOutputStream::TPart::CrLf()); |
| 32 | |
| 33 | // headers |
| 34 | for (THttpHeaders::TConstIterator i = Headers.Begin(); i != Headers.End(); ++i) { |
| 35 | parts.push_back(IOutputStream::TPart(i->Name())); |
| 36 | parts.push_back(IOutputStream::TPart(TStringBuf(": "))); |
| 37 | parts.push_back(IOutputStream::TPart(i->Value())); |
| 38 | parts.push_back(IOutputStream::TPart::CrLf()); |
| 39 | } |
| 40 | |
| 41 | char buf[50]; |
| 42 | |
| 43 | if (!Content.empty()) { |
| 44 | TMemoryOutput mo(buf, sizeof(buf)); |
| 45 | |
| 46 | mo << Content.size(); |
| 47 | |
| 48 | parts.push_back(IOutputStream::TPart(TStringBuf("Content-Length: "))); |
| 49 | parts.push_back(IOutputStream::TPart(buf, mo.Buf() - buf)); |
| 50 | parts.push_back(IOutputStream::TPart::CrLf()); |
| 51 | } |
| 52 | |
| 53 | // content |
| 54 | parts.push_back(IOutputStream::TPart::CrLf()); |
| 55 | |
| 56 | if (!Content.empty()) { |
| 57 | parts.push_back(IOutputStream::TPart(Content)); |
| 58 | } |
| 59 | |
| 60 | os.Write(parts.data(), parts.size()); |
| 61 | } |
| 62 | |
| 63 | template <> |
| 64 | void Out<THttpResponse>(IOutputStream& os, const THttpResponse& resp) { |
no test coverage detected