Finally fix firstboot redirect problems.

This issue was easy to solve once I started using the Live HTTP
Headers Firefox extension to debug it:

https://addons.mozilla.org/en-US/firefox/addon/live-http-headers/

With this particular InternalRedirect, CherryPy inexplicably responds
with a 301 ("Moved Permanently") unless we manually tell it to use a
307 ("Moved Temporarily") response code.  I don't know why CherryPy
does this, and it may be indicative of a deeper problem that I don't
currently have time to debug, as the request-response process for
redirecting from http://(server)/plinth to
https://(server)/plinth/firstboot is ridiculous and contains about
twice as many requests as I would've expected.
This commit is contained in:
Nick Daly 2013-12-08 11:46:33 -06:00
parent 4d5d93678b
commit 68e186deff

View File

@ -60,7 +60,10 @@ class Root(plugin_mount.PagePlugin):
# if we created a new user db, make sure it can't be read by everyone
userdb_fname = '{}.sqlite3'.format(cfg.user_db)
os.chmod(userdb_fname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
raise cherrypy.InternalRedirect('firstboot')
# cherrypy.InternalRedirect throws a 301, causing the
# browser to cache the redirect, preventing the user from
# navigating to /plinth until the browser is restarted.
raise cherrypy.HTTPRedirect('firstboot', 307)
elif db['state'] < 5:
cfg.log("First Boot state = %d" % db['state'])
raise cherrypy.InternalRedirect('firstboot/state%d' % db['state'])