mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
support SSL_CERT_FILE env for pycurl http backend
This commit is contained in:
parent
d58638733e
commit
17e351f825
2 changed files with 10 additions and 12 deletions
11
.github/workflows/tests.yaml
vendored
11
.github/workflows/tests.yaml
vendored
|
@ -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
|
||||
|
@ -82,12 +82,3 @@ jobs:
|
|||
# uses: lhotari/action-upterm@v1
|
||||
- name: Run pytest
|
||||
run: scripts/run_cached_tests
|
||||
|
||||
- name: save mitmproxy cache
|
||||
if: always()
|
||||
uses: actions/cache/save@v4
|
||||
env:
|
||||
cache-name: cache-mitm
|
||||
with:
|
||||
path: ~/.mitmproxy
|
||||
key: ${{ env.cache-name }}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -17,8 +18,9 @@ from .base import BaseSession, TemporaryError, Response, HTTPError
|
|||
__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:
|
||||
|
@ -29,6 +31,11 @@ def try_use_http2(curl):
|
|||
elif HTTP2_AVAILABLE:
|
||||
curl.setopt(pycurl.HTTP_VERSION, 4)
|
||||
|
||||
if SSL_CERT_FILE:
|
||||
curl.setopt_string(pycurl.CAINFO, SSL_CERT_FILE)
|
||||
# some servers insist sending us compressed content
|
||||
curl.setopt_string(pycurl.ACCEPT_ENCODING, "")
|
||||
|
||||
class TornadoSession(BaseSession):
|
||||
def setup(
|
||||
self,
|
||||
|
@ -68,7 +75,7 @@ class TornadoSession(BaseSession):
|
|||
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue