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

Function request_block

plugins/slice/util.cc:49–174  ·  view source on GitHub ↗

create and issue a block request

Source from the content-addressed store, hash-verified

47
48// create and issue a block request
49bool
50request_block(TSCont contp, Data *const data)
51{
52 // ensure no upstream connection
53 if (data->m_upstream.m_read.isOpen()) {
54 ERROR_LOG("Block request already in flight!");
55 return false;
56 }
57
58 switch (data->m_blockstate) {
59 case BlockState::Pending:
60 case BlockState::PendingInt:
61 case BlockState::PendingRef:
62 break;
63 default:
64 ERROR_LOG("request_block called with non Pending* state!");
65 return false;
66 break;
67 }
68
69 int64_t const blockbeg = (data->m_config->m_blockbytes * data->m_blocknum);
70 Range blockbe(blockbeg, blockbeg + data->m_config->m_blockbytes);
71
72 char rangestr[1024];
73 int rangelen = sizeof(rangestr);
74 bool const rpstat = blockbe.toStringClosed(rangestr, &rangelen);
75 TSAssert(rpstat);
76
77 DEBUG_LOG("requestBlock: %s", rangestr);
78
79 // reuse the incoming client header, just change the range
80 HttpHeader header(data->m_req_hdrmgr.m_buffer, data->m_req_hdrmgr.m_lochdr);
81
82 // if configured, remove range header from head requests
83 if (data->m_method_type == TS_HTTP_METHOD_HEAD && data->m_config->m_head_strip_range) {
84 header.removeKey(TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE);
85 } else {
86 // add/set sub range key and add slicer tag
87 bool const rangestat = header.setKeyVal(TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE, rangestr, rangelen);
88
89 if (!rangestat) {
90 ERROR_LOG("Error trying to set range request header %s", rangestr);
91 return false;
92 }
93 }
94
95 header.removeKey(SLICE_CRR_HEADER.data(), SLICE_CRR_HEADER.size());
96 if (data->m_config->m_prefetchcount > 0 && data->m_req_range.m_beg >= 0 &&
97 data->m_blocknum == data->m_req_range.firstBlockFor(data->m_config->m_blockbytes)) {
98 header.setKeyVal(SLICE_CRR_HEADER.data(), SLICE_CRR_HEADER.size(), SLICE_CRR_VAL.data(), SLICE_CRR_VAL.size());
99 }
100
101 // create virtual connection back into ATS
102 TSHttpConnectOptions options = TSHttpConnectOptionsGet(TS_CONNECT_PLUGIN);
103 options.addr = reinterpret_cast<sockaddr *>(&data->m_client_ip);
104 options.tag = PLUGIN_NAME;
105 options.id = 0;
106 options.buffer_index = data->m_buffer_index;

Callers 3

handle_server_respFunction · 0.85
handle_client_reqFunction · 0.85
handle_client_respFunction · 0.85

Calls 15

TSHttpConnectOptionsGetFunction · 0.85
TSHttpConnectPluginFunction · 0.85
TSHttpHdrLengthGetFunction · 0.85
TSHttpHdrPrintFunction · 0.85
TSVIOReenableFunction · 0.85
TSHttpParserClearFunction · 0.85
removeKeyMethod · 0.80
setKeyValMethod · 0.80
firstBlockForMethod · 0.80
setupConnectionMethod · 0.80
setupVioWriteMethod · 0.80
blockIsInsideMethod · 0.80

Tested by

no test coverage detected