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

Function query_responder

src/iocore/net/OCSPStapling.cc:1032–1108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1030}
1031
1032static TS_OCSP_RESPONSE *
1033query_responder(const char *uri, const char *user_agent, TS_OCSP_REQUEST *req, int req_timeout, bool use_get)
1034{
1035 ink_hrtime start, end;
1036 TS_OCSP_RESPONSE *resp = nullptr;
1037
1038 start = ink_get_hrtime();
1039 end = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
1040
1041 HTTPRequest httpreq;
1042
1043 httpreq.set_request_line(use_get, uri);
1044
1045 // Host header
1046 const char *host = strstr(uri, "://") + 3;
1047 const char *slash = strchr(host, '/');
1048 if (slash == nullptr) {
1049 slash = host + strlen(host);
1050 }
1051 int host_len = slash - host;
1052 httpreq.add_header("Host", 4, host, host_len);
1053
1054 // User-Agent header
1055 if (user_agent != nullptr) {
1056 httpreq.add_header("User-Agent", user_agent);
1057 }
1058
1059 // Content-Type, Content-Length, Request Body
1060 if (!use_get) {
1061 if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(TS_OCSP_REQUEST), reinterpret_cast<const ASN1_VALUE *>(req)) !=
1062 1) {
1063 Error("failed to make a request for OCSP server; uri=%s", uri);
1064 return nullptr;
1065 }
1066 }
1067
1068 // Send request
1069 Event *e = eventProcessor.schedule_imm(&httpreq, ET_NET);
1070
1071 // Wait until the request completes
1072 do {
1073 ink_hrtime_sleep(HRTIME_MSECONDS(1));
1074 } while (!httpreq.is_done() && (ink_get_hrtime() < end));
1075
1076 if (!httpreq.is_done()) {
1077 Error("OCSP request was timed out; uri=%s", uri);
1078 if (!httpreq.is_initiated()) {
1079 Dbg(dbg_ctl_ssl_ocsp, "Request is not initiated yet. Cancelling the event.");
1080 e->cancel(&httpreq);
1081 }
1082 }
1083
1084 if (httpreq.is_success()) {
1085 // Parse the response
1086 int len;
1087 unsigned char *res = httpreq.get_response_body(&len);
1088 const unsigned char *p = res;
1089 resp = reinterpret_cast<TS_OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(TS_OCSP_RESPONSE)));

Callers 1

Calls 15

ink_get_hrtimeFunction · 0.85
ink_hrtime_addFunction · 0.85
ink_hrtime_from_secFunction · 0.85
ink_hrtime_sleepFunction · 0.85
ats_freeFunction · 0.85
set_request_lineMethod · 0.80
add_headerMethod · 0.80
set_bodyMethod · 0.80
is_initiatedMethod · 0.80
is_successMethod · 0.80
get_response_bodyMethod · 0.80
ErrorClass · 0.50

Tested by

no test coverage detected