-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make ZnTooManyRedirects more intelligent (add a trail of followed URL…
…s and two resume behaviors)
- Loading branch information
Showing
11 changed files
with
84 additions
and
19 deletions.
There are no files selected for viewing
14 changes: 0 additions & 14 deletions
14
repository/Zinc-HTTP.package/ZnClient.class/instance/executeWithRedirectsRemaining..st
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
repository/Zinc-HTTP.package/ZnClient.class/instance/executeWithRedirectsRemaining.trail..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
private - protocol | ||
executeWithRedirectsRemaining: redirectCount trail: collectionOfUrls | ||
self getConnectionAndExecute. | ||
response isRedirect | ||
ifTrue: [ | ||
(redirectCount > 0 and: [ self followRedirects ]) | ||
ifTrue: [ | ||
self prepareRedirect. | ||
collectionOfUrls add: self request url. | ||
self | ||
executeWithRedirectsRemaining: redirectCount - 1 | ||
trail: collectionOfUrls ] | ||
ifFalse: [ | ||
self followRedirects | ||
ifTrue: [ | exception | | ||
(exception := ZnTooManyRedirects new) | ||
trail: collectionOfUrls. | ||
exception signal = exception defaultResumeValue | ||
ifTrue: [ | ||
"when resumed with default resume value, start over" | ||
self | ||
executeWithRedirectsRemaining: self maxNumberOfRedirects | ||
trail: collectionOfUrls ] ] ] ]. | ||
^ self handleResponse |
4 changes: 3 additions & 1 deletion
4
repository/Zinc-HTTP.package/ZnClient.class/instance/executeWithRetriesRemaining..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
repository/Zinc-HTTP.package/ZnTooManyRedirects.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
ZnTooManyRedirects is signalled when an HTTP client has been following more redirects than allowed. | ||
|
||
The default resume behavior is to retry, signal with any other value to give up just return the redirect. | ||
|
||
Part of Zinc HTTP Components. |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP.package/ZnTooManyRedirects.class/instance/defaultResumeValue.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
private | ||
defaultResumeValue | ||
^ #retry |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP.package/ZnTooManyRedirects.class/instance/trail..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
trail: aCollectionOfUrls | ||
trail := aCollectionOfUrls |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP.package/ZnTooManyRedirects.class/instance/trail.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
trail | ||
^ trail |
6 changes: 4 additions & 2 deletions
6
repository/Zinc-HTTP.package/ZnTooManyRedirects.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
{ | ||
"commentStamp" : "", | ||
"commentStamp" : "<historical>", | ||
"super" : "Error", | ||
"category" : "Zinc-HTTP-Exceptions", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ ], | ||
"instvars" : [ | ||
"trail" | ||
], | ||
"name" : "ZnTooManyRedirects", | ||
"type" : "normal" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
self packageOrganizer ensurePackage: #'Zinc-HTTP' withTags: #(#'Client-Server' #Core #Exceptions #Logging #Streaming #Support #Variables)! | ||
SystemOrganization addCategory: #'Zinc-HTTP'! | ||
SystemOrganization addCategory: #'Zinc-HTTP-Client-Server'! | ||
SystemOrganization addCategory: #'Zinc-HTTP-Core'! | ||
SystemOrganization addCategory: #'Zinc-HTTP-Exceptions'! | ||
SystemOrganization addCategory: #'Zinc-HTTP-Logging'! | ||
SystemOrganization addCategory: #'Zinc-HTTP-Streaming'! | ||
SystemOrganization addCategory: #'Zinc-HTTP-Support'! | ||
SystemOrganization addCategory: #'Zinc-HTTP-Variables'! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
repository/Zinc-Tests.package/ZnClientTest.class/instance/testRedirectLoopAndTrail.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
testing | ||
testRedirectLoopAndTrail | ||
self withServerDo: [ :server | | client count | | ||
server onRequestRespond: [ :request | | ||
request uri firstPathSegment = 'follow' | ||
ifTrue: [ ZnResponse redirect: 'follow' ] ]. | ||
|
||
(client := ZnClient new) | ||
url: server localUrl; addPath: 'follow'; | ||
maxNumberOfRedirects: 10. | ||
self should: [ client get ] raise: ZnTooManyRedirects. | ||
client close. | ||
|
||
(client := ZnClient new) | ||
url: server localUrl; addPath: 'follow'; | ||
maxNumberOfRedirects: 10. | ||
[ client get ] on: ZnTooManyRedirects do: [ :exception | | ||
self assert: exception isResumable. | ||
self assert: exception trail size equals: 10. | ||
self assert: (exception trail allSatisfy: [ :each | each = (server localUrl / 'follow') ]) ]. | ||
client close. | ||
|
||
(client := ZnClient new) | ||
url: server localUrl; addPath: 'follow'; | ||
maxNumberOfRedirects: 10. | ||
count := 0. | ||
[ client get ] on: ZnTooManyRedirects do: [ :exception | | ||
count := count + 1. | ||
exception trail size <= 30 | ||
ifTrue: [ exception resume ] | ||
ifFalse: [ exception resume: #doNotRetry ] ]. | ||
self assert: count equals: 4. | ||
client close ] |