PDFium Delphi Component Docs

FPdfCryptoHttpCurl 单元

单元: FPdfCryptoHttpCurl
Free Pascal 下基于 libcurl 的 HTTP(S) 传输后端,在非 Windows 目标上替 TPdfCryptoFetchSession 执行有上限的 GET 与 POST 获取

语法

function CryptoCurlAvailable: Boolean;
function CryptoCurlGet(const Url: AnsiString; TimeoutMs: Cardinal;
  MaxBytes: Integer; out Data: TBytes; out DownloadedBytes: Integer;
  const ConnectTo: AnsiString = ''): Boolean;
function CryptoCurlPost(const Url: AnsiString; const Body: TBytes;
  const ContentType: AnsiString; TimeoutMs: Cardinal; MaxBytes: Integer;
  out Data: TBytes; out DownloadedBytes: Integer;
  const ConnectTo: AnsiString = ''): Boolean;

说明

FPdfCryptoHttpCurl 是 FPdfCryptoHttp 在线获取传输层的非 Windows 那一半:在 Linux 和 macOS 上,TPdfCryptoFetchSession.Fetch 与 TPdfCryptoFetchSession.FetchPost 为 AIA 中间证书、CRL 分发点和 OCSP 请求发起的每一次 HTTP(S) 获取,都走 CryptoCurlGet 或 CryptoCurlPost;Windows 目标则用 FPdfCryptoHttp 内部的 WinHttp 路径。离开 Windows 后,FPdfCryptoHttp 中的 CryptoHttpAvailable 直接委托给 CryptoCurlAvailable

底层传输是 libcurl,运行时动态绑定而不是静态链接:Linux 上是 libcurl.so.4,macOS 上是 libcurl.4.dylib,FPC 的 Windows 目标上是 libcurl.dll 或 libcurl-4.dll——不过 Windows 上获取会话优先用 WinHttp,根本不会调进这个单元。只有同时报告 CURL_VERSION_ASYNCHDNS 和 CURL_VERSION_THREADSAFE 两项特性的模块才会被采用:传输在屏蔽信号的情况下按毫秒级预算运行,全局初始化器也必须能与 worker 线程安全共存;不满足条件的 libcurl 一律按不存在处理,不会拿来用

时间戳传输也受同一项可用性检查约束:FPdfTsaFpc 中的 TsaHttpAvailable 除了要求自己的入口点,还要求 CryptoCurlAvailable 成立,因此证书获取和 RFC 3161 请求共用同一个具备所需特性的 libcurl 模块

所有失败路径都返回 False 而不抛异常,此时 Data 为 nil,DownloadedBytes 保存截至失败时已收到的字节数,获取会话之类的调用方可以据此从共享的字节预算中扣除。在 Delphi 下接口照常编译,但三个函数都返回 False:Delphi 只面向 Windows,那里的后端是 FPdfCryptoHttp 中的 WinHttp 路径

函数

函数说明
CryptoCurlAvailable首次调用时在锁保护下加载一次 libcurl;只有全部入口点都解析成功、且模块报告支持异步 DNS 与线程安全时才返回 True
CryptoCurlGet执行有上限的 HTTP 或 HTTPS GET;只有状态码恰为 200 且响应体非空才算成功,最多保存 MaxBytes 字节,并通过 DownloadedBytes 报告实际收到的总字节数
CryptoCurlPost以调用方给定的 ContentType 执行有上限的 HTTP 或 HTTPS POST,Body 不能为空;状态码、大小与字节计数规则与 GET 相同

备注

参见

FPdfCryptoSsl, FPdfTsaFpc, FPdfTsa, TPdf.ValidatePadesTrust