| 379 | } |
| 380 | |
| 381 | bool |
| 382 | handleNextServerHeader(Data *const data) |
| 383 | { |
| 384 | // block response header |
| 385 | HttpHeader header(data->m_resp_hdrmgr.m_buffer, data->m_resp_hdrmgr.m_lochdr); |
| 386 | if (dbg_ctl.on()) { |
| 387 | DEBUG_LOG("Next Header:\n%s", header.toString().c_str()); |
| 388 | } |
| 389 | |
| 390 | bool same = true; |
| 391 | |
| 392 | switch (header.status()) { |
| 393 | case TS_HTTP_STATUS_NOT_FOUND: |
| 394 | if (data->onlyHeader()) { |
| 395 | return false; |
| 396 | } |
| 397 | // need to reissue reference slice |
| 398 | logSliceError("404 internal block response (asset gone)", data, header); |
| 399 | same = false; |
| 400 | break; |
| 401 | case TS_HTTP_STATUS_PARTIAL_CONTENT: |
| 402 | break; |
| 403 | default: |
| 404 | if (data->onlyHeader() && header.status() == TS_HTTP_STATUS_OK) { |
| 405 | return true; |
| 406 | } |
| 407 | DEBUG_LOG("Non 206/404 internal block response encountered"); |
| 408 | return false; |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | // can't parse the content range header, abort -- might be too strict |
| 413 | ContentRange blockcr; |
| 414 | |
| 415 | if (same) { |
| 416 | blockcr = contentRangeFrom(header); |
| 417 | if (!blockcr.isValid() || blockcr.m_length != data->m_contentlen) { |
| 418 | logSliceError("Mismatch/Bad block Content-Range", data, header); |
| 419 | same = false; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | if (same) { |
| 424 | // prefer the etag but use Last-Modified if we must. |
| 425 | char etag[8192]; |
| 426 | int etaglen = sizeof(etag); |
| 427 | header.valueForKey(TS_MIME_FIELD_ETAG, TS_MIME_LEN_ETAG, etag, &etaglen); |
| 428 | |
| 429 | if (0 < data->m_etaglen || 0 < etaglen) { |
| 430 | same = data->m_etaglen == etaglen && 0 == strncmp(etag, data->m_etag, etaglen); |
| 431 | if (!same) { |
| 432 | logSliceError("Mismatch block Etag", data, header); |
| 433 | } |
| 434 | } else { |
| 435 | char lastmodified[33]; |
| 436 | int lastmodifiedlen = sizeof(lastmodified); |
| 437 | header.valueForKey(TS_MIME_FIELD_LAST_MODIFIED, TS_MIME_LEN_LAST_MODIFIED, lastmodified, &lastmodifiedlen); |
| 438 | if (0 < data->m_lastmodifiedlen || 0 < lastmodifiedlen) { |
no test coverage detected