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
|
path: ~/.mitmproxy
|
||||||
key: ${{ env.cache-name }}
|
key: ${{ env.cache-name }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ env.cache-name }}
|
${{ env.cache-name }}-
|
||||||
- name: Install mitmproxy
|
- name: Install mitmproxy
|
||||||
run: |
|
run: |
|
||||||
sudo apt update
|
sudo apt update
|
||||||
|
@ -82,12 +82,3 @@ jobs:
|
||||||
# uses: lhotari/action-upterm@v1
|
# uses: lhotari/action-upterm@v1
|
||||||
- name: Run pytest
|
- name: Run pytest
|
||||||
run: scripts/run_cached_tests
|
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
|
import json as _json
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from typing import Optional, Dict, Any
|
from typing import Optional, Dict, Any
|
||||||
|
import os
|
||||||
|
|
||||||
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
||||||
|
|
||||||
|
@ -17,8 +18,9 @@ from .base import BaseSession, TemporaryError, Response, HTTPError
|
||||||
__all__ = ['session']
|
__all__ = ['session']
|
||||||
|
|
||||||
HTTP2_AVAILABLE = None if pycurl else False
|
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
|
global HTTP2_AVAILABLE
|
||||||
if HTTP2_AVAILABLE is None:
|
if HTTP2_AVAILABLE is None:
|
||||||
try:
|
try:
|
||||||
|
@ -29,6 +31,11 @@ def try_use_http2(curl):
|
||||||
elif HTTP2_AVAILABLE:
|
elif HTTP2_AVAILABLE:
|
||||||
curl.setopt(pycurl.HTTP_VERSION, 4)
|
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):
|
class TornadoSession(BaseSession):
|
||||||
def setup(
|
def setup(
|
||||||
self,
|
self,
|
||||||
|
@ -68,7 +75,7 @@ class TornadoSession(BaseSession):
|
||||||
kwargs['body'] = body
|
kwargs['body'] = body
|
||||||
elif json:
|
elif json:
|
||||||
kwargs['body'] = _json.dumps(json)
|
kwargs['body'] = _json.dumps(json)
|
||||||
kwargs['prepare_curl_callback'] = try_use_http2
|
kwargs['prepare_curl_callback'] = setup_curl
|
||||||
|
|
||||||
if proxy:
|
if proxy:
|
||||||
host, port = proxy.rsplit(':', 1)
|
host, port = proxy.rsplit(':', 1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue