22using System . Collections . Generic ;
33using System . IO ;
44using System . Linq ;
5+ using System . Net . Http ;
56using System . Threading . Tasks ;
67using Cuiliang . AliyunOssSdk . Api ;
78using Cuiliang . AliyunOssSdk . Api . Bucket . List ;
@@ -24,17 +25,13 @@ namespace Cuiliang.AliyunOssSdk
2425 /// </summary>
2526 public class OssClient
2627 {
27- private RequestContext _requestContext = null ;
28+ private readonly HttpClient _client ;
29+ private readonly RequestContext _requestContext ;
2830
29- public OssClient ( OssCredential credential )
30- : this ( credential , ClientConfiguration . Default )
31+ public OssClient ( HttpClient client , RequestContext requestContext )
3132 {
32-
33- }
34-
35- public OssClient ( OssCredential credential , ClientConfiguration config )
36- {
37- _requestContext = new RequestContext ( credential , config ) ;
33+ _client = client ;
34+ _requestContext = requestContext ;
3835 }
3936
4037 /// <summary>
@@ -44,7 +41,7 @@ public OssClient(OssCredential credential, ClientConfiguration config)
4441 public async Task < OssResult < ListBucketsResult > > ListBucketsAsync ( string region )
4542 {
4643 var cmd = new ListBucketCommand ( _requestContext , region , new ListBucketsRequest ( ) ) ;
47- return await cmd . ExecuteAsync ( ) ;
44+ return await cmd . ExecuteAsync ( _client ) ;
4845 }
4946
5047 /// <summary>
@@ -58,7 +55,7 @@ public async Task<OssResult<PutObjectResult>> PutObjectAsync(BucketInfo bucket,
5855 {
5956 var cmd = new PutObjectCommand ( _requestContext , bucket , key , file , null ) ;
6057
61- return await cmd . ExecuteAsync ( ) ;
58+ return await cmd . ExecuteAsync ( _client ) ;
6259 }
6360
6461 /// <summary>
@@ -113,14 +110,14 @@ public async Task<OssResult<PutObjectResult>> PutObjectByFileNameAsync(BucketInf
113110 /// <param name="targetKey"></param>
114111 /// <param name="extraHeaders"></param>
115112 /// <returns></returns>
116- public async Task < OssResult < CopyObjectResult > > CopyObjectAsync ( BucketInfo bucket , string srcKey ,
113+ public async Task < OssResult < CopyObjectResult > > CopyObjectAsync ( BucketInfo bucket , string srcKey ,
117114 BucketInfo targetBucket ,
118- string targetKey ,
115+ string targetKey ,
119116 IDictionary < string , string > extraHeaders = null )
120117 {
121118 var cmd = new CopyObjectCommand ( _requestContext , targetBucket , targetKey , bucket , srcKey , extraHeaders ) ;
122119
123- return await cmd . ExecuteAsync ( ) ;
120+ return await cmd . ExecuteAsync ( _client ) ;
124121 }
125122
126123 /// <summary>
@@ -134,7 +131,7 @@ public async Task<OssResult<GetObjectResult>> GetObjectAsync(BucketInfo bucket,
134131 {
135132 var cmd = new GetObjectCommand ( _requestContext , bucket , key , parameters ) ;
136133
137- return await cmd . ExecuteAsync ( ) ;
134+ return await cmd . ExecuteAsync ( _client ) ;
138135 }
139136
140137 /// <summary>
@@ -150,7 +147,7 @@ public async Task<OssResult<AppentObjectResult>> AppendObject(BucketInfo bucket,
150147 {
151148 var cmd = new AppendObjectCommand ( _requestContext , bucket , key , nextAppendPosition , file ) ;
152149
153- return await cmd . ExecuteAsync ( ) ;
150+ return await cmd . ExecuteAsync ( _client ) ;
154151 }
155152
156153 /// <summary>
@@ -163,7 +160,7 @@ public async Task<OssResult<DeleteObjectResult>> DeleteObjectAsync(BucketInfo bu
163160 {
164161 var cmd = new DeleteObjectCommand ( _requestContext , bucket , key ) ;
165162
166- return await cmd . ExecuteAsync ( ) ;
163+ return await cmd . ExecuteAsync ( _client ) ;
167164 }
168165
169166 /// <summary>
@@ -178,7 +175,7 @@ public async Task<OssResult<DeleteMultipleObjectsResult>> DeleteMultipleObjectsA
178175 {
179176 var cmd = new DeleteMultipleObjectsCommand ( _requestContext , bucket , keys , quiet ) ;
180177
181- return await cmd . ExecuteAsync ( ) ;
178+ return await cmd . ExecuteAsync ( _client ) ;
182179 }
183180
184181 /// <summary>
@@ -191,7 +188,7 @@ public async Task<OssResult<DeleteMultipleObjectsResult>> DeleteMultipleObjectsA
191188 public async Task < OssResult < HeadObjectResult > > HeadObjectAsync ( BucketInfo bucket , string key , HeadObjectParams parameters )
192189 {
193190 var cmd = new HeadObjectCommand ( _requestContext , bucket , key , parameters ) ;
194- return await cmd . ExecuteAsync ( ) ;
191+ return await cmd . ExecuteAsync ( _client ) ;
195192 }
196193
197194 /// <summary>
@@ -203,7 +200,7 @@ public async Task<OssResult<HeadObjectResult>> HeadObjectAsync(BucketInfo bucket
203200 public async Task < OssResult < GetObjectMetaResult > > GetObjectMetaAsync ( BucketInfo bucket , string key )
204201 {
205202 var cmd = new GetObjectMetaCommand ( _requestContext , bucket , key ) ;
206- return await cmd . ExecuteAsync ( ) ;
203+ return await cmd . ExecuteAsync ( _client ) ;
207204 }
208205 }
209206}
0 commit comments