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

Added Cookie Header to XML and Websocket request #10575

Closed
wants to merge 2 commits into from

Conversation

clozr
Copy link

@clozr clozr commented Oct 27, 2016

Continuation of Pull Request #7167

#7167

Needed to clean my repository. So created this Pull Request

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @javache and @philikon to be potential reviewers.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 27, 2016
@lacker
Copy link
Contributor

lacker commented Oct 29, 2016

Why is this the right behavior? It's not clear to me that these libraries should automatically use cookies.

FWIW #9114 is a similar pull request.

@clozr
Copy link
Author

clozr commented Oct 29, 2016

Fetch & Websocket API should be a drop-in replacement for the web version of the code.
In webapp, the http protocol handler will send any cookie for that domain when making websocket request. Same thing for any fetch request.
Besides, this is a very common pattern and if we go by DRY philosophy, it makes sense to support this pattern so that other users don't have to reinvent the wheel. I hope this clarifies.

@lacker
Copy link
Contributor

lacker commented Nov 7, 2016

I accepted #9114 for websockets since that had already been reviewed by a bunch of folks, so I think you will need to update this to just center on non websocket things.

@clozr
Copy link
Author

clozr commented Nov 7, 2016

@lacker I just took a quick look at #9114 and that seems to be android counterpart of this PR. We still need to do it for objective-c. However, since he has already written the test for this scenario we don't need a separate testcase, his testcase should be enough to test this one as well.

@lacker lacker self-assigned this Nov 7, 2016
@lacker
Copy link
Contributor

lacker commented Nov 7, 2016

OK sounds good to me.

@lacker
Copy link
Contributor

lacker commented Nov 30, 2016

Hey, so I am unclear on the status of this, maybe I wasn't specific enough. With #9114 does this PR need to be updated, or do you think it's ready to go right now? In particular I am curious how we should test given the two different PRs that the behavior is the same cross-platform.

@clozr
Copy link
Author

clozr commented Dec 8, 2016

@lacker I reviewed the #9114, that PR fixes sending cookie header in websocket request for android websocket. This PR also does the same for IOS side. Since the test for #9114 was written in JS and platform agnostics, same test also works for this PR.
However this PR also fixes, saving and sending cookies in XHR requests on IOS as well.

@lacker
Copy link
Contributor

lacker commented Dec 8, 2016

Can you make this be tested automatically? It seems like that manual procedure in the other pull request, nobody is ever going to do that.

@hramos
Copy link
Contributor

hramos commented Jan 19, 2017

Ping @clozr, see earlier feedback.

@clozr
Copy link
Author

clozr commented Jan 21, 2017

To test automatically we will need a test mode callback to examine the headers being sent for websocket connect request. Give me couple of days to do it.

@ycai2
Copy link

ycai2 commented Mar 29, 2017

Is this PR ready to be merged? @clozr

@GrigoryPtashko
Copy link

I side up with everybody who's waiting for this feature. Are there any plans on when this PR is going to be merged?

@shergin
Copy link
Contributor

shergin commented Apr 26, 2017

I believe we should merge this.

@facebook-github-bot facebook-github-bot added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: needs-revision labels Apr 26, 2017
@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification.

@facebook-github-bot facebook-github-bot removed the Import Started This pull request has been imported. This does not imply the PR has been approved. label Apr 27, 2017
@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label May 5, 2017
@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@shergin
Copy link
Contributor

shergin commented May 7, 2017

@clozr Looks like we have weird difficulties with merging this PR. Could you please rebase it on master?

@clozr clozr force-pushed the network branch 3 times, most recently from 22a2a5e to d3b3c35 Compare May 8, 2017 02:02
@clozr
Copy link
Author

clozr commented May 8, 2017

Just updated the PR to facebook/master. Please let me know if you come across any problem

@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ycai2
Copy link

ycai2 commented May 18, 2017

@clozr It seems like this PR can't be merged. Could you take a look at the build failure?

@clozr clozr force-pushed the network branch 2 times, most recently from 3b6849a to 15a9471 Compare May 18, 2017 00:37
@clozr
Copy link
Author

clozr commented May 18, 2017

Looks like there were some unrelated issues. I have rebased it again. Let's see how the current build goes.

@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@clozr
Copy link
Author

clozr commented May 18, 2017

Looks Good now

Copy link
Contributor

@shergin shergin left a comment

Choose a reason for hiding this comment

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

I am soooory for late detailed review but code style should be fixed.

@@ -63,6 +63,9 @@ - (NSURLSessionDataTask *)sendRequest:(NSURLRequest *)request
callbackQueue.maxConcurrentOperationCount = 1;
callbackQueue.underlyingQueue = [[_bridge networking] methodQueue];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
[ configuration setHTTPShouldSetCookies:YES];
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, fix codestyle across all changed lines. This diff cannot be merged without it (because of linter).

NSDictionary* headers = [RCTConvert NSDictionary:query[@"headers"]];
[headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
//request.allHTTPHeaderFields = [self stripNullsInRequestHeaders:[RCTConvert NSDictionary:query[@"headers"]]];
if(value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, add space.

// set supplied headers
NSDictionary* headers = [RCTConvert NSDictionary:query[@"headers"]];
[headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
//request.allHTTPHeaderFields = [self stripNullsInRequestHeaders:[RCTConvert NSDictionary:query[@"headers"]]];
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this line.

// fetch). To get secure cookies for wss URLs, replace wss with https
// in the URL.
NSURLComponents *components = [NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:true];
if ([[components.scheme lowercaseString] isEqualToString:@"wss"]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, use dot notation for lowercaseString.

if ([[components.scheme lowercaseString] isEqualToString:@"wss"]) {
components.scheme = @"https";
}
// Load and set the cookie header.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add new line.

// Load and set the cookie header.
NSArray<NSHTTPCookie *> *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:URL];
request.allHTTPHeaderFields = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this line.

request.allHTTPHeaderFields = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];


// set supplied headers
Copy link
Contributor

Choose a reason for hiding this comment

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

Capital letter, full stop at the end.



// set supplied headers
NSDictionary* headers = [RCTConvert NSDictionary:query[@"headers"]];
Copy link
Contributor

Choose a reason for hiding this comment

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

NSDictionary *headers = ...

@clozr
Copy link
Author

clozr commented May 19, 2017

Fixed the lint errors. Let me know any more issues

@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants