@@ -68,7 +68,7 @@ public static void UpdateProxy(ProxyProperty property)
68
68
var userName when string . IsNullOrEmpty ( userName ) =>
69
69
( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") , null ) ,
70
70
_ => ( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") ,
71
- new NetworkCredential ( Proxy . UserName , Proxy . Password ) )
71
+ new NetworkCredential ( Proxy . UserName , Proxy . Password ) )
72
72
} ,
73
73
_ => ( null , null )
74
74
} ,
@@ -79,7 +79,7 @@ var userName when string.IsNullOrEmpty(userName) =>
79
79
_ => throw new ArgumentOutOfRangeException ( )
80
80
} ;
81
81
}
82
- catch ( UriFormatException e )
82
+ catch ( UriFormatException e )
83
83
{
84
84
API . ShowMsg ( "Please try again" , "Unable to parse Http Proxy" ) ;
85
85
Log . Exception ( "Flow.Launcher.Infrastructure.Http" , "Unable to parse Uri" , e ) ;
@@ -94,7 +94,7 @@ public static async Task DownloadAsync([NotNull] string url, [NotNull] string fi
94
94
if ( response . StatusCode == HttpStatusCode . OK )
95
95
{
96
96
await using var fileStream = new FileStream ( filePath , FileMode . CreateNew ) ;
97
- await response . Content . CopyToAsync ( fileStream ) ;
97
+ await response . Content . CopyToAsync ( fileStream , token ) ;
98
98
}
99
99
else
100
100
{
@@ -117,7 +117,7 @@ public static async Task DownloadAsync([NotNull] string url, [NotNull] string fi
117
117
public static Task < string > GetAsync ( [ NotNull ] string url , CancellationToken token = default )
118
118
{
119
119
Log . Debug ( $ "|Http.Get|Url <{ url } >") ;
120
- return GetAsync ( new Uri ( url . Replace ( "#" , "%23" ) ) , token ) ;
120
+ return GetAsync ( new Uri ( url ) , token ) ;
121
121
}
122
122
123
123
/// <summary>
@@ -130,36 +130,57 @@ public static async Task<string> GetAsync([NotNull] Uri url, CancellationToken t
130
130
{
131
131
Log . Debug ( $ "|Http.Get|Url <{ url } >") ;
132
132
using var response = await client . GetAsync ( url , token ) ;
133
- var content = await response . Content . ReadAsStringAsync ( ) ;
134
- if ( response . StatusCode == HttpStatusCode . OK )
135
- {
136
- return content ;
137
- }
138
- else
133
+ var content = await response . Content . ReadAsStringAsync ( token ) ;
134
+ if ( response . StatusCode != HttpStatusCode . OK )
139
135
{
140
136
throw new HttpRequestException (
141
137
$ "Error code <{ response . StatusCode } > with content <{ content } > returned from <{ url } >") ;
142
138
}
139
+
140
+ return content ;
143
141
}
144
142
145
143
/// <summary>
146
- /// Asynchrously get the result as stream from url.
144
+ /// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
145
+ /// </summary>
146
+ /// <param name="url">The Uri the request is sent to.</param>
147
+ /// <param name="completionOption">An HTTP completion option value that indicates when the operation should be considered completed.</param>
148
+ /// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
149
+ /// <returns></returns>
150
+ public static Task < Stream > GetStreamAsync ( [ NotNull ] string url ,
151
+ CancellationToken token = default ) => GetStreamAsync ( new Uri ( url ) , token ) ;
152
+
153
+
154
+ /// <summary>
155
+ /// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
147
156
/// </summary>
148
157
/// <param name="url"></param>
158
+ /// <param name="token"></param>
149
159
/// <returns></returns>
150
- public static async Task < Stream > GetStreamAsync ( [ NotNull ] string url , CancellationToken token = default )
160
+ public static async Task < Stream > GetStreamAsync ( [ NotNull ] Uri url ,
161
+ CancellationToken token = default )
162
+ {
163
+ Log . Debug ( $ "|Http.Get|Url <{ url } >") ;
164
+ return await client . GetStreamAsync ( url , token ) ;
165
+ }
166
+
167
+ public static async Task < HttpResponseMessage > GetResponseAsync ( string url , HttpCompletionOption completionOption = HttpCompletionOption . ResponseContentRead ,
168
+ CancellationToken token = default )
169
+ => await GetResponseAsync ( new Uri ( url ) , completionOption , token ) ;
170
+
171
+ public static async Task < HttpResponseMessage > GetResponseAsync ( [ NotNull ] Uri url , HttpCompletionOption completionOption = HttpCompletionOption . ResponseContentRead ,
172
+ CancellationToken token = default )
151
173
{
152
174
Log . Debug ( $ "|Http.Get|Url <{ url } >") ;
153
- var response = await client . GetAsync ( url , HttpCompletionOption . ResponseHeadersRead , token ) ;
154
- return await response . Content . ReadAsStreamAsync ( ) ;
175
+ return await client . GetAsync ( url , completionOption , token ) ;
155
176
}
156
177
157
178
/// <summary>
158
179
/// Asynchrously send an HTTP request.
159
180
/// </summary>
160
- public static async Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken token = default )
181
+ public static async Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , HttpCompletionOption completionOption = HttpCompletionOption . ResponseContentRead , CancellationToken token = default )
161
182
{
162
- return await client . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , token ) ;
183
+ return await client . SendAsync ( request , completionOption , token ) ;
163
184
}
164
185
}
165
186
}
0 commit comments