Skip to content
This repository

Redirect delegate call sequence fix #301

Open
wants to merge 1 commit into from

2 participants

Yung-Luen Lan johnz45
Yung-Luen Lan

Currently, the requestRedirected delegate method will be called right after the header is parsed. However, the data received delegate method which comes together with the redirected header will be called after the requestRedirected callback.

The sequence is like this:

  1. HTTP Redirect Header
  2. requestRedirected
  3. HTTP Redirect Body (usually some simple html indicate the redirection)
  4. dataReceived
  5. HTTP Header
  6. headerReceived
  7. HTTP Body
  8. dataReceived

I think in this sequence, step 4 may cause bugs. The delegate is most likely accumulating the received data for writing to file, live parsing, etc. Apparently, we should not append the data received from step 4 to step 8. The most straight forward thought is to "reset" the data status after the request being redirected but that actually happens before step 4.

I propose to move the step 2 between step 4 and 5.

Yung-Luen Lan yllan referenced this pull request
Closed

Redirect fix #300

johnz45

There is actually a check in handleBytesReceived that returns before calling the dataReceived delegate if there is a redirect happening. This redirect flag is set at step 1 during response header reading and reset after step 4. Hence, it should be fine in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 2 authors.

Jan 16, 2012
yllan Call requestRedirected after the request is actually redirected, not …
…before.
3a5278f
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 2 deletions. Show diff stats Hide diff stats

  1. +1 2  Classes/ASIHTTPRequest.m
3  Classes/ASIHTTPRequest.m
@@ -1466,6 +1466,7 @@ - (void)performRedirect
1466 1466 } else {
1467 1467 // Go all the way back to the beginning and build the request again, so that we can apply any new cookies
1468 1468 [self main];
  1469 + [self performSelectorOnMainThread:@selector(requestRedirected) withObject:nil waitUntilDone:[NSThread isMainThread]];
1469 1470 }
1470 1471 }
1471 1472
@@ -2314,8 +2315,6 @@ - (BOOL)willRedirect
2314 2315 return NO;
2315 2316 }
2316 2317
2317   - [self performSelectorOnMainThread:@selector(requestRedirected) withObject:nil waitUntilDone:[NSThread isMainThread]];
2318   -
2319 2318 // By default, we redirect 301 and 302 response codes as GET requests
2320 2319 // According to RFC 2616 this is wrong, but this is what most browsers do, so it's probably what you're expecting to happen
2321 2320 // See also:

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.