From 101b92570dc3e307e2bec82bd8ef76298a5700fd Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Wed, 19 Aug 2015 16:09:08 -0700 Subject: [PATCH] Changed where to add userIp for the correct caching behavior. --- googleapiclient/discovery.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py index e5c5b915bb..966b592eda 100644 --- a/googleapiclient/discovery.py +++ b/googleapiclient/discovery.py @@ -190,15 +190,6 @@ def build(serviceName, requested_url = uritemplate.expand(discoveryServiceUrl, params) - # REMOTE_ADDR is defined by the CGI spec [RFC3875] as the environment - # variable that contains the network address of the client sending the - # request. If it exists then add that to the request for the discovery - # document to avoid exceeding the quota on discovery requests. - if 'REMOTE_ADDR' in os.environ: - requested_url = _add_query_parameter(requested_url, 'userIp', - os.environ['REMOTE_ADDR']) - logger.info('URL being requested: GET %s' % requested_url) - content = retrieve_discovery_doc(requested_url, http, cache_discovery, cache) return build_from_document(content, base=discoveryServiceUrl, http=http, @@ -232,13 +223,22 @@ def retrieve_discovery_doc(url, http, cache_discovery, cache): if content: return content - resp, content = http.request(url) + actual_url = url + # REMOTE_ADDR is defined by the CGI spec [RFC3875] as the environment + # variable that contains the network address of the client sending the + # request. If it exists then add that to the request for the discovery + # document to avoid exceeding the quota on discovery requests. + if 'REMOTE_ADDR' in os.environ: + actual_url = _add_query_parameter(url, 'userIp', os.environ['REMOTE_ADDR']) + logger.info('URL being requested: GET %s' % actual_url) + + resp, content = http.request(actual_url) if resp.status == 404: raise UnknownApiNameOrVersion("name: %s version: %s" % (serviceName, version)) if resp.status >= 400: - raise HttpError(resp, content, uri=url) + raise HttpError(resp, content, uri=actual_url) try: content = content.decode('utf-8')