thirdparty/google_appengine/google/appengine/api/urlfetch_stub.py
changeset 828 f5fd65cc3bf3
parent 686 df109be0567c
child 2273 e4cb9c53db3e
equal deleted inserted replaced
827:88c186556a80 828:f5fd65cc3bf3
    49 
    49 
    50 _API_CALL_DEADLINE = 5.0
    50 _API_CALL_DEADLINE = 5.0
    51 
    51 
    52 
    52 
    53 _UNTRUSTED_REQUEST_HEADERS = frozenset([
    53 _UNTRUSTED_REQUEST_HEADERS = frozenset([
       
    54   'accept-encoding',
    54   'content-length',
    55   'content-length',
    55   'host',
    56   'host',
    56   'referer',
    57   'referer',
    57   'user-agent',
    58   'user-agent',
    58   'vary',
    59   'vary',
    78       request: the fetch to perform, a URLFetchRequest
    79       request: the fetch to perform, a URLFetchRequest
    79       response: the fetch response, a URLFetchResponse
    80       response: the fetch response, a URLFetchResponse
    80     """
    81     """
    81     (protocol, host, path, parameters, query, fragment) = urlparse.urlparse(request.url())
    82     (protocol, host, path, parameters, query, fragment) = urlparse.urlparse(request.url())
    82 
    83 
    83     payload = ''
    84     payload = None
    84     if request.method() == urlfetch_service_pb.URLFetchRequest.GET:
    85     if request.method() == urlfetch_service_pb.URLFetchRequest.GET:
    85       method = 'GET'
    86       method = 'GET'
    86     elif request.method() == urlfetch_service_pb.URLFetchRequest.POST:
    87     elif request.method() == urlfetch_service_pb.URLFetchRequest.POST:
    87       method = 'POST'
    88       method = 'POST'
    88       payload = request.payload()
    89       payload = request.payload()
   116                    follow_redirects=True):
   117                    follow_redirects=True):
   117     """Retrieves a URL.
   118     """Retrieves a URL.
   118 
   119 
   119     Args:
   120     Args:
   120       url: String containing the URL to access.
   121       url: String containing the URL to access.
   121       payload: Request payload to send, if any.
   122       payload: Request payload to send, if any; None if no payload.
   122       method: HTTP method to use (e.g., 'GET')
   123       method: HTTP method to use (e.g., 'GET')
   123       headers: List of additional header objects to use for the request.
   124       headers: List of additional header objects to use for the request.
   124       response: Response object
   125       response: Response object
   125       follow_redirects: optional setting (defaulting to True) for whether or not
   126       follow_redirects: optional setting (defaulting to True) for whether or not
   126         we should transparently follow redirects (up to MAX_REDIRECTS)
   127         we should transparently follow redirects (up to MAX_REDIRECTS)
   148       if host == '' and protocol == '':
   149       if host == '' and protocol == '':
   149         host = last_host
   150         host = last_host
   150         protocol = last_protocol
   151         protocol = last_protocol
   151 
   152 
   152       adjusted_headers = {
   153       adjusted_headers = {
   153         'Content-Length': len(payload),
       
   154         'Host': host,
   154         'Host': host,
   155         'Accept': '*/*',
   155         'Accept': '*/*',
   156       }
   156       }
       
   157       if payload is not None:
       
   158         adjusted_headers['Content-Length'] = len(payload)
   157       if method == 'POST' and payload:
   159       if method == 'POST' and payload:
   158         adjusted_headers['Content-Type'] = 'application/x-www-form-urlencoded'
   160         adjusted_headers['Content-Type'] = 'application/x-www-form-urlencoded'
   159 
   161 
   160       for header in headers:
   162       for header in headers:
   161         adjusted_headers[header.key().title()] = header.value()
   163         adjusted_headers[header.key().title()] = header.value()