MCPcopy Create free account
hub / github.com/apache/trafficserver / prepareResponse

Function prepareResponse

plugins/esi/combo_handler.cc:951–1069  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

949}
950
951static void
952prepareResponse(InterceptData &int_data, ByteBlockList &body_blocks, string &resp_header_fields)
953{
954 if (int_data.creq.status == TS_HTTP_STATUS_OK) {
955 HttpDataFetcherImpl::ResponseData resp_data;
956 TSMLoc field_loc;
957 time_t expires_time;
958 bool got_expires_time = false;
959 int num_headers = HEADER_ALLOWLIST.size();
960 int flags_list[num_headers];
961 CacheControlHeader cch;
962
963 for (int i = 0; i < num_headers; i++) {
964 flags_list[i] = 0;
965 }
966
967 ContentTypeHandler cth(resp_header_fields);
968
969 for (StringList::iterator iter = int_data.creq.file_urls.begin(); iter != int_data.creq.file_urls.end(); ++iter) {
970 if (int_data.fetcher->getData(*iter, resp_data) && resp_data.status == TS_HTTP_STATUS_OK) {
971 body_blocks.push_back(ByteBlock(resp_data.content, resp_data.content_len));
972 if (find(HEADER_ALLOWLIST.begin(), HEADER_ALLOWLIST.end(), TS_MIME_FIELD_CONTENT_TYPE) == HEADER_ALLOWLIST.end()) {
973 if (!cth.nextObjectHeader(resp_data.bufp, resp_data.hdr_loc)) {
974 LOG_ERROR("Content type missing or forbidden for requested URL [%s]", iter->c_str());
975 int_data.creq.status = TS_HTTP_STATUS_FORBIDDEN;
976 break;
977 }
978 }
979
980 // Load this document's Cache-Control header into our managing object
981 cch.update(resp_data.bufp, resp_data.hdr_loc);
982
983 field_loc = TSMimeHdrFieldFind(resp_data.bufp, resp_data.hdr_loc, TS_MIME_FIELD_EXPIRES, TS_MIME_LEN_EXPIRES);
984 if (field_loc != TS_NULL_MLOC) {
985 time_t curr_field_expires_time;
986 int n_values = TSMimeHdrFieldValuesCount(resp_data.bufp, resp_data.hdr_loc, field_loc);
987 if ((n_values != TS_ERROR) && (n_values > 0)) {
988 curr_field_expires_time = TSMimeHdrFieldValueDateGet(resp_data.bufp, resp_data.hdr_loc, field_loc);
989 if (!got_expires_time) {
990 expires_time = curr_field_expires_time;
991 got_expires_time = true;
992 } else if (curr_field_expires_time < expires_time) {
993 expires_time = curr_field_expires_time;
994 }
995 }
996 TSHandleMLocRelease(resp_data.bufp, resp_data.hdr_loc, field_loc);
997 }
998
999 for (int i = 0; i < num_headers; i++) {
1000 if (flags_list[i]) {
1001 continue;
1002 }
1003
1004 const string &header = HEADER_ALLOWLIST[i];
1005
1006 field_loc = TSMimeHdrFieldFind(resp_data.bufp, resp_data.hdr_loc, header.c_str(), header.size());
1007 if (field_loc != TS_NULL_MLOC) {
1008 bool values_added = false;

Callers 1

writeResponseFunction · 0.85

Calls 15

ByteBlockClass · 0.85
TSMimeHdrFieldFindFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
gzipFunction · 0.85
nextObjectHeaderMethod · 0.80
generateMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected