Skip to content

Commit

Permalink
Changed where to add userIp for the correct caching behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Matsuo committed Aug 19, 2015
1 parent 6e07b2f commit 101b925
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions googleapiclient/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 101b925

Please sign in to comment.