| 114 | } |
| 115 | |
| 116 | HeaderState |
| 117 | handleFirstServerHeader(Data *const data, TSCont const contp) |
| 118 | { |
| 119 | HttpHeader header(data->m_resp_hdrmgr.m_buffer, data->m_resp_hdrmgr.m_lochdr); |
| 120 | |
| 121 | if (dbg_ctl.on()) { |
| 122 | DEBUG_LOG("First header\n%s", header.toString().c_str()); |
| 123 | } |
| 124 | |
| 125 | data->m_dnstream.setupVioWrite(contp, INT64_MAX); |
| 126 | |
| 127 | TSVIO const output_vio = data->m_dnstream.m_write.m_vio; |
| 128 | TSIOBuffer const output_buf = data->m_dnstream.m_write.m_iobuf; |
| 129 | |
| 130 | // only process a 206, everything else gets a (possibly incomplete) |
| 131 | // pass through |
| 132 | if (TS_HTTP_STATUS_PARTIAL_CONTENT != header.status()) { |
| 133 | DEBUG_LOG("Initial response other than 206: %d", header.status()); |
| 134 | |
| 135 | // Should run TSVIONSetBytes(output_io, hlen + bodybytes); |
| 136 | int64_t const hlen = TSHttpHdrLengthGet(header.m_buffer, header.m_lochdr); |
| 137 | int64_t const clen = contentLengthFrom(header); |
| 138 | if (TS_HTTP_STATUS_OK == header.status() && data->onlyHeader()) { |
| 139 | DEBUG_LOG("HEAD/PURGE request stripped Range header: expects 200"); |
| 140 | data->m_bytestosend = hlen; |
| 141 | data->m_blockexpected = 0; |
| 142 | TSVIONBytesSet(output_vio, hlen); |
| 143 | TSHttpHdrPrint(header.m_buffer, header.m_lochdr, output_buf); |
| 144 | data->m_bytessent = hlen; |
| 145 | TSVIOReenable(output_vio); |
| 146 | return HeaderState::Good; |
| 147 | } |
| 148 | DEBUG_LOG("Passthru bytes: header: %" PRId64 " body: %" PRId64, hlen, clen); |
| 149 | if (clen != INT64_MAX) { |
| 150 | update_object_size(data->m_txnp, clen, *data->m_config); |
| 151 | TSVIONBytesSet(output_vio, hlen + clen); |
| 152 | } else { |
| 153 | TSVIONBytesSet(output_vio, clen); |
| 154 | } |
| 155 | TSHttpHdrPrint(header.m_buffer, header.m_lochdr, output_buf); |
| 156 | return HeaderState::Passthru; |
| 157 | } |
| 158 | |
| 159 | ContentRange const blockcr = contentRangeFrom(header); |
| 160 | |
| 161 | // 206 with bad content range -- should NEVER happen. |
| 162 | if (!blockcr.isValid()) { |
| 163 | std::string const msg502 = string502(header.version()); |
| 164 | TSVIONBytesSet(output_vio, msg502.size()); |
| 165 | TSIOBufferWrite(output_buf, msg502.data(), msg502.size()); |
| 166 | TSVIOReenable(output_vio); |
| 167 | return HeaderState::Fail; |
| 168 | } |
| 169 | |
| 170 | update_object_size(data->m_txnp, blockcr.m_length, *data->m_config); |
| 171 | |
| 172 | // set the resource content length from block response |
| 173 | data->m_contentlen = blockcr.m_length; |
no test coverage detected