| 803 | } |
| 804 | |
| 805 | inline void RebuildStream() { |
| 806 | bool keepAlive = false; |
| 807 | const TCompressionCodecFactory::TEncoderConstructor* encoder = nullptr; |
| 808 | bool chunked = false; |
| 809 | bool haveContentLength = false; |
| 810 | |
| 811 | for (THttpHeaders::TConstIterator h = Headers_.Begin(); h != Headers_.End(); ++h) { |
| 812 | const THttpInputHeader& header = *h; |
| 813 | const TString hl = to_lower(header.Name()); |
| 814 | |
| 815 | if (hl == TStringBuf("connection")) { |
| 816 | keepAlive = to_lower(header.Value()) == TStringBuf("keep-alive"); |
| 817 | } else if (IsCompressionHeaderEnabled() && hl == TStringBuf("content-encoding")) { |
| 818 | encoder = TCompressionCodecFactory::Instance().FindEncoder(to_lower(header.Value())); |
| 819 | } else if (hl == TStringBuf("transfer-encoding")) { |
| 820 | chunked = to_lower(header.Value()) == TStringBuf("chunked"); |
| 821 | } else if (hl == TStringBuf("content-length")) { |
| 822 | haveContentLength = true; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | if (!haveContentLength && !chunked && (IsHttpRequest() || HasResponseBody()) && SupportChunkedTransfer() && (keepAlive || encoder || IsHttpRequest())) { |
| 827 | AddHeader(THttpInputHeader("Transfer-Encoding", "chunked")); |
| 828 | chunked = true; |
| 829 | } |
| 830 | |
| 831 | if (IsBodyEncodingEnabled() && chunked) { |
| 832 | Output_ = Streams_.Add(new TChunkedOutput(Output_)); |
| 833 | } |
| 834 | |
| 835 | Output_ = Streams_.Add(new TTeeOutput(Output_, &SizeCalculator_)); |
| 836 | |
| 837 | if (IsBodyEncodingEnabled() && encoder) { |
| 838 | Output_ = Streams_.Add((*encoder)(Output_).Release()); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | inline void AddHeader(const THttpInputHeader& hdr) { |
| 843 | Headers_.AddHeader(hdr); |
nothing calls this directly
no test coverage detected