Skip to content

DISCUSSION: Allow http as an argument to Connection so libraries other than httplib2 can be used #551

@dhermes

Description

@dhermes

This way we can support people using Twisted (for example) or other frameworks without having to write any other code. Though docs could be nice? We could supply an abstract class for them to subclass?


As of 12ac983:

$ git log -1 --pretty=%H
12ac983fe613785c998aeeb1d8b981f4b5b347d9
$ git grep '\.http' -- gcloud/ | egrep -v 'test'
gcloud/datastore/connection.py:        :raises: :class:`six.moves.http_client.HTTPException` if the response
gcloud/datastore/connection.py:        headers, content = self.http.request(
gcloud/datastore/connection.py:            raise six.moves.http_client.HTTPException(message)
gcloud/storage/connection.py:        return self.http.request(uri=url, method=method, headers=headers,
gcloud/storage/key.py:        download.InitializeDownload(request, self.connection.http)
gcloud/storage/key.py:        upload.InitializeUpload(request, conn.http)
gcloud/storage/key.py:            http_wrapper.MakeRequest(conn.http, request, retries=num_retries)

We only actively use the httplib2.Http() instance twice. Once in storage.connection.Connection.make_request:

        return self.http.request(uri=url, method=method, headers=headers,
                                 body=data)

and once in datastore.connection.Connection._request:

        headers, content = self.http.request(
            uri=self.build_api_url(dataset_id=dataset_id, method=method),
            method='POST', headers=headers, body=data)

In either case the object only needs to be able to accept

  • uri
  • method
  • headers
  • body

and needs to append a

Authorization: Bearer ya29.some-OAUTH-TOKEN...

header to headers. (See the source, the user agent is also updated and the request is retried if a 401 Unauthorized is encountered, but an external client need not do either of those.)


ASIDE: Should we add an auth label?

Metadata

Metadata

Assignees

Labels

api: coretype: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions