You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "maskit (via GitHub)" <gi...@apache.org> on 2023/04/12 19:53:56 UTC

[GitHub] [trafficserver] maskit commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

maskit commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1164575910


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +511,72 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req);

Review Comment:
   Good catch. I added error handling.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org