Skip to content

Commit

Permalink
limit the amount of redirects to a fixed number and also don't create…
Browse files Browse the repository at this point in the history
… a new request object since it's already setup for us
  • Loading branch information
mattetti authored and Marin Usalj committed Jul 27, 2012
1 parent 84f8555 commit 9d2c7c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions motion/core/ns_url_request.rb
Expand Up @@ -3,8 +3,10 @@ class NSURLRequest
# Provides a to_s method so we can use inspect in instances and get
# valuable information.
def to_s
"#<#{self.class}:#{self.object_id} - url: #{self.URL.description}, cache policy: #{self.cachePolicy}, Pipelining: #{self.HTTPShouldUsePipelining}, main doc url: #{mainDocumentURL},\
timeout: #{self.timeoutInterval}, network service type: #{self.networkServiceType} >"
"#<#{self.class}:#{self.object_id} - url: #{self.URL.description},
headers: #{self.allHTTPHeaderFields.inspect},
cache policy: #{self.cachePolicy}, Pipelining: #{self.HTTPShouldUsePipelining}, main doc url: #{mainDocumentURL},\
timeout: #{self.timeoutInterval}, network service type: #{self.networkServiceType} >"
end

end
17 changes: 10 additions & 7 deletions motion/http.rb
Expand Up @@ -159,13 +159,16 @@ def connection(connection, didReceiveData:received_data)
def connection(connection, willSendRequest:request, redirectResponse:redirect_response)
@redirection ||= 0
@redirection += 1
log "##{@redirection} HTTP redirection: #{request} - #{self.description}"
new_request = request.mutableCopy
# new_request.setValue(@credentials.inspect, forHTTPHeaderField:'Authorization') # disabled while we figure this one out
new_request.setAllHTTPHeaderFields(@headers) if @headers
@connection.cancel
@connection = create_connection(new_request, self)
new_request
log "##{@redirection} HTTP redirection: #{request.inspect} - #{self.description}"
if @redirection >= 30

This comment has been minimized.

Copy link
@nov

nov Aug 27, 2012

Contributor

I feel 30 is too large for iOS device, especially in 3G network.
Maybe 5 or 6 is enough?

This comment has been minimized.

Copy link
@supermarin

supermarin Aug 27, 2012

Contributor

Hm, have you tried timing how much does it take for 1 redirect?

This comment has been minimized.

Copy link
@nov

nov Aug 27, 2012

Contributor

In my current case, it shouldn't redirect, so this number doesn't matter.
But this method is called when received 30x response, isn't it?

log "Too many redirections"
@response.error_message = "Too many redirections"
@request.done_loading!
call_delegator_with_response
nil
else
request
end
end

def connection(connection, didFailWithError: error)
Expand Down

0 comments on commit 9d2c7c6

Please sign in to comment.