Customer header when going through proxy

447 views
Skip to first unread message

Ian Stansbury

unread,
Feb 13, 2017, 10:28:53 AM2/13/17
to Google Cloud Pub/Sub Discussions
All,

My company is requiring me to go through a proxy to get to Google PubSub. Setting the url to go to was fairly easy but I have ran into a blocker because I need to add a custom header that the proxy will validate. Anyone have a suggestion on the best approach to adding a customer header before sending the publish call.  Using V1 api.

Thanks,
Ian

Ian Stansbury

unread,
Feb 13, 2017, 10:47:01 AM2/13/17
to Google Cloud Pub/Sub Discussions
Also, using the Java util

Adam

unread,
Feb 13, 2017, 12:49:02 PM2/13/17
to Google Cloud Pub/Sub Discussions
If you're using the Google API Java Client to call the Pub/Sub API, you can add the custom header using a custom HttpRequestInitializer. An example of how to use a custom HttpRequestInitializer can be found in the client library documentation section Handling Errors. In this case it shows how to set a retry handler, but it can be trivially modified to also add custom headers by adding a call to request.setHeaders(). Another, more complete example of  HttpRequestInitializer can be found in RetryHttpInitializerWrapper in the cloud-pubsub-samples-java GitHub repository.

Santosh Ashtaputra

unread,
Feb 22, 2017, 6:00:15 AM2/22/17
to Google Cloud Pub/Sub Discussions
Hi Adam,

Could you tell me how to connect to pubsub through proxy for python client. i'm using below sample code for getting monitoring data from pubsub.

from oauth2client.contrib.gce import AppAssertionCredentials
from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
from apiclient.discovery import build

credentials = AppAssertionCredentials('https://www.googleapis.com/auth/pubsub')
credentials = ServiceAccountCredentials.from_json_keyfile_name('path to json file', scopes=scopes)

http_auth = credentials.authorize(Http())

pubsub1 = build('pubsub', 'v1',http=http_auth)

Santosh Ashtaputra

unread,
Feb 23, 2017, 4:48:14 AM2/23/17
to Google Cloud Pub/Sub Discussions
It worked by using below command:

http_auth = credentials.authorize(Http(proxy_info = httplib2.ProxyInfo(httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL, 'proxy url wihout http', 8080, proxy_user = '', proxy_pass = '') ))
Reply all
Reply to author
Forward
0 new messages