favicon dispatcher

11 views
Skip to first unread message

cfb

unread,
Aug 3, 2008, 12:52:53 PM8/3/08
to Google App Engine
Since google has a three application limit and you can't easily rename
applications, I have taken to dispatching project from a single
toplevel application:

dispatch.py:
import project1, project2, project3, projectN

def main():
hostname = os.environ['HTTP_HOST']
logging.debug('disptach: ' + hostname + ' ' +
os.environ['REMOTE_ADDR'] + ' ' + time.asctime(time.localtime()) )

if hostname == 'localhost:8080' or hostname == 'localhost:80' or
hostname == 'localhost':
localhost.makepage()
elif hostname == 'domain.net' or hostname == 'www.domain.net':
domain.makepage()
elif hostname == 'project1.domain.net':
project1.makepage()
elif hostname == 'project2.domain.net':
project2.makepage()
elif hostname == 'project3.domain.net':
project3.makepage()
elif hostname == 'projectN.domain.net':
projectN.makepage()
else:
logging.error('disptach: ' + hostname + ' ' +
os.environ['REMOTE_ADDR'] + ' ' + time.asctime(time.localtime()) )
print "no match on the project host"


My question is: does anyone have a convenient solution for
dispatching favicon requests for separate parts of a project or for
multiple projects? I know it's a separate request generated by the
browser; so, all I should really need to do is create a block of code
than handles that URL request and make sure app.yaml maps the request
to the handler instead of a static file:

app.yaml:
- url: /favicon\.ico
script: dispatch.py

project1.py:
def makepage():
logging.debug('project1.domain.net makepage: ' +
os.environ['REMOTE_ADDR'] + ' ' + time.asctime(time.localtime()) )

application = webapp.WSGIApplication([('/', MainPage),
('/other', OtherPage),
('/favicon\.ico', favicon)
],
debug=False)

wsgiref.handlers.CGIHandler().run(application)

class favicon(webapp.RequestHandler):
def get(self):
What goes here to send back a favicon.ico???!!?!

I'm at a bit of a loss to what code is actually needed to get the
favicon.iso actually delivered back to the browser.

Thanks in advance for any help/suggestion provided...

Calvin Spealman

unread,
Aug 3, 2008, 1:00:43 PM8/3/08
to google-a...@googlegroups.com
the limit is 10 now

--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/

cfb

unread,
Aug 3, 2008, 1:48:12 PM8/3/08
to Google App Engine
...and I'm already over that.

Calvin Spealman

unread,
Aug 3, 2008, 1:53:14 PM8/3/08
to google-a...@googlegroups.com
just pointing out. anyway, does you dispatcher already not work with
favicons? they would be directed to the right subdomain right? so does
it work or not, as is?

Jorge Vargas

unread,
Aug 3, 2008, 5:41:29 PM8/3/08
to google-a...@googlegroups.com
Serving static content from the dynamic code isn't a great idea, but
all you will have to do is
a- load the image file
b- set the correct content-type header. for example.
Content-type: image/png

Also I'll suggest using a better method for that if/elif for example a
dict, dispatcher.
http://wordaligned.org/articles/lexical-dispatch-in-python

cfb

unread,
Aug 3, 2008, 6:15:23 PM8/3/08
to Google App Engine
results in the same favicon for each name... plus there were some
other small customizations that I was hoping to accomplish (different
favicons for birthdays and holidays that what not; which would mean
that favicon wouldn't be "static content").

I guess what I was hoping that someone would show me that
os.environ['HTTP_HOST'] equivalent is available in the app.yaml
context (would be handy for some subdomain things that I would like to
play around with as well).

Jorge Vargas

unread,
Aug 11, 2008, 7:42:29 PM8/11/08
to google-a...@googlegroups.com
On Sun, Aug 3, 2008 at 4:15 PM, cfb <chris....@gmail.com> wrote:
>
> results in the same favicon for each name... plus there were some
> other small customizations that I was hoping to accomplish (different
> favicons for birthdays and holidays that what not; which would mean
> that favicon wouldn't be "static content").
>
do you have a static route for one, maybe that's taking over.

> I guess what I was hoping that someone would show me that
> os.environ['HTTP_HOST'] equivalent is available in the app.yaml
> context (would be handy for some subdomain things that I would like to
> play around with as well).

I don't think that's avalaible. Starting with the fact you are not
supposed to be doing this.

Roberto Saccon

unread,
Aug 11, 2008, 9:39:18 PM8/11/08
to Google App Engine
there is no problem (beside of efficiency) in serving dynamically
static favicon images per domain name, just make sure that the client
browser caches the image, if possible (see static.serve in django or
even better the serve function at http://code.google.com/p/django-dynamic-media-serve/
for inspiration), but you have to use differnet domais and not
subdomains, because the current appengine design is laid out to map
just one subdomain (usually "www") to googles server.

regards
Roberto

On Aug 11, 8:42 pm, "Jorge Vargas" <jorge.var...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages