-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Remove WebRequest from SoundPlayer #65854
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,7 @@ | |||||
using System.Diagnostics; | ||||||
using System.Diagnostics.CodeAnalysis; | ||||||
using System.IO; | ||||||
using System.Net; | ||||||
using System.Net.Http; | ||||||
using System.Runtime.InteropServices; | ||||||
using System.Runtime.Serialization; | ||||||
using System.Threading; | ||||||
|
@@ -22,6 +22,7 @@ public class SoundPlayer : Component, ISerializable | |||||
private Uri? _uri; | ||||||
private string _soundLocation = string.Empty; | ||||||
private int _loadTimeout = DefaultLoadTimeout; | ||||||
private HttpClient _httpClient = new HttpClient(); | ||||||
|
||||||
// used to lock all synchronous calls to the SoundPlayer object | ||||||
private readonly ManualResetEvent _semaphore = new ManualResetEvent(true); | ||||||
|
@@ -261,16 +262,7 @@ private void LoadSync() | |||||
// setup the http stream | ||||||
if (_uri != null && !_uri.IsFile && _stream == null) | ||||||
{ | ||||||
#pragma warning disable SYSLIB0014 // WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. | ||||||
WebRequest webRequest = WebRequest.Create(_uri); | ||||||
#pragma warning restore SYSLIB0014 | ||||||
webRequest.Timeout = LoadTimeout; | ||||||
|
||||||
WebResponse webResponse; | ||||||
webResponse = webRequest.GetResponse(); | ||||||
|
||||||
// now get the stream | ||||||
_stream = webResponse.GetResponseStream(); | ||||||
_stream = _httpClient.GetStreamAsync(_uri).Result; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Since this function is synchronous, I'm wondering if we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
} | ||||||
|
||||||
// DO NOT assert - NRE is expected for null stream | ||||||
|
@@ -486,14 +478,7 @@ private async Task CopyStreamAsync(CancellationToken cancellationToken) | |||||
// setup the http stream | ||||||
if (_uri != null && !_uri.IsFile && _stream == null) | ||||||
{ | ||||||
#pragma warning disable SYSLIB0014 // WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. | ||||||
WebRequest webRequest = WebRequest.Create(_uri); | ||||||
#pragma warning restore SYSLIB0014 | ||||||
using (cancellationToken.Register(r => ((WebRequest)r!).Abort(), webRequest)) | ||||||
{ | ||||||
WebResponse webResponse = await webRequest.GetResponseAsync().ConfigureAwait(false); | ||||||
_stream = webResponse.GetResponseStream(); | ||||||
} | ||||||
_stream = _httpClient.GetStreamAsync(_uri, cancellationToken).Result; | ||||||
} | ||||||
|
||||||
_streamData = new byte[BlockSize]; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we are loosing
LoadTimeout
without replacement. We may consider something like:and pass it to
GetStreamAsync