Hello Sven, Yes, this is exactly what I need. Thanks very much for the quick fix! I know that resuming the exception also works. That was the solution that I used until now. But the new solution is much nicer. Jan. On Wed, Nov 23, 2011 at 5:37 PM, Sven Van Caekenberghe <sven@beta9.be>wrote:
Jan,
On 23 Nov 2011, at 14:12, Sven Van Caekenberghe wrote:
Let me think a bit about this, and I will come back to you.
I added some new features so that now this should work:
testRedirectDontFollow | client | (client := ZnClient new) dontFollowRedirects; get: 'http://www.pharo-project.org'. self assert: client response isRedirect. client enforceHttpSuccess: true; get: 'http://www.pharo-project.org'. self assert: client response isRedirect. client close
I think this will cover your use case, please let me know how it goes.
I discovered that I more ore less already had something that came close:
testRedirect | client response | client := ZnClient new url: 'http://www.pharo-project.org'. self assert: (client get; isSuccess). client close; maxNumberOfRedirects: 0; url: 'http://www.pharo-project.org'. self should: [ client get ] raise: ZnTooManyRedirects. client close. response := [ ZnClient new beOneShot; maxNumberOfRedirects: 0; get: 'http://www.pharo-project.org'; response ] on: ZnTooManyRedirects do: [ :exception | exception resume ]. self assert: response isRedirect
Resuming the exception gave a true redirect response.
But that code is not very nice/handy, and it would not work when combined with enforceHttpSuccess: true.
These are new commits:
==================== Summary ====================
Name: Zinc-HTTP-SvenVanCaekenberghe.221 Author: SvenVanCaekenberghe Time: 23 November 2011, 5:30:09 pm UUID: 4df9982e-63e1-49ea-bfb0-2f9cb43f6f0b Ancestors: Zinc-HTTP-SvenVanCaekenberghe.220
added new #followsRedirects boolean option to ZnClient because setting #maxNumberOfRedirects to 0 did not work well for an example see the ZnClientTests>>#testRedirectDontFollow Thx Jan van de Sandt for reporting this
==================== Summary ====================
Name: Zinc-Tests-SvenVanCaekenberghe.115 Author: SvenVanCaekenberghe Time: 23 November 2011, 5:31:22 pm UUID: eb8c67e4-bdf2-4741-b149-78bdaf5d4970 Ancestors: Zinc-Tests-SvenVanCaekenberghe.114
added ZnClientTests>>#testRedirectDontFollow to test the new #followsRedirects boolean option to ZnClient, including under the case of #enforceHttpSuccess: true
Regards,
Sven