Updating to latest ycmd

This required changing the HMAC calculation logic.
This commit is contained in:
Strahinja Val Markovic 2015-04-17 15:00:58 -07:00
parent 8e30a02d4f
commit a70bf21d29
2 changed files with 31 additions and 19 deletions

View File

@ -24,8 +24,8 @@ from retries import retries
from requests_futures.sessions import FuturesSession from requests_futures.sessions import FuturesSession
from ycm.unsafe_thread_pool_executor import UnsafeThreadPoolExecutor from ycm.unsafe_thread_pool_executor import UnsafeThreadPoolExecutor
from ycm import vimsupport from ycm import vimsupport
from ycmd import utils
from ycmd.utils import ToUtf8Json from ycmd.utils import ToUtf8Json
from ycmd.hmac_utils import CreateRequestHmac, CreateHmac, SecureStringsEqual
from ycmd.responses import ServerError, UnknownExtraConf from ycmd.responses import ServerError, UnknownExtraConf
_HEADERS = {'content-type': 'application/json'} _HEADERS = {'content-type': 'application/json'}
@ -89,29 +89,37 @@ class BaseRequest( object ):
method, method,
timeout = _DEFAULT_TIMEOUT_SEC ): timeout = _DEFAULT_TIMEOUT_SEC ):
def SendRequest( data, handler, method, timeout ): def SendRequest( data, handler, method, timeout ):
request_uri = _BuildUri( handler )
if method == 'POST': if method == 'POST':
sent_data = ToUtf8Json( data ) sent_data = ToUtf8Json( data )
return BaseRequest.session.post( return BaseRequest.session.post(
_BuildUri( handler ), request_uri,
data = sent_data, data = sent_data,
headers = BaseRequest._ExtraHeaders( sent_data ), headers = BaseRequest._ExtraHeaders( method,
request_uri,
sent_data ),
timeout = timeout ) timeout = timeout )
if method == 'GET': if method == 'GET':
return BaseRequest.session.get( return BaseRequest.session.get(
_BuildUri( handler ), request_uri,
headers = BaseRequest._ExtraHeaders(), headers = BaseRequest._ExtraHeaders( method, request_uri ),
timeout = timeout ) timeout = timeout )
@retries( 5, delay = 0.5, backoff = 1.5 ) @retries( 5, delay = 0.5, backoff = 1.5 )
def DelayedSendRequest( data, handler, method ): def DelayedSendRequest( data, handler, method ):
request_uri = _BuildUri( handler )
if method == 'POST': if method == 'POST':
sent_data = ToUtf8Json( data ) sent_data = ToUtf8Json( data )
return requests.post( _BuildUri( handler ), return requests.post(
data = sent_data, request_uri,
headers = BaseRequest._ExtraHeaders( sent_data ) ) data = sent_data,
headers = BaseRequest._ExtraHeaders( method,
request_uri,
sent_data ) )
if method == 'GET': if method == 'GET':
return requests.get( _BuildUri( handler ), return requests.get(
headers = BaseRequest._ExtraHeaders() ) request_uri,
headers = BaseRequest._ExtraHeaders( method, request_uri ) )
if not _CheckServerIsHealthyWithCache(): if not _CheckServerIsHealthyWithCache():
return _EXECUTOR.submit( DelayedSendRequest, data, handler, method ) return _EXECUTOR.submit( DelayedSendRequest, data, handler, method )
@ -120,12 +128,15 @@ class BaseRequest( object ):
@staticmethod @staticmethod
def _ExtraHeaders( request_body = None ): def _ExtraHeaders( method, request_uri, request_body = None ):
if not request_body: if not request_body:
request_body = '' request_body = ''
headers = dict( _HEADERS ) headers = dict( _HEADERS )
headers[ _HMAC_HEADER ] = b64encode( headers[ _HMAC_HEADER ] = b64encode(
utils.CreateHexHmac( request_body, BaseRequest.hmac_secret ) ) CreateRequestHmac( method,
urlparse.urlparse( request_uri ).path,
request_body,
BaseRequest.hmac_secret ) )
return headers return headers
session = FuturesSession( executor = _EXECUTOR ) session = FuturesSession( executor = _EXECUTOR )
@ -174,10 +185,9 @@ def HandleServerException( exception ):
def _ValidateResponseObject( response ): def _ValidateResponseObject( response ):
if not utils.ContentHexHmacValid( hmac = CreateHmac( response.content, BaseRequest.hmac_secret )
response.content, if not SecureStringsEqual( hmac,
b64decode( response.headers[ _HMAC_HEADER ] ), b64decode( response.headers[ _HMAC_HEADER ] ) ):
BaseRequest.hmac_secret ):
raise RuntimeError( 'Received invalid HMAC for response!' ) raise RuntimeError( 'Received invalid HMAC for response!' )
return True return True
@ -191,8 +201,10 @@ def _CheckServerIsHealthyWithCache():
global SERVER_HEALTHY global SERVER_HEALTHY
def _ServerIsHealthy(): def _ServerIsHealthy():
response = requests.get( _BuildUri( 'healthy' ), request_uri = _BuildUri( 'healthy' )
headers = BaseRequest._ExtraHeaders() ) response = requests.get( request_uri,
headers = BaseRequest._ExtraHeaders(
'GET', request_uri, '' ) )
_ValidateResponseObject( response ) _ValidateResponseObject( response )
response.raise_for_status() response.raise_for_status()
return response.json() return response.json()

2
third_party/ycmd vendored

@ -1 +1 @@
Subproject commit 954cf04c5f12228d385a8c2088443d5d7b303d48 Subproject commit 426833360adec8db72ed6cef9d7aa7f037e6a5b8