Permalink
Browse files

Add support for 'Range' HTTP header in WebHttpClientRequest [SPRNETRE…

…ST-28]
  • Loading branch information...
1 parent e2fdd53 commit 7cfe13b40ad5b22b08e45a94e7882730148ccc64 @bbaia bbaia committed Nov 9, 2012
@@ -468,10 +468,31 @@ protected virtual void PrepareForExecution()
}
break;
}
- //case "RANGE":
- // {
- // break;
- // }
+ case "RANGE":
+ {
+ string headerValue = this.headers[header];
+ try
+ {
+ // Supports '<range specifier>=<from>-<to>' format
+ string[] rangesSpecifiers = headerValue.Split('=');
+ string rangesSpecifier = rangesSpecifiers[0];
+ string byteRangesSpecifier = rangesSpecifiers[1];
+ int byteRangesSpecifierSeparator = byteRangesSpecifier.IndexOf('-');
+#if NET_4_0 || SILVERLIGHT
+ long from = long.Parse(byteRangesSpecifier.Substring(0, byteRangesSpecifierSeparator));
+ long to = long.Parse(byteRangesSpecifier.Substring(byteRangesSpecifierSeparator + 1));
+#else
+ int from = int.Parse(byteRangesSpecifier.Substring(0, byteRangesSpecifierSeparator));
+ int to = int.Parse(byteRangesSpecifier.Substring(byteRangesSpecifierSeparator + 1));
+#endif
+ this.httpWebRequest.AddRange(rangesSpecifier, from, to);
+ }
+ catch
+ {
+ this.httpWebRequest.Headers[header] = this.headers[header];
+ }
+ break;
+ }
case "REFERER":
{
this.httpWebRequest.Referer = this.headers[header];
@@ -158,6 +158,21 @@ public void NtlmAuthorizationOK()
}
}
+ [Test(Description="SPRNETREST-28")]
+ public void RangeHeader()
+ {
+ IClientHttpRequest request = this.CreateRequest("/echo", HttpMethod.PUT);
+
+ request.Headers.ContentLength = 0;
+ request.Headers["Range"] = "bytes=128-1024";
+
+ using (IClientHttpResponse response = request.Execute())
+ {
+ Assert.AreEqual("bytes=128-1024", response.Headers["Range"]);
+ Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "OK");
+ }
+ }
+
#region Test classes

0 comments on commit 7cfe13b

Please sign in to comment.