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

Check if NSURLProtocolClient has private callback before calling it #2765

Merged

Conversation

ms-jihua
Copy link
Contributor

@ms-jihua ms-jihua commented Jun 8, 2017

Fixes #2764


This change is Reviewable

Copy link

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

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

Why didn't our test collateral hit this? Is it because we don't ever POST with NSURLSession?

@@ -288,7 +288,8 @@ - (void)startLoading {
// TODO #2721: If this properly supports streaming bodies instead of flattening the data up front,
// more accurate callbacks can be done
NSInteger contentSize = self.request.HTTPBody ? self.request.HTTPBody.length : _flattenedBodyStream.size();
if (contentSize > 0) {
if (([self.client respondsToSelector:@selector(URLProtocol:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:)]) &&

Choose a reason for hiding this comment

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

In looking for this issue, I realized that no header declares the protocol method URLProtocol:didWriteData:...; could we add one in NSURLProtocolInternal? Ideally, NSURLConnection would conform to this private protocol, and the compiler would warn us if it didn't have the right methods on it. NSURLSessionTask should eventually do this, but it doesn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is literally declared in NSURLProtocolInternal.h...

Copy link
Contributor

Choose a reason for hiding this comment

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

there are other "private" invocations in this file, are these expected to succeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by other "private" invocations?

@DHowett-MSFT
Copy link

DHowett-MSFT commented Jun 8, 2017

@ms-jihua this is the entirety of NSURLProtocolInternal.h for me:

//******************************************************************************
//
// Copyright (c) Microsoft. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************

#pragma once

#import "Starboard/SmartTypes.h"

@interface NSURLProtocol ()
+ (id)_URLProtocolClassForRequest:(id)request;

@end

@ms-jihua
Copy link
Contributor Author

ms-jihua commented Jun 8, 2017

Yup, we lack POST/UploadTask tests for NSURLSession - should I add some?

@ms-jihua
Copy link
Contributor Author

ms-jihua commented Jun 8, 2017

@DHowett-MSFT ...I somehow missed the existence of another NSURLProtocolInternal.h in Frameworks/include. I'll coalesce it with the one in Frameworks\Foundation.

@rajsesh
Copy link
Contributor

rajsesh commented Jun 8, 2017

@ms-jihua yes, It would be helpful to have at least one test for POST using NSURLSession.

@ms-jihua
Copy link
Contributor Author

ms-jihua commented Jun 8, 2017

@DHowett-MSFT @rajsesh-msft wait a second, [NSURLSession uploadTaskWith...] functions are still stubs. How did we hit this bug?

@DHowett-MSFT
Copy link

@ms-jihua two things: 1) users can implement NSURLProtocolClient on their own, and they don't know about this. 2) A data task can still be a post with a body stream if it's created from an NSURLRequest with a body/bodystream. Also, GETs can have bodies just as well as POSTs can. 😄

- Add test for a POST NSURLSessionTask
@rajsesh rajsesh merged commit c5fb684 into microsoft:develop Jun 9, 2017
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.

5 participants