Skip to content

Commit

Permalink
Fix to issue (#1219)
Browse files Browse the repository at this point in the history
In-browser caching conflicts between home page and json-ld context
Ensure output of 'vary' header.
Collect outputing of json-ld context in one place and redirect to it from home page.
  • Loading branch information
RichardWallis committed Jun 21, 2016
1 parent e059d5f commit a4fd4ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def setCurrent(self,current):
self.tlocal.CurrentDataCache = current
if(self._DataCache.get(current) == None):
self._DataCache[current] = {}
log.info("Setting _CurrentDataCache: %s",current)
#log.info("Setting _CurrentDataCache: %s",current)

def getCurrent(self):
return self.tlocal.CurrentDataCache
Expand Down Expand Up @@ -189,7 +189,7 @@ def getCurrent(self):

def setCurrent(self,current):
self.tlocal.CurrentStoreSet = current
log.info("PageStore setting CurrentStoreSet: %s",current)
#log.info("PageStore setting CurrentStoreSet: %s",current)

def put(self, key, val,cache=None):
ca = self.getCurrent()
Expand Down Expand Up @@ -243,7 +243,7 @@ def getCurrent(self):

def setCurrent(self,current):
self.tlocal.CurrentStoreSet = current
log.info("HeaderStore setting CurrentStoreSet: %s",current)
#log.info("HeaderStore setting CurrentStoreSet: %s",current)

def put(self, key, val,cache=None):
ca = self.getCurrent()
Expand Down
22 changes: 13 additions & 9 deletions sdoapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,11 +1062,10 @@ def handleHomepage(self, node):
# print "accept_header: " + str(accept_header) + " mimereq: "+str(mimereq) + "Scores H:{0} XH:{1} J:{2} ".format(html_score,xhtml_score,jsonld_score)

if (ENABLE_JSONLD_CONTEXT and (jsonld_score < html_score and jsonld_score < xhtml_score)):
jsonldcontext = GetJsonLdContext(layers=ALL_LAYERS)
self.response.headers['Content-Type'] = "application/ld+json"
#self.emitCacheHeaders()
self.response.out.write( jsonldcontext )
return True
self.response.set_status(302,"Found")
self.response.headers['Location'] = makeUrl("","docs/jsonldcontext.json")
self.emitCacheHeaders()
return False #don't cache this redirect
else:
# Serve a homepage from template
# the .tpl has responsibility for extension homepages
Expand All @@ -1091,7 +1090,7 @@ def handleHomepage(self, node):
#log.info("Served and cached fresh homepage.tpl key: %s " % sitekeyedhomepage)
PageStore.put(sitekeyedhomepage, page)
# self.response.out.write( open("static/index.html", 'r').read() )
return True
return False # - Not caching homepage
log.info("Warning: got here how?")
return False

Expand Down Expand Up @@ -1420,15 +1419,20 @@ def handleJSONContext(self, node):
self.error(404)
self.response.out.write('<title>404 Not Found.</title><a href="/">404 Not Found (JSON-LD Context not enabled.)</a><br/><br/>')
return True

if (node=="docs/jsonldcontext.json.txt"):

jsonldcontext = ""
if PageStore.get("JSONLDCONTEXT"):
jsonldcontext = PageStore.get("JSONLDCONTEXT")
else:
jsonldcontext = GetJsonLdContext(layers=ALL_LAYERS)
PageStore.put("JSONLDCONTEXT",jsonldcontext)

if (node=="docs/jsonldcontext.json.txt"):
self.response.headers['Content-Type'] = "text/plain"
self.emitCacheHeaders()
self.response.out.write( jsonldcontext )
return True
if (node=="docs/jsonldcontext.json"):
jsonldcontext = GetJsonLdContext(layers=ALL_LAYERS)
self.response.headers['Content-Type'] = "application/ld+json"
self.emitCacheHeaders()
self.response.out.write( jsonldcontext )
Expand Down

0 comments on commit a4fd4ad

Please sign in to comment.