Merge lp:~wallyworld/lazr.restful/namedpost-url-change-1056666 into lp:lazr.restful

Proposed by Ian Booth
Status: Merged
Approved by: Curtis Hovey
Approved revision: 202
Merged at revision: 201
Proposed branch: lp:~wallyworld/lazr.restful/namedpost-url-change-1056666
Merge into: lp:lazr.restful
Diff against target: 73 lines (+21/-3)
4 files modified
src/lazr/restful/NEWS.txt (+6/-0)
src/lazr/restful/_resource.py (+9/-0)
src/lazr/restful/example/base/tests/entry.txt (+5/-2)
src/lazr/restful/version.txt (+1/-1)
To merge this branch: bzr merge lp:~wallyworld/lazr.restful/namedpost-url-change-1056666
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+126405@code.launchpad.net

Commit message

Redirect to a new location if the resource url changes after a named operation.

Description of the change

A named post operation may result in the resource on which the post is operating to have a different url at the end of the operation. Put and Patch operations do the right thing and issue a 301 with the new location, but named post operations don't. This branch corrects that.

I updated an existing doc test which performs a named post to account for the new behaviour.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/lazr/restful/NEWS.txt'
--- src/lazr/restful/NEWS.txt 2012-03-15 03:07:15 +0000
+++ src/lazr/restful/NEWS.txt 2012-09-26 09:35:24 +0000
@@ -2,6 +2,12 @@
2NEWS for lazr.restful2NEWS for lazr.restful
3=====================3=====================
44
50.19.7 (2012-09-26)
6===================
7
8Fixed bug 1056666: make named operations which result in a resource URL change
9issue a 301 response containing the new location.
10
50.19.6 (2012-03-15)110.19.6 (2012-03-15)
6===================12===================
713
814
=== modified file 'src/lazr/restful/_resource.py'
--- src/lazr/restful/_resource.py 2011-10-11 13:33:15 +0000
+++ src/lazr/restful/_resource.py 2012-09-26 09:35:24 +0000
@@ -1393,6 +1393,7 @@
13931393
1394 def handleCustomPOST(self, operation_name):1394 def handleCustomPOST(self, operation_name):
1395 """See `CustomOperationResourceMixin`."""1395 """See `CustomOperationResourceMixin`."""
1396 original_url = absoluteURL(self.entry.context, self.request)
1396 value = super(EntryResource, self).handleCustomPOST(operation_name)1397 value = super(EntryResource, self).handleCustomPOST(operation_name)
1397 # We don't know what the custom operation might have done.1398 # We don't know what the custom operation might have done.
1398 # Remove this object from the representation cache, just to be1399 # Remove this object from the representation cache, just to be
@@ -1400,6 +1401,14 @@
1400 cache = self._representation_cache1401 cache = self._representation_cache
1401 if cache is not None:1402 if cache is not None:
1402 cache.delete(self.context)1403 cache.delete(self.context)
1404 new_url = absoluteURL(self.entry.context, self.request)
1405 if original_url != new_url:
1406 # The object moved. Serve a redirect to its new location.
1407 # This might not necessarily be the location of the entry!
1408 self.request.response.setStatus(301)
1409 self.request.response.setHeader(
1410 'Location', absoluteURL(self.context, self.request))
1411 return ''
1403 return value1412 return value
14041413
1405 def _getETagCores(self, unmarshalled_field_values=None):1414 def _getETagCores(self, unmarshalled_field_values=None):
14061415
=== modified file 'src/lazr/restful/example/base/tests/entry.txt'
--- src/lazr/restful/example/base/tests/entry.txt 2011-02-01 00:57:27 +0000
+++ src/lazr/restful/example/base/tests/entry.txt 2012-09-26 09:35:24 +0000
@@ -252,13 +252,16 @@
252252
253Some entries support custom operations through POST. You can invoke a253Some entries support custom operations through POST. You can invoke a
254custom operation to modify a cookbook's name, making it seem more254custom operation to modify a cookbook's name, making it seem more
255interesting.255interesting. As a result of the operation, the cookbook's location will
256change so we get a 301 response with the new URL.
256257
257 >>> print webservice.get(joy_url).jsonBody()['cuisine']258 >>> print webservice.get(joy_url).jsonBody()['cuisine']
258 General259 General
259260
260 >>> print webservice.named_post(joy_url, 'make_more_interesting', {})261 >>> print webservice.named_post(joy_url, 'make_more_interesting', {})
261 HTTP/1.1 200 Ok262 HTTP/1.1 301 Moved Permanently
263 ...
264 Location: http://cookbooks.dev/devel/cookbooks/The%20New%20The%20Joy%20of%20Cooking
262 ...265 ...
263266
264 >>> new_joy_url = quote("/cookbooks/The New The Joy of Cooking")267 >>> new_joy_url = quote("/cookbooks/The New The Joy of Cooking")
265268
=== modified file 'src/lazr/restful/version.txt'
--- src/lazr/restful/version.txt 2012-03-15 03:07:15 +0000
+++ src/lazr/restful/version.txt 2012-09-26 09:35:24 +0000
@@ -1,1 +1,1 @@
10.19.610.19.7

Subscribers

People subscribed via source and target branches