# HG changeset patch # User RhodeCode Admin # Date 2023-03-10 11:29:37 # Node ID c50c73e45c0ead96052ac048a7c9128b430e9613 # Parent 093203116b24aebb891bdcf01811a1109fe04860 pycurl: fix usage of bytes when making curl calls diff --git a/rhodecode/lib/vcs/__init__.py b/rhodecode/lib/vcs/__init__.py --- a/rhodecode/lib/vcs/__init__.py +++ b/rhodecode/lib/vcs/__init__.py @@ -22,18 +22,19 @@ Various version Control System version lib (vcs) management abstraction layer for Python. Build with server client architecture. """ +import io import atexit import logging -from io import StringIO import rhodecode +from rhodecode.lib.str_utils import safe_bytes from rhodecode.lib.vcs.conf import settings from rhodecode.lib.vcs.backends import get_vcs_instance, get_backend from rhodecode.lib.vcs.exceptions import ( VCSError, RepositoryError, CommitError, VCSCommunicationError) __all__ = [ - 'get_version', 'get_vcs_instance', 'get_backend', + 'get_vcs_instance', 'get_backend', 'VCSError', 'RepositoryError', 'CommitError', 'VCSCommunicationError' ] @@ -54,14 +55,9 @@ except ImportError: import pycurl -def get_version(): - """ - Returns shorter version (digit parts only) as string. - """ - return '.'.join((str(each) for each in VERSION[:3])) +def connect_http(server_and_port): + log.debug('Initialized VCSServer connections to %s.', server_and_port) - -def connect_http(server_and_port): from rhodecode.lib.vcs import connection, client_http from rhodecode.lib.middleware.utils import scm_app @@ -113,6 +109,7 @@ class CurlSession(object): Please have a look at the class :class:`requests.Session` when you extend it. """ + CURL_UA = f'RhodeCode HTTP {rhodecode.__version__}' def __init__(self): curl = pycurl.Curl() @@ -122,7 +119,7 @@ class CurlSession(object): curl.setopt(curl.TCP_NODELAY, True) curl.setopt(curl.PROTOCOLS, curl.PROTO_HTTP) - curl.setopt(curl.USERAGENT, 'RhodeCode HTTP {}'.format(rhodecode.__version__)) + curl.setopt(curl.USERAGENT, safe_bytes(self.CURL_UA)) curl.setopt(curl.SSL_VERIFYPEER, 0) curl.setopt(curl.SSL_VERIFYHOST, 0) self._curl = curl @@ -130,8 +127,8 @@ class CurlSession(object): def post(self, url, data, allow_redirects=False, headers=None): headers = headers or {} # format is ['header_name1: header_value1', 'header_name2: header_value2']) - headers_list = ["Expect:"] + ['{}: {}'.format(k, v) for k, v in headers.items()] - response_buffer = StringIO() + headers_list = [b"Expect:"] + [safe_bytes('{}: {}'.format(k, v)) for k, v in headers.items()] + response_buffer = io.BytesIO() curl = self._curl curl.setopt(curl.URL, url)