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

Replace HttpWebRequest with HttpClient #35

Open
rogerfar opened this issue Feb 11, 2021 · 8 comments
Open

Replace HttpWebRequest with HttpClient #35

rogerfar opened this issue Feb 11, 2021 · 8 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@rogerfar
Copy link

I came across this issue recently:
https://stackoverflow.com/questions/66156483/webrequest-behavour-different-between-net-framework-4-8-and-dotnet-5
and
https://twitter.com/mikaelsyska/status/1359968961765535744

It might be worth looking into replacing the HttpWebRequest in ChunkDownloader with something like a HttpClient, which has been completely rewritten in .NET Core and should yield better performance.

@ghost1372
Copy link
Contributor

similar to #31
And yes, I agree with that😁

@bezzad bezzad self-assigned this Feb 12, 2021
@bezzad bezzad added the good first issue Good for newcomers label Feb 12, 2021
@bezzad
Copy link
Owner

bezzad commented Feb 12, 2021

I'm researching and I hope I can find a solution soon. Because the structure cost of the program for conversion and full use of HttpClient is expensive.

@hez2010
Copy link

hez2010 commented Aug 23, 2021

I think HttpWebRequest can be replaced with HttpRequestMessage, the later one is used by HttpClient and almost the same with HttpWebRequest. Also note that HttpClient should be used as singleton (it won't release socket even after calling Dispose()).

@GihanSoft
Copy link
Contributor

There is a problem with http client.
Buffer of HttpClient is limited to 2GB.
Won't it make problems?

@hez2010
Copy link

hez2010 commented Oct 10, 2021

@GihanSoft You can buffer it by yourself while using HttpClient:

var req = new HttpRequestMessage(...);
var res = (await httpClient.SendAsync(req, HttpCompletionOption.ResponseHeadersRead)).EnsureSuccessStatusCode();
using var stream = await res.Content.ReadAsStreamAsync();
const int bufferSize = 1048576;
var buffer = new byte[bufferSize];
while (true)
{
    var length = await stream.ReadAsync(buffer);
    if (length == 0) break;
    // use buffer[0..length]
}

@GihanSoft
Copy link
Contributor

@hez2010
The point is you can't control flow of date. no way to pause it or slow it. If you set low buffer capacity, it won't wait for buffer to be read. It just throw.

@NALStudio
Copy link

HttpWebRequest and all related methods have been deprecated since .NET 6. We are already at .NET 9, and I wouldn't bet on this functionality being in .NET for much longer, so it would probably be wise to start to port this project over to HttpClient soon...-ish? 😄

@ghost1372
Copy link
Contributor

@bezzad any news? still open from 2021!
and we are going to 2025!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants