Google App Engine Custom Domain APIs

In my GAE (Python) application, I implemented multilevel and multisite support based on the host part of the request object.

For example, www.foo.com/index.html and www.bar.com/index.html processed by the same application (for example, myapp.appspot.com ). The application reads the host value, and then decides which namespace and site configuration to use. This works fine while the application receives the request directly from the agent user.

However, I would like to use the channel API, but there is a problem because requests to /_ah/channel/connected/ and /_ah/channel/disconnected/ do not come from the original user agent. Instead, the request has Host: myapp.appspot.com and the to=myapp.appspot.com . (The from parameter is the token I expect. Also, www.foo.com/_ah/channel/jsapi redirected to the talkgadget server, which is not documented, but seems to be expected.)

I assume that the problem is caused by code in channel.js that my application does not call using the source host, for example. www.foo.com/_ah/channel/connected . Instead, it uses the talkgadget.google.com host, which (as far as I can tell) will call my application, but using myapp.appspot.com , ignoring the original host, and therefore I cannot use the host value for my purpose.

As a workaround, I can determine how to include host information in the channel token, so when my connected and disconnected handlers get the token, they can use the token instead.

However, I would like to know if there is a better approach where I could get the original hostname (e.g. www.foo.com ) for /_ah/channel/connected/ and /_ah/channel/disconnected/ . Any ideas?

This is what I have tried so far (without any success):

Adding a custom domain name to the JS src attribute:

 <script type="text/javascript" src="//www.foo.com/_ah/channel/jsapi"></script> 

I also tried manually overriding the base url of the channel socket suggested here: https://stackoverflow.com/questions/16558776/google-app-engine-channel-api-same-origin-policy

 <script type="text/javascript"> onOpened = function() { // TODO }; onMessage = function() { // TODO }; onError = function() { // TODO }; onClose = function() { // TODO }; goog.appengine.Socket.BASE_URL = "https://www.foo.com/_ah/channel/"; channel = new goog.appengine.Channel('{{channelToken}}'); socket = channel.open(); socket.onopen = onOpened; socket.onmessage = onMessage; socket.onerror = onError; socket.onclose = onClose; </script> 

I could not find the official documentation for channel.js, and I do not want to implement something that will break easily with the next Google update.

+6
source share
1 answer

With the exception of the proxy, I see no better way than including information in a group. The problem is that the library / infrastructure (cannot be sure without looking deeper) robs the HTTP level information (host header), and, indeed, you have no control over the HTTP level for transmitting custom headers, etc. Thus, you either need to have information at a lower level (TCP does not even provide a means for this, and since the entry point of your code is through a browser running on the .js channel, and not at the system level of the process running on a bare network interface, this is not true) or at a higher level, i.e. inside the channel.

+1
source

All Articles