[Checkins] SVN: keas.kmi/trunk/src/keas/kmi/ Return a 404 rather than an error page if the key cannot be found.
Marius Gedminas
marius at pov.lt
Thu Sep 4 17:04:30 EDT 2008
Log message for revision 90843:
Return a 404 rather than an error page if the key cannot be found.
Changed:
U keas.kmi/trunk/src/keas/kmi/README.txt
U keas.kmi/trunk/src/keas/kmi/rest.py
-=-
Modified: keas.kmi/trunk/src/keas/kmi/README.txt
===================================================================
--- keas.kmi/trunk/src/keas/kmi/README.txt 2008-09-04 21:00:30 UTC (rev 90842)
+++ keas.kmi/trunk/src/keas/kmi/README.txt 2008-09-04 21:04:30 UTC (rev 90843)
@@ -251,6 +251,21 @@
>>> len(encKey)
32
+If you try to request a nonexistent key, you get a 404 error:
+encryption key string:
+
+ >>> import cStringIO
+ >>> io = cStringIO.StringIO('xyzzy')
+
+ >>> request = TestRequest(io)
+ >>> request.method = 'POST'
+
+ >>> keyCall = rest.KeyView(keys, request)
+ >>> print keyCall()
+ Key not found
+ >>> request.response.getStatus()
+ 404
+
A `GET` request to the root shows us a server status page
>>> request = TestRequest()
Modified: keas.kmi/trunk/src/keas/kmi/rest.py
===================================================================
--- keas.kmi/trunk/src/keas/kmi/rest.py 2008-09-04 21:00:30 UTC (rev 90842)
+++ keas.kmi/trunk/src/keas/kmi/rest.py 2008-09-04 21:04:30 UTC (rev 90843)
@@ -45,4 +45,9 @@
stream.seek(0)
key = stream.read()
self.request.response.setHeader('content-type', 'text/plain')
- return self.context.getEncryptionKey(key)
+ try:
+ return self.context.getEncryptionKey(key)
+ except KeyError:
+ self.request.response.setStatus(404)
+ return 'Key not found'
+
More information about the Checkins
mailing list