Skip to content

Commit e728dde

Browse files
committed
remove http request expect header
improve the qiniu exception fix the http code
1 parent 587d148 commit e728dde

14 files changed

+217
-157
lines changed

src/Qiniu/CDN/CdnManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public RefreshResult RefreshUrlsAndDirs(string[] urls, string[] dirs)
8585
}
8686
sb.AppendLine();
8787

88-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
88+
result.RefCode = (int)HttpCode.INVALID_ARGUMENT;
8989
result.RefText += sb.ToString();
9090
}
9191

@@ -145,7 +145,7 @@ public PrefetchResult PrefetchUrls(string[] urls)
145145
}
146146
sb.AppendLine();
147147

148-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
148+
result.RefCode = (int)HttpCode.INVALID_ARGUMENT;
149149
result.RefText += sb.ToString();
150150
}
151151

@@ -192,7 +192,7 @@ public BandwidthResult GetBandwidthData(string[] domains, string startDate, stri
192192
}
193193
sb.AppendLine();
194194

195-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
195+
result.RefCode = (int)HttpCode.INVALID_ARGUMENT;
196196
result.RefText += sb.ToString();
197197
}
198198

@@ -239,7 +239,7 @@ public FluxResult GetFluxData(string[] domains, string startDate, string endDate
239239
}
240240
sb.AppendLine();
241241

242-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
242+
result.RefCode = (int)HttpCode.INVALID_ARGUMENT;
243243
result.RefText += sb.ToString();
244244
}
245245

@@ -281,7 +281,7 @@ public LogListResult GetCdnLogList(string[] domains, string day)
281281
}
282282
sb.AppendLine();
283283

284-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
284+
result.RefCode = (int)HttpCode.INVALID_ARGUMENT;
285285
result.RefText += sb.ToString();
286286
}
287287

src/Qiniu/Http/HttpCode.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public enum HttpCode
8080
/// <summary>
8181
/// 服务端操作失败
8282
/// </summary>
83-
SERVER_OPERATION_FAILED = 599,
83+
SERVER_OPERATION_FAILED = 599,
8484

8585
/// <summary>
8686
/// 资源内容被修改
@@ -124,32 +124,42 @@ public enum HttpCode
124124
/// <summary>
125125
/// 自定义HTTP状态码 (默认值)
126126
/// </summary>
127-
USER_UNDEF = -256,
127+
USER_UNDEF = 0,
128128

129129
/// <summary>
130130
/// 自定义HTTP状态码 (用户取消)
131131
/// </summary>
132-
USER_CANCELED = -255,
132+
USER_CANCELED = -2,
133133

134134
/// <summary>
135135
/// 自定义HTTP状态码 (用户暂停)
136136
/// </summary>
137-
USER_PAUSED = -254,
137+
USER_PAUSED = 1,
138138

139139
/// <summary>
140140
/// 自定义HTTP状态码 (用户继续)
141141
/// </summary>
142-
USER_RESUMED = -253,
142+
USER_RESUMED = 2,
143143

144144
/// <summary>
145145
/// 自定义HTTP状态码 (需要重试)
146146
/// </summary>
147-
USER_NEED_RETRY = -252,
147+
USER_NEED_RETRY = 3,
148148

149149
/// <summary>
150150
/// 自定义HTTP状态码 (异常或错误)
151151
/// </summary>
152-
USER_EXCEPTION = -252,
152+
INVALID_ARGUMENT = -4,
153+
154+
/// <summary>
155+
/// 自定义HTTP状态码(文件不合法)
156+
/// </summary>
157+
INVALID_FILE = -3,
158+
159+
/// <summary>
160+
/// 自定义HTTP状态码(凭证不合法)
161+
/// </summary>
162+
INVALID_TOKEN = -5,
153163

154164
#endregion _USR_
155165

src/Qiniu/Http/HttpManager.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public HttpResult Get(string url, string token, bool binaryMode = false)
8282
}
8383
wReq.UserAgent = userAgent;
8484
wReq.AllowAutoRedirect = allowAutoRedirect;
85+
wReq.ServicePoint.Expect100Continue = false;
8586

8687
HttpWebResponse wResp = wReq.GetResponse() as HttpWebResponse;
8788

@@ -149,7 +150,7 @@ public HttpResult Get(string url, string token, bool binaryMode = false)
149150
}
150151
sb.AppendLine();
151152

152-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
153+
result.RefCode = (int)HttpCode.USER_UNDEF;
153154
result.RefText += sb.ToString();
154155
}
155156
finally
@@ -186,6 +187,7 @@ public HttpResult Post(string url, string token, bool binaryMode = false)
186187
}
187188
wReq.UserAgent = userAgent;
188189
wReq.AllowAutoRedirect = allowAutoRedirect;
190+
wReq.ServicePoint.Expect100Continue = false;
189191

190192
HttpWebResponse wResp = wReq.GetResponse() as HttpWebResponse;
191193

@@ -253,7 +255,7 @@ public HttpResult Post(string url, string token, bool binaryMode = false)
253255
}
254256
sb.AppendLine();
255257

256-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
258+
result.RefCode = (int)HttpCode.USER_UNDEF;
257259
result.RefText += sb.ToString();
258260
}
259261
finally
@@ -292,6 +294,7 @@ public HttpResult PostData(string url, byte[] data, string token, bool binaryMod
292294
wReq.ContentType = ContentType.APPLICATION_OCTET_STREAM;
293295
wReq.UserAgent = userAgent;
294296
wReq.AllowAutoRedirect = allowAutoRedirect;
297+
wReq.ServicePoint.Expect100Continue = false;
295298

296299
if (data != null)
297300
{
@@ -369,7 +372,7 @@ public HttpResult PostData(string url, byte[] data, string token, bool binaryMod
369372
}
370373
sb.AppendLine();
371374

372-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
375+
result.RefCode = (int)HttpCode.USER_UNDEF;
373376
result.RefText += sb.ToString();
374377
}
375378
finally
@@ -409,6 +412,7 @@ public HttpResult PostData(string url, byte[] data, string mimeType, string toke
409412
wReq.ContentType = mimeType;
410413
wReq.UserAgent = userAgent;
411414
wReq.AllowAutoRedirect = allowAutoRedirect;
415+
wReq.ServicePoint.Expect100Continue = false;
412416

413417
if (data != null)
414418
{
@@ -486,7 +490,7 @@ public HttpResult PostData(string url, byte[] data, string mimeType, string toke
486490
}
487491
sb.AppendLine();
488492

489-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
493+
result.RefCode = (int)HttpCode.USER_UNDEF;
490494
result.RefText += sb.ToString();
491495
}
492496
finally
@@ -525,6 +529,7 @@ public HttpResult PostJson(string url, string data, string token, bool binaryMod
525529
wReq.ContentType = ContentType.APPLICATION_JSON;
526530
wReq.UserAgent = userAgent;
527531
wReq.AllowAutoRedirect = allowAutoRedirect;
532+
wReq.ServicePoint.Expect100Continue = false;
528533

529534
if (data != null)
530535
{
@@ -602,7 +607,7 @@ public HttpResult PostJson(string url, string data, string token, bool binaryMod
602607
}
603608
sb.AppendLine();
604609

605-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
610+
result.RefCode = (int)HttpCode.USER_UNDEF;
606611
result.RefText += sb.ToString();
607612
}
608613
finally
@@ -641,6 +646,7 @@ public HttpResult PostText(string url, string data, string token, bool binaryMod
641646
wReq.ContentType = ContentType.TEXT_PLAIN;
642647
wReq.UserAgent = userAgent;
643648
wReq.AllowAutoRedirect = allowAutoRedirect;
649+
wReq.ServicePoint.Expect100Continue = false;
644650

645651
if (data != null)
646652
{
@@ -718,7 +724,7 @@ public HttpResult PostText(string url, string data, string token, bool binaryMod
718724
}
719725
sb.AppendLine();
720726

721-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
727+
result.RefCode = (int)HttpCode.USER_UNDEF;
722728
result.RefText += sb.ToString();
723729
}
724730
finally
@@ -757,6 +763,7 @@ public HttpResult PostForm(string url, Dictionary<string, string> kvData, string
757763
wReq.ContentType = ContentType.WWW_FORM_URLENC;
758764
wReq.UserAgent = userAgent;
759765
wReq.AllowAutoRedirect = allowAutoRedirect;
766+
wReq.ServicePoint.Expect100Continue = false;
760767

761768
if (kvData != null)
762769
{
@@ -840,7 +847,7 @@ public HttpResult PostForm(string url, Dictionary<string, string> kvData, string
840847
}
841848
sb.AppendLine();
842849

843-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
850+
result.RefCode = (int)HttpCode.USER_UNDEF;
844851
result.RefText += sb.ToString();
845852
}
846853
finally
@@ -879,6 +886,7 @@ public HttpResult PostForm(string url, string data, string token, bool binaryMod
879886
wReq.ContentType = ContentType.WWW_FORM_URLENC;
880887
wReq.UserAgent = userAgent;
881888
wReq.AllowAutoRedirect = allowAutoRedirect;
889+
wReq.ServicePoint.Expect100Continue = false;
882890

883891
if (!string.IsNullOrEmpty(data))
884892
{
@@ -956,7 +964,7 @@ public HttpResult PostForm(string url, string data, string token, bool binaryMod
956964
}
957965
sb.AppendLine();
958966

959-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
967+
result.RefCode = (int)HttpCode.USER_UNDEF;
960968
result.RefText += sb.ToString();
961969
}
962970
finally
@@ -995,6 +1003,7 @@ public HttpResult PostForm(string url, byte[] data, string token, bool binaryMod
9951003
wReq.ContentType = ContentType.WWW_FORM_URLENC;
9961004
wReq.UserAgent = userAgent;
9971005
wReq.AllowAutoRedirect = allowAutoRedirect;
1006+
wReq.ServicePoint.Expect100Continue = false;
9981007

9991008
if (data != null)
10001009
{
@@ -1072,7 +1081,7 @@ public HttpResult PostForm(string url, byte[] data, string token, bool binaryMod
10721081
}
10731082
sb.AppendLine();
10741083

1075-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
1084+
result.RefCode = (int)HttpCode.USER_UNDEF;
10761085
result.RefText += sb.ToString();
10771086
}
10781087
finally
@@ -1112,6 +1121,7 @@ public HttpResult PostMultipart(string url, byte[] data, string boundary, string
11121121
wReq.ContentType = string.Format("{0}; boundary={1}", ContentType.MULTIPART_FORM_DATA, boundary);
11131122
wReq.UserAgent = userAgent;
11141123
wReq.AllowAutoRedirect = allowAutoRedirect;
1124+
wReq.ServicePoint.Expect100Continue = false;
11151125

11161126
wReq.AllowWriteStreamBuffering = true;
11171127
using (Stream sReq = wReq.GetRequestStream())
@@ -1186,7 +1196,7 @@ public HttpResult PostMultipart(string url, byte[] data, string boundary, string
11861196
}
11871197
sb.AppendLine();
11881198

1189-
result.RefCode = (int)HttpCode.USER_EXCEPTION;
1199+
result.RefCode = (int)HttpCode.USER_UNDEF;
11901200
result.RefText += sb.ToString();
11911201
}
11921202
finally

src/Qiniu/Http/HttpResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public override string ToString()
128128
/// 非法上传凭证错误
129129
/// </summary>
130130
public static HttpResult InvalidToken = new HttpResult {
131-
Code=(int)HttpCode.USER_CANCELED,
131+
Code=(int)HttpCode.INVALID_TOKEN,
132132
Text="invalid uptoken"
133133
};
134134

@@ -137,7 +137,7 @@ public override string ToString()
137137
/// </summary>
138138
public static HttpResult InvalidFile = new HttpResult
139139
{
140-
Code = (int)HttpCode.USER_CANCELED,
140+
Code = (int)HttpCode.INVALID_FILE,
141141
Text = "invalid file"
142142
};
143143
}

src/Qiniu/Qiniu.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<Compile Include="Storage\PfopInfo.cs" />
8989
<Compile Include="Storage\PrefopResult.cs" />
9090
<Compile Include="Storage\PutExtra.cs" />
91+
<Compile Include="Storage\QiniuException.cs" />
9192
<Compile Include="Storage\Zone.cs" />
9293
<Compile Include="Storage\ZoneHelper.cs" />
9394
<Compile Include="Storage\ZoneInfo.cs" />
@@ -158,7 +159,7 @@
158159
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
159160
<PropertyGroup>
160161
<PostBuildEvent>
161-
</PostBuildEvent>
162+
</PostBuildEvent>
162163
</PropertyGroup>
163164
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
164165
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)