* handle_content_length_header(...) * Function handles the insertion of content length headers into * header. header CAN equal base. */
| 6662 | * header. header CAN equal base. |
| 6663 | */ |
| 6664 | void |
| 6665 | HttpTransact::handle_content_length_header(State *s, HTTPHdr *header, HTTPHdr *base) |
| 6666 | { |
| 6667 | int64_t cl = HTTP_UNDEFINED_CL; |
| 6668 | ink_assert(header->type_get() == HTTP_TYPE_RESPONSE); |
| 6669 | if (base->presence(MIME_PRESENCE_CONTENT_LENGTH)) { |
| 6670 | cl = base->get_content_length(); |
| 6671 | if (cl >= 0) { |
| 6672 | // header->set_content_length(cl); |
| 6673 | ink_assert(header->get_content_length() == cl); |
| 6674 | |
| 6675 | switch (s->source) { |
| 6676 | case SOURCE_HTTP_ORIGIN_SERVER: |
| 6677 | // We made our decision about whether to trust the |
| 6678 | // response content length in init_state_vars_from_response() |
| 6679 | if (s->range_setup != HttpTransact::RANGE_NOT_TRANSFORM_REQUESTED) { |
| 6680 | break; |
| 6681 | } |
| 6682 | // fallthrough |
| 6683 | |
| 6684 | case SOURCE_CACHE: |
| 6685 | // if we are doing a single Range: request, calculate the new |
| 6686 | // C-L: header |
| 6687 | if (s->range_setup == HttpTransact::RANGE_NOT_TRANSFORM_REQUESTED) { |
| 6688 | change_response_header_because_of_range_request(s, header); |
| 6689 | s->hdr_info.trust_response_cl = true; |
| 6690 | } |
| 6691 | //////////////////////////////////////////////// |
| 6692 | // Make sure that the cache's object size // |
| 6693 | // agrees with the Content-Length // |
| 6694 | // Otherwise, set the state's machine view // |
| 6695 | // of c-l to undefined to turn off K-A // |
| 6696 | //////////////////////////////////////////////// |
| 6697 | else if (s->cache_info.object_read->object_size_get() == cl) { |
| 6698 | s->hdr_info.trust_response_cl = true; |
| 6699 | } else { |
| 6700 | TxnDbg(dbg_ctl_http_trans, "Content Length header and cache object size mismatch." |
| 6701 | "Disabling keep-alive"); |
| 6702 | s->hdr_info.trust_response_cl = false; |
| 6703 | } |
| 6704 | break; |
| 6705 | |
| 6706 | case SOURCE_TRANSFORM: |
| 6707 | if (s->range_setup == HttpTransact::RANGE_REQUESTED) { |
| 6708 | header->set_content_length(s->range_output_cl); |
| 6709 | s->hdr_info.trust_response_cl = true; |
| 6710 | } else if (s->hdr_info.transform_response_cl == HTTP_UNDEFINED_CL) { |
| 6711 | s->hdr_info.trust_response_cl = false; |
| 6712 | } else { |
| 6713 | s->hdr_info.trust_response_cl = true; |
| 6714 | } |
| 6715 | break; |
| 6716 | |
| 6717 | default: |
| 6718 | ink_release_assert(0); |
| 6719 | break; |
| 6720 | } |
| 6721 | } else { |
nothing calls this directly
no test coverage detected