Skip to content
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

Drop special headers from redirected requests #289

Merged
merged 5 commits into from
Mar 9, 2019
Merged

Drop special headers from redirected requests #289

merged 5 commits into from
Mar 9, 2019

Conversation

sberrevoets
Copy link
Contributor

Checklist

  • I've checked that all new and existing tests pass
  • I've updated the documentation if necessary
  • I've added an entry in the CHANGELOG to credit myself

Description

The change in #263 means a redirected request had the same headers as the original request (because it was a copy and not a brand new NSURLRequest instance).

While the new behavior was correct, it didn't account for "special headers" that URLSession "handles". The docs aren't entirely clear what that means, but we've at least confirmed it removes the "Authorization" headers as that poses a security risk, so this PR removes all those headers + a test.

@keith
Copy link

keith commented Sep 16, 2018

I think these test failures are related to your changes @sberrevoets ? It looks like master is mostly green (besides some flakes)

@sberrevoets
Copy link
Contributor Author

sberrevoets commented Sep 16, 2018

I was able to reproduce this once (via rake, I never saw them fail in Xcode 9.4.1), but now even rake is succeeding locally.

@AliSoftware any idea what might be going on?

@AliSoftware
Copy link
Owner

AliSoftware commented Sep 16, 2018

I think the build failures might be related to the race condition bug we discovered in URLSession in #230 (comment) (don't hesitate to duplicate the radar to help us make Apple fix it btw)

See also #280

@sberrevoets
Copy link
Contributor Author

Ah thanks for the heads up, I've duped the radar. What would you like to see here in the meantime?

@sberrevoets
Copy link
Contributor Author

Friendly ping @AliSoftware :)

@AliSoftware
Copy link
Owner

Sorry for the late reply.
I honestly don't really know. I mean those redirect tests are probably always gonna fail until that Apple bug gets fixed or we find a workaround.
So maybe we should merge that anyway given that the failures are not our fault?

Or a better solution might be to introduce a small delay in the redirection (like what we done in the other PR to confirm the bug was a race condition) as it seemed to at least reduce a lot the bug from happening; even if that means introducing a delay and slowing down stuff a little, that's probably better than failing 70% of the time…?

@sberrevoets
Copy link
Contributor Author

Yeah that's a very good question. For me it'd probably depend on how much it fails. If it really is 70% of the time right now then adding a delay seems worth it. If it's every now and then, it might be possible to (somehow) auto-retry the affected tests, or take a simpler approach of adding a comment explaining the problem.

I'm also open to alternatives, framework bugs like these are a huge PITA 😕

@jeffctown
Copy link
Collaborator

@sberrevoets - we're reviewing all outstanding PRs before making a release, and then updating the version of Swift being used. the hope is to do all of this before Xcode 10.2 comes out, so our timeline is a bit tight.

If you are still interested in getting this in, please resolve the conflicts. If you are not interested, having that feedback would be helpful too.

@sberrevoets
Copy link
Contributor Author

Happy to resolve conflicts (though can't promise I'll have time for that before the 10.2 release), but how depends on what approach is preferable. Based on the conversation above I'm not sure if there's a clear path forward.

@jeffctown
Copy link
Collaborator

jeffctown commented Mar 8, 2019

@sberrevoets - if you mean the failing tests - those were disabled in CI (#301 & #302), so you don't need to worry about that part. We only need the conflicts resolved. If you want to give me permission to commit to your fork's master branch I don't mind resolving them myself. the tests should pass once the conflicts are resolved.

@sberrevoets
Copy link
Contributor Author

Ah I missed that, that makes resolving conflicts a bit easier. Pushed an update but also gave edit access just in case.

@jeffctown jeffctown requested review from AliSoftware and Liquidsoul and removed request for AliSoftware March 8, 2019 19:11
Copy link
Owner

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little sad that the tests that were previously added and which were testing if proper headers were dropped or preserved… got removed.

I mean I know they are flaky due to the Apple Bug but with #301 and #302 the goal was to disable those… only on CI. While still be able to run them on Xcode (which seemed less prone to the race condition bug for some reason probably related to our personal machines speeds)

So I think it would still be valuable to reintroduce that test that we had before the recent commit fixing the conflict, even though it won't be run by CI, as it seemed valuable and properly written and could still be useful to have when we run the tests on Xcode and not on CI.

[mReq setValue:nil forHTTPHeaderField:@"Host"];
[mReq setValue:nil forHTTPHeaderField:@"Proxy-Authenticate"];
[mReq setValue:nil forHTTPHeaderField:@"Proxy-Authorization"];
[mReq setValue:nil forHTTPHeaderField:@"WWW-Authenticate"];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could maybe be a for header in @[@"…",@"…",…] loop instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit to put this into it's own method since where it is now is already a bit large.

@jeffctown
Copy link
Collaborator

jeffctown commented Mar 8, 2019

@AliSoftware I updated this branch with a for loop, and I still see the conditional tests.

@AliSoftware
Copy link
Owner

I was talking about a new test case that @sberrevoets wrote in his initial commits, and that I remember about from when I reviewed the diff on that PR before the conflict resolution today. That new test case which was added in that PR was essentially creating a request, with all the headers of interest here + another header — named "preserved" iirc —, and after using that dummy request and redirecting it, did XCTAssertNil() on all proper headers to check they were properly removed and an XCTAssertEqual() on the one named "preserved" to check it wasn't removed.

That test case seems not to be there anymore (or is my GitHub view of the PR diff on my phone making me missing something?). It probably was removed by the force-push done by @sberrevoets today I guess. While I think it would be worth to have that test case back (even if it ends up not being run on CI because we disabled them there, but they would still be able to be run locally in Xcode)

@jeffctown
Copy link
Collaborator

Oh! My bad man. I thought you meant the buggy test.

Sent with GitHawk

@sberrevoets
Copy link
Contributor Author

I did remove that test case because it was one of the conflicts. Working on adding that back now.

@sberrevoets
Copy link
Contributor Author

Added that back and ran it locally - it still passed.

@"Proxy-Authenticate": @"proxy-authenticate",
@"Proxy-Authorization": @"proxy-authorization",
@"WWW-Authenticate": @"www-authenticate",
@"Preserved": @"preserved"
Copy link
Owner

@AliSoftware AliSoftware Mar 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because if, say, we change the implementation one day and accidentally make the new implementation behave ( wrongly) as "remove all headers but the last" or "only keep one header" (instead of doing what it's supposed to do like today), I would try to put one or two more "headers to be preserved" in there and intertwine them in the middle of that list instead of all in the end 😉 #paranoiaModeOn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since it's a dictionary order isn't guaranteed anyway? Is that different under the NSURLSession hood?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point!

Though I suspect that dictionary literals, even though they don't guarantee order by contract as it's not a expected requirement for dicts, might end up always being iterated in the same deterministic order in practice (because of current implantation details of dictionary literals in ObjC)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it doesn't hurt to add - done. (In a separate commit for reviewing purposes, happy to rebase at the end if you'd like.)

@AliSoftware
Copy link
Owner

Thanks @sberrevoets 🎉

@sberrevoets
Copy link
Contributor Author

Thanks for the reviews and suggestions!

@jeffctown jeffctown merged commit e2dd12e into AliSoftware:master Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants