-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User-Agent is missing from NSURLRequest
in stubRequestsPassingTest:...
when using NSURLSessionConfiguraiton
?
#82
Comments
I believe this is because NSURLSession adds the HTTPAdditionalHeaders at the very end just before sending the request to the network, so you are querying them too soon? Will try and investigate but I'm not sure it has anything to do with OHHTTPStubs code itself, but more to do with the way Cocoa URL Loading system handles this property and when it uses it to add the headers. Will keep you posted. |
Unfortunately I just confirmed that it seems to be iOS's fault. (1) I created a NSURLSessionConfiguration and NSURLSession as in your code: NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
config.HTTPAdditionalHeaders = @{ @"User-Agent": @"Test User Agent" };
NSURLSession *session = [NSURLSession sessionWithConfiguration:config]; (2) Then sent a request with this session: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"foo://unknownhost:666"]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
NSLog(@"Completed");
} (3) I set a breakpoint in my At that time, So unfortunately this issue does not seem to be coming from my own code (where I could have had overridden the headers maybe, in that case I could have had that fixed) but from iOS itself 😞 PS: Probably this If you have any suggestion on how to hack into that, I'm interested. |
…equest being made) from the NSURLProtocol methods. [Work In Progress] This is an attempt to fix #82 — (but the code has to be cleaned-up a bit and heavily tested before I do a release)
Hi again, I've started working on a branch to workaround this issue. Feel free to test this branch in your code and tell me if it fixes your issue. If so I'll cleanup the code and ensure it's portable (even for those using older SDKs/versions or still using |
I just discovered a very strange behavior:
@rsaunders100 Do you observe the same behavior on your app? This comforts me in the fact that this is an iOS bug. I encourage you to fill a radar / bug report to Apple. |
Awesome stuff. I'll do that. Sent from my iPhone
|
Do you still have the issue with iOS8.1, 8.2 and 8.3? [EDIT] Ok nvm, I misread the tests I recently added; the issue is still present in iOS8.3, still trying to find a workaround for this Apple bug (but it's quite hard as we don't have access to the |
…the request if not done by iOS (iOS8 Bug, see #82)
… the request being made) from the NSURLProtocol methods. This is an attempt to fix #82 — (but the code has to be cleaned-up a bit and heavily tested before I do a release)
I am setting up the userAgent string using
NSURLSessionConfiguraiton
:The User-Agent is being sent over the network - I can see it using Charles Proxy. However, it is not coming though in the stub checker:
The text was updated successfully, but these errors were encountered: