@@ -22,10 +22,11 @@ public class BucketManager
2222 /// </summary>
2323 /// <param name="mac"></param>
2424 /// <param name="config"></param>
25- public BucketManager ( Mac mac , Config config )
25+ /// <param name="authOptions"></param>
26+ public BucketManager ( Mac mac , Config config , AuthOptions authOptions = null )
2627 {
2728 this . mac = mac ;
28- this . auth = new Auth ( mac ) ;
29+ this . auth = new Auth ( mac , authOptions ) ;
2930 this . httpManager = new HttpManager ( ) ;
3031 this . config = config ;
3132 }
@@ -45,13 +46,8 @@ public StatResult Stat(string bucket, string key)
4546 {
4647 string statUrl = string . Format ( "{0}{1}" , this . config . RsHost ( this . mac . AccessKey , bucket ) ,
4748 StatOp ( bucket , key ) ) ;
48- StringDictionary headers = new StringDictionary
49- {
50- { "Content-Type" , ContentType . WWW_FORM_URLENC }
51- } ;
52- string token = auth . CreateManageTokenV2 ( "GET" , statUrl , headers ) ;
5349
54- HttpResult hr = httpManager . Get ( statUrl , headers , token ) ;
50+ HttpResult hr = httpManager . Get ( statUrl , null , auth ) ;
5551 result . Shadow ( hr ) ;
5652 }
5753 catch ( QiniuException ex )
@@ -94,13 +90,8 @@ public BucketsResult Buckets(bool shared)
9490 sharedStr = "true" ;
9591 }
9692 string bucketsUrl = string . Format ( "{0}/buckets?shared={1}" , rsHost , sharedStr ) ;
97- StringDictionary headers = new StringDictionary
98- {
99- { "Content-Type" , ContentType . WWW_FORM_URLENC }
100- } ;
101- string token = auth . CreateManageTokenV2 ( "GET" , bucketsUrl , headers ) ;
10293
103- HttpResult hr = httpManager . Get ( bucketsUrl , headers , token ) ;
94+ HttpResult hr = httpManager . Get ( bucketsUrl , null , auth ) ;
10495 result . Shadow ( hr ) ;
10596 }
10697 catch ( QiniuException ex )
@@ -139,13 +130,8 @@ public HttpResult Delete(string bucket, string key)
139130 {
140131 string deleteUrl = string . Format ( "{0}{1}" , this . config . RsHost ( this . mac . AccessKey , bucket ) ,
141132 DeleteOp ( bucket , key ) ) ;
142- StringDictionary headers = new StringDictionary
143- {
144- { "Content-Type" , ContentType . WWW_FORM_URLENC }
145- } ;
146- string token = auth . CreateManageTokenV2 ( "POST" , deleteUrl , headers ) ;
147133
148- result = httpManager . Post ( deleteUrl , headers , token ) ;
134+ result = httpManager . Post ( deleteUrl , null , auth ) ;
149135 }
150136 catch ( QiniuException ex )
151137 {
@@ -198,13 +184,8 @@ public HttpResult Copy(string srcBucket, string srcKey, string dstBucket, string
198184 {
199185 string copyUrl = string . Format ( "{0}{1}" , this . config . RsHost ( this . mac . AccessKey , srcBucket ) ,
200186 CopyOp ( srcBucket , srcKey , dstBucket , dstKey , force ) ) ;
201- StringDictionary headers = new StringDictionary
202- {
203- { "Content-Type" , ContentType . WWW_FORM_URLENC }
204- } ;
205- string token = auth . CreateManageTokenV2 ( "POST" , copyUrl , headers ) ;
206187
207- result = httpManager . Post ( copyUrl , headers , token ) ;
188+ result = httpManager . Post ( copyUrl , null , auth ) ;
208189 }
209190 catch ( QiniuException ex )
210191 {
@@ -257,13 +238,8 @@ public HttpResult Move(string srcBucket, string srcKey, string dstBucket, string
257238 {
258239 string moveUrl = string . Format ( "{0}{1}" , this . config . RsHost ( this . mac . AccessKey , srcBucket ) ,
259240 MoveOp ( srcBucket , srcKey , dstBucket , dstKey , force ) ) ;
260- StringDictionary headers = new StringDictionary
261- {
262- { "Content-Type" , ContentType . WWW_FORM_URLENC }
263- } ;
264- string token = auth . CreateManageTokenV2 ( "POST" , moveUrl , headers ) ;
265241
266- result = httpManager . Post ( moveUrl , headers , token ) ;
242+ result = httpManager . Post ( moveUrl , null , auth ) ;
267243 }
268244 catch ( QiniuException ex )
269245 {
@@ -301,12 +277,8 @@ public HttpResult ChangeMime(string bucket, string key, string mimeType)
301277 {
302278 string chgmUrl = string . Format ( "{0}{1}" , this . config . RsHost ( this . mac . AccessKey , bucket ) ,
303279 ChangeMimeOp ( bucket , key , mimeType ) ) ;
304- StringDictionary headers = new StringDictionary
305- {
306- { "Content-Type" , ContentType . WWW_FORM_URLENC }
307- } ;
308- string token = auth . CreateManageTokenV2 ( "POST" , chgmUrl , headers ) ;
309- result = httpManager . Post ( chgmUrl , headers , token ) ;
280+
281+ result = httpManager . Post ( chgmUrl , null , auth ) ;
310282 }
311283 catch ( QiniuException ex )
312284 {
@@ -344,12 +316,8 @@ public HttpResult ChangeType(string bucket, string key, int fileType)
344316 {
345317 string chtypeUrl = string . Format ( "{0}{1}" , this . config . RsHost ( this . mac . AccessKey , bucket ) ,
346318 ChangeTypeOp ( bucket , key , fileType ) ) ;
347- StringDictionary headers = new StringDictionary
348- {
349- { "Content-Type" , ContentType . WWW_FORM_URLENC }
350- } ;
351- string token = auth . CreateManageTokenV2 ( "POST" , chtypeUrl , headers ) ;
352- result = httpManager . Post ( chtypeUrl , headers , token ) ;
319+
320+ result = httpManager . Post ( chtypeUrl , null , auth ) ;
353321 }
354322 catch ( QiniuException ex )
355323 {
@@ -381,12 +349,8 @@ public HttpResult RestoreAr(string bucket, string key, int freezeAfterDays)
381349 string restoreUrl = string . Format ( "{0}{1}" ,
382350 this . config . RsHost ( this . mac . AccessKey , bucket ) ,
383351 RestoreArOp ( bucket , key , freezeAfterDays ) ) ;
384- StringDictionary headers = new StringDictionary
385- {
386- { "Content-Type" , ContentType . WWW_FORM_URLENC }
387- } ;
388- string token = auth . CreateManageTokenV2 ( "POST" , restoreUrl , headers ) ;
389- result = httpManager . Post ( restoreUrl , headers , token ) ;
352+
353+ result = httpManager . Post ( restoreUrl , null , auth ) ;
390354 }
391355 catch ( QiniuException ex )
392356 {
@@ -423,17 +387,8 @@ private BatchResult Batch(string batchOps)
423387 string scheme = this . config . UseHttps ? "https://" : "http://" ;
424388 string rsHost = string . Format ( "{0}{1}" , scheme , Config . DefaultRsHost ) ;
425389 string batchUrl = rsHost + "/batch" ;
426- string token = auth . CreateManageTokenV2 (
427- "POST" ,
428- batchUrl ,
429- new StringDictionary
430- {
431- { "Content-Type" , ContentType . WWW_FORM_URLENC }
432- } ,
433- batchOps ) ;
434- byte [ ] data = Encoding . UTF8 . GetBytes ( batchOps ) ;
435-
436- HttpResult hr = httpManager . PostForm ( batchUrl , data , token ) ;
390+
391+ HttpResult hr = httpManager . PostForm ( batchUrl , null , batchOps , auth ) ;
437392 result . Shadow ( hr ) ;
438393 }
439394 catch ( QiniuException ex )
@@ -489,13 +444,8 @@ public FetchResult Fetch(string resUrl, string bucket, string key)
489444 {
490445 string fetchUrl = string . Format ( "{0}{1}" , this . config . IovipHost ( this . mac . AccessKey , bucket ) ,
491446 FetchOp ( resUrl , bucket , key ) ) ;
492- StringDictionary headers = new StringDictionary
493- {
494- { "Content-Type" , ContentType . WWW_FORM_URLENC }
495- } ;
496- string token = auth . CreateManageTokenV2 ( "POST" , fetchUrl , headers ) ;
497447
498- HttpResult httpResult = httpManager . Post ( fetchUrl , headers , token ) ;
448+ HttpResult httpResult = httpManager . Post ( fetchUrl , null , auth ) ;
499449 result . Shadow ( httpResult ) ;
500450 }
501451 catch ( QiniuException ex )
@@ -532,13 +482,8 @@ public HttpResult Prefetch(string bucket, string key)
532482 try
533483 {
534484 string prefetchUrl = this . config . IovipHost ( this . mac . AccessKey , bucket ) + PrefetchOp ( bucket , key ) ;
535- StringDictionary headers = new StringDictionary
536- {
537- { "Content-Type" , ContentType . WWW_FORM_URLENC }
538- } ;
539- string token = auth . CreateManageTokenV2 ( "POST" , prefetchUrl , headers ) ;
540485
541- result = httpManager . Post ( prefetchUrl , headers , token ) ;
486+ result = httpManager . Post ( prefetchUrl , null , auth ) ;
542487 }
543488 catch ( QiniuException ex )
544489 {
@@ -576,17 +521,8 @@ public DomainsResult Domains(string bucket)
576521 string rsHost = string . Format ( "{0}{1}" , scheme , Config . DefaultApiHost ) ;
577522 string domainsUrl = string . Format ( "{0}{1}" , rsHost , "/v6/domain/list" ) ;
578523 string body = string . Format ( "tbl={0}" , bucket ) ;
579- string token = auth . CreateManageTokenV2 (
580- "POST" ,
581- domainsUrl ,
582- new StringDictionary
583- {
584- { "Content-Type" , ContentType . WWW_FORM_URLENC }
585- } ,
586- body ) ;
587- byte [ ] data = Encoding . UTF8 . GetBytes ( body ) ;
588-
589- HttpResult hr = httpManager . PostForm ( domainsUrl , data , token ) ;
524+
525+ HttpResult hr = httpManager . PostForm ( domainsUrl , null , body , auth ) ;
590526 result . Shadow ( hr ) ;
591527 }
592528 catch ( QiniuException ex )
@@ -671,13 +607,8 @@ public ListResult ListFiles(string bucket, string prefix, string marker, int lim
671607 }
672608
673609 string listUrl = string . Format ( "{0}{1}" , this . config . RsfHost ( this . mac . AccessKey , bucket ) , sb . ToString ( ) ) ;
674- StringDictionary headers = new StringDictionary
675- {
676- { "Content-Type" , ContentType . WWW_FORM_URLENC }
677- } ;
678- string token = auth . CreateManageTokenV2 ( "POST" , listUrl , headers ) ;
679610
680- HttpResult hr = httpManager . Post ( listUrl , headers , token ) ;
611+ HttpResult hr = httpManager . Post ( listUrl , null , auth ) ;
681612 result . Shadow ( hr ) ;
682613 }
683614 catch ( QiniuException ex )
@@ -716,12 +647,7 @@ public HttpResult DeleteAfterDays(string bucket, string key, int deleteAfterDays
716647 {
717648 string updateUrl = string . Format ( "{0}{1}" , this . config . RsHost ( this . mac . AccessKey , bucket ) ,
718649 DeleteAfterDaysOp ( bucket , key , deleteAfterDays ) ) ;
719- StringDictionary headers = new StringDictionary
720- {
721- { "Content-Type" , ContentType . WWW_FORM_URLENC }
722- } ;
723- string token = auth . CreateManageTokenV2 ( "POST" , updateUrl , headers ) ;
724- result = httpManager . Post ( updateUrl , headers , token ) ;
650+ result = httpManager . Post ( updateUrl , null , auth ) ;
725651 }
726652 catch ( QiniuException ex )
727653 {
0 commit comments