Skip to content

Commit

Permalink
support SSL_CERT_FILE env for pycurl http backend
Browse files Browse the repository at this point in the history
  • Loading branch information
lilydjwg committed Feb 10, 2025
1 parent d67d765 commit 0aa26af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
path: ~/.mitmproxy
key: ${{ env.cache-name }}
restore-keys: |
${{ env.cache-name }}
${{ env.cache-name }}-
- name: Install mitmproxy
run: |
sudo apt update
Expand All @@ -90,4 +90,4 @@ jobs:
cache-name: cache-mitm
with:
path: ~/.mitmproxy
key: ${{ env.cache-name }}
key: ${{ env.cache-name }}-${{ github.run_id }}-${{ github.run_attempt }}
9 changes: 7 additions & 2 deletions nvchecker/httpclient/tornado_httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json as _json
from urllib.parse import urlencode
from typing import Optional, Dict, Any
import os

from tornado.httpclient import AsyncHTTPClient, HTTPRequest

Expand All @@ -17,8 +18,9 @@
__all__ = ['session']

HTTP2_AVAILABLE = None if pycurl else False
SSL_CERT_FILE = os.environ.get('SSL_CERT_FILE')

def try_use_http2(curl):
def setup_curl(curl):
global HTTP2_AVAILABLE
if HTTP2_AVAILABLE is None:
try:
Expand All @@ -29,6 +31,9 @@ def try_use_http2(curl):
elif HTTP2_AVAILABLE:
curl.setopt(pycurl.HTTP_VERSION, 4)

if SSL_CERT_FILE:
curl.setopt_string(pycurl.CAPATH, SSL_CERT_FILE)

class TornadoSession(BaseSession):
def setup(
self,
Expand Down Expand Up @@ -68,7 +73,7 @@ async def request_impl(
kwargs['body'] = body
elif json:
kwargs['body'] = _json.dumps(json)
kwargs['prepare_curl_callback'] = try_use_http2
kwargs['prepare_curl_callback'] = setup_curl

if proxy:
host, port = proxy.rsplit(':', 1)
Expand Down

0 comments on commit 0aa26af

Please sign in to comment.