pokeb/asi-http-request — Issue #298: HEADRequest returns an ASIHTTPRequest with a non-retaining reference to self
Author: bri3d
Created: 2011-12-20 22:10:34+00:00
State: open

I understand that it's not documented officially, but HEADRequest's comment indicates that "you can use it yourself."

This is quite difficult, because HEADRequest sets mainRequest to self without a retain, and mainRequest is an assigned property. Hence, when the created HEADRequest references the mainRequest, it's generally been released already (especially if the request is used asynchronously) and its behavior becomes undefined (usually an EXEC_BAD_ACCESS when theRequest is assigned to mainRequest in readResponseHeaders).

I think there a are a few solutions here:
1) Document that the sender must retain the ASIHTTPRequest to which HEADRequest was sent for the lifetime of the linked HEADRequest. This seems really bad (in addition to highly inconvenient in the case of asynchronous HEAD requests). On the flip side, it requires no code change.

- or -

2) Make mainRequest a retained property (or implement similar retain/release behavior). This is a code change and might have an effect I'm not thinking about, but it's a lot more logical and less dangerous.