##// END OF EJS Templates
pycurl: fix usage of bytes when making curl calls
super-admin -
r4965:c50c73e4 default
parent child Browse files
Show More
@@ -22,18 +22,19 b''
22 Various version Control System version lib (vcs) management abstraction layer
22 Various version Control System version lib (vcs) management abstraction layer
23 for Python. Build with server client architecture.
23 for Python. Build with server client architecture.
24 """
24 """
25 import io
25 import atexit
26 import atexit
26 import logging
27 import logging
27 from io import StringIO
28
28
29 import rhodecode
29 import rhodecode
30 from rhodecode.lib.str_utils import safe_bytes
30 from rhodecode.lib.vcs.conf import settings
31 from rhodecode.lib.vcs.conf import settings
31 from rhodecode.lib.vcs.backends import get_vcs_instance, get_backend
32 from rhodecode.lib.vcs.backends import get_vcs_instance, get_backend
32 from rhodecode.lib.vcs.exceptions import (
33 from rhodecode.lib.vcs.exceptions import (
33 VCSError, RepositoryError, CommitError, VCSCommunicationError)
34 VCSError, RepositoryError, CommitError, VCSCommunicationError)
34
35
35 __all__ = [
36 __all__ = [
36 'get_version', 'get_vcs_instance', 'get_backend',
37 'get_vcs_instance', 'get_backend',
37 'VCSError', 'RepositoryError', 'CommitError', 'VCSCommunicationError'
38 'VCSError', 'RepositoryError', 'CommitError', 'VCSCommunicationError'
38 ]
39 ]
39
40
@@ -54,14 +55,9 b' except ImportError:'
54 import pycurl
55 import pycurl
55
56
56
57
57 def get_version():
58 def connect_http(server_and_port):
58 """
59 log.debug('Initialized VCSServer connections to %s.', server_and_port)
59 Returns shorter version (digit parts only) as string.
60 """
61 return '.'.join((str(each) for each in VERSION[:3]))
62
60
63
64 def connect_http(server_and_port):
65 from rhodecode.lib.vcs import connection, client_http
61 from rhodecode.lib.vcs import connection, client_http
66 from rhodecode.lib.middleware.utils import scm_app
62 from rhodecode.lib.middleware.utils import scm_app
67
63
@@ -113,6 +109,7 b' class CurlSession(object):'
113 Please have a look at the class :class:`requests.Session` when you extend
109 Please have a look at the class :class:`requests.Session` when you extend
114 it.
110 it.
115 """
111 """
112 CURL_UA = f'RhodeCode HTTP {rhodecode.__version__}'
116
113
117 def __init__(self):
114 def __init__(self):
118 curl = pycurl.Curl()
115 curl = pycurl.Curl()
@@ -122,7 +119,7 b' class CurlSession(object):'
122
119
123 curl.setopt(curl.TCP_NODELAY, True)
120 curl.setopt(curl.TCP_NODELAY, True)
124 curl.setopt(curl.PROTOCOLS, curl.PROTO_HTTP)
121 curl.setopt(curl.PROTOCOLS, curl.PROTO_HTTP)
125 curl.setopt(curl.USERAGENT, 'RhodeCode HTTP {}'.format(rhodecode.__version__))
122 curl.setopt(curl.USERAGENT, safe_bytes(self.CURL_UA))
126 curl.setopt(curl.SSL_VERIFYPEER, 0)
123 curl.setopt(curl.SSL_VERIFYPEER, 0)
127 curl.setopt(curl.SSL_VERIFYHOST, 0)
124 curl.setopt(curl.SSL_VERIFYHOST, 0)
128 self._curl = curl
125 self._curl = curl
@@ -130,8 +127,8 b' class CurlSession(object):'
130 def post(self, url, data, allow_redirects=False, headers=None):
127 def post(self, url, data, allow_redirects=False, headers=None):
131 headers = headers or {}
128 headers = headers or {}
132 # format is ['header_name1: header_value1', 'header_name2: header_value2'])
129 # format is ['header_name1: header_value1', 'header_name2: header_value2'])
133 headers_list = ["Expect:"] + ['{}: {}'.format(k, v) for k, v in headers.items()]
130 headers_list = [b"Expect:"] + [safe_bytes('{}: {}'.format(k, v)) for k, v in headers.items()]
134 response_buffer = StringIO()
131 response_buffer = io.BytesIO()
135
132
136 curl = self._curl
133 curl = self._curl
137 curl.setopt(curl.URL, url)
134 curl.setopt(curl.URL, url)
General Comments 0
You need to be logged in to leave comments. Login now