thirdparty/google_appengine/google/appengine/api/urlfetch_stub.py
changeset 2864 2e0b0af889be
parent 2413 d0b7dac5325c
equal deleted inserted replaced
2862:27971a13089f 2864:2e0b0af889be
    53 
    53 
    54 
    54 
    55 _UNTRUSTED_REQUEST_HEADERS = frozenset([
    55 _UNTRUSTED_REQUEST_HEADERS = frozenset([
    56   'content-length',
    56   'content-length',
    57   'host',
    57   'host',
    58   'referer',
       
    59   'vary',
    58   'vary',
    60   'via',
    59   'via',
    61   'x-forwarded-for',
    60   'x-forwarded-for',
    62 ])
    61 ])
    63 
    62 
   166         protocol = last_protocol
   165         protocol = last_protocol
   167 
   166 
   168       adjusted_headers = {
   167       adjusted_headers = {
   169           'User-Agent':
   168           'User-Agent':
   170           'AppEngine-Google; (+http://code.google.com/appengine)',
   169           'AppEngine-Google; (+http://code.google.com/appengine)',
   171           'Referer': 'http://localhost/',
       
   172           'Host': host,
   170           'Host': host,
   173           'Accept-Encoding': 'gzip',
   171           'Accept-Encoding': 'gzip',
   174       }
   172       }
   175       if payload is not None:
   173       if payload is not None:
   176         adjusted_headers['Content-Length'] = len(payload)
   174         adjusted_headers['Content-Length'] = len(payload)
   210         orig_timeout = socket.getdefaulttimeout()
   208         orig_timeout = socket.getdefaulttimeout()
   211         try:
   209         try:
   212           socket.setdefaulttimeout(deadline)
   210           socket.setdefaulttimeout(deadline)
   213           connection.request(method, full_path, payload, adjusted_headers)
   211           connection.request(method, full_path, payload, adjusted_headers)
   214           http_response = connection.getresponse()
   212           http_response = connection.getresponse()
   215           http_response_data = http_response.read()
   213           if method == 'HEAD':
       
   214             http_response_data = ''
       
   215           else:
       
   216             http_response_data = http_response.read()
   216         finally:
   217         finally:
   217           socket.setdefaulttimeout(orig_timeout)
   218           socket.setdefaulttimeout(orig_timeout)
   218           connection.close()
   219           connection.close()
   219       except (httplib.error, socket.error, IOError), e:
   220       except (httplib.error, socket.error, IOError), e:
   220         raise apiproxy_errors.ApplicationError(
   221         raise apiproxy_errors.ApplicationError(
   237         for header_key, header_value in http_response.getheaders():
   238         for header_key, header_value in http_response.getheaders():
   238           if (header_key.lower() == 'content-encoding' and
   239           if (header_key.lower() == 'content-encoding' and
   239               header_value == 'gzip'):
   240               header_value == 'gzip'):
   240             continue
   241             continue
   241           if header_key.lower() == 'content-length':
   242           if header_key.lower() == 'content-length':
   242             header_value = len(response.content())
   243             header_value = str(len(response.content()))
   243           header_proto = response.add_header()
   244           header_proto = response.add_header()
   244           header_proto.set_key(header_key)
   245           header_proto.set_key(header_key)
   245           header_proto.set_value(header_value)
   246           header_proto.set_value(header_value)
   246 
   247 
   247         if len(http_response_data) > MAX_RESPONSE_SIZE:
   248         if len(http_response_data) > MAX_RESPONSE_SIZE: