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

Use .NET standard HttpClient instead of HttpHelper #1326

Merged
merged 5 commits into from
Jul 20, 2017
Merged

Conversation

hermitdave
Copy link
Contributor

Use .NET standard HttpClient instead of HttpHelper

return _httpClient;
}

var messageHandler = new HttpClientHandler() { MaxConnectionsPerServer = 10 };
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't we want to allow a developer to specify their own MaxConnectionsPerServer value if 10 didn't work for their scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbarkerms they can specify their own HttpMessageHandler which is then used when instantiating the httpClient.. we can do one or the other..

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I see it now, thanks

/// <returns>awaitable task</returns>
public virtual async Task InitializeAsync(StorageFolder folder, string folderName)
public virtual async Task InitializeAsync(StorageFolder folder, string folderName, HttpMessageHandler httpMessageHandler = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this method be simplified by calling the above overload?

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 the heck did i do that change for. Let me have another look there

break;
}
}
catch (FileNotFoundException)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we swallowing exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have seen requests finish with no data.. Hence retry loop.. This happened on very rare occasions before as well but wasn't very noticable.. Swallowing only FileNotFound that is throw by InitializeAsync btw

Copy link
Contributor

Choose a reason for hiding this comment

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

ok makes sense thanks

return _httpClient;
}

var messageHandler = new HttpClientHandler() { MaxConnectionsPerServer = 10 };
Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I see it now, thanks

Upgrade Microsoft.NETCore.UniversalWindowsPlatform nuget to 5.3.3 to see if appveyor issue is resolved
@hermitdave hermitdave force-pushed the CacheBase-HttpClient branch from 96a9023 to ceb3279 Compare July 19, 2017 22:02
This change also maintains Microsoft.NETCore.UniversalWindowsPlatform NuGet package on version 5.3.3
Mark HttpHelper, HttpHelperRequest and HttpHelperResponse obsolete
Add CacheBase.InitializeAsync overload previously available.
{
get
{
if (_httpClient != null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we reverse this if

if(_httpClient == null)
{
    var messageHandler = new HttpClientHandler() { MaxConnectionsPerServer = 10 };
    _httpClient = new HttpClient(messageHandler);
}
return _httpClient;

/// <param name="folderName">Cache folder name</param>
/// <param name="httpMessageHandler">instance of <see cref="HttpMessageHandler"/></param>
/// <returns>awaitable task</returns>
public virtual async Task InitializeAsync(StorageFolder folder, string folderName, HttpMessageHandler httpMessageHandler)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have all the overloads for this method? Why not one method with everything initialized to null?

public virtual async Task InitializeAsync(StorageFolder folder = null, string folderName = null, HttpMessageHandler httpMessageHandler = null)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally hate having to set things to null when calling methods.. I am not fussed.. I can reverted to original calls only

Copy link
Contributor

Choose a reason for hiding this comment

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

The dev wouldn't need to set anything because they already have defaults

Copy link
Contributor

@skendrot skendrot Jul 20, 2017

Choose a reason for hiding this comment

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

With the above method the dev can do the following:
InitializeAsync();
InitializeAsync(StorageFolder.GetFolder());
InitializeAsync("bob");
InitializeAsync(new ClientHttpMessageHandler());
InitializeAsync(StorageFolder.GetFolder(), "bob");
On and on...

{
stream.CopyTo(fs);

fs.Flush();
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't need to flush if in a using statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skendrot I just encountered an issue when copying stream where stream needed flushing explicitly.. every single call resulted in partially copied stream returned to caller unless flush was called.


webStream.Seek(0);
instance = await InitializeTypeAsync(randomAccessStream, initializerKeyValues).ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the stream from the response not be passed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bitmap requests IRandomAccessStream. The original stream is Stream and the operation has to be done somewhere.

@skendrot skendrot merged commit 24ec0c3 into dev Jul 20, 2017
@pedrolamas pedrolamas deleted the CacheBase-HttpClient branch July 20, 2017 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants