Skip to content

Commit 630420a

Browse files
committed
Fixes restsharp#636 - Header of 'Range' now supports a rangeSpecifier
1 parent 0b6ffe8 commit 630420a

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

RestSharp.Tests/AddRangeTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace RestSharp.Tests
2+
{
3+
using Xunit;
4+
5+
public class AddRangeTests
6+
{
7+
[Fact]
8+
public void ShouldParseOutRangeSpecifier()
9+
{
10+
var restClient = new RestClient("http://localhost");
11+
var req = new RestRequest("bob", Method.GET);
12+
13+
req.AddHeader("Range", "pages=1-2");
14+
var resp = restClient.Execute(req);
15+
}
16+
}
17+
}

RestSharp.Tests/RestSharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
</Reference>
8282
</ItemGroup>
8383
<ItemGroup>
84+
<Compile Include="AddRangeTests.cs" />
8485
<Compile Include="OAuthTests.cs" />
8586
<Compile Include="SampleClasses\EmployeeTracker.cs" />
8687
<Compile Include="SampleClasses\EnumTest.cs" />

RestSharp/Http.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,18 @@ private void ProcessResponseStream(Stream webResponseStream, HttpResponse respon
464464
#if FRAMEWORK
465465
private void AddRange(HttpWebRequest r, string range)
466466
{
467-
System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(range, "=(\\d+)-(\\d+)$");
467+
System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(range, "(\\w+)=(\\d+)-(\\d+)$");
468468

469469
if (!m.Success)
470470
{
471471
return;
472472
}
473473

474-
int from = Convert.ToInt32(m.Groups[1].Value);
475-
int to = Convert.ToInt32(m.Groups[2].Value);
474+
string rangeSpecifier = m.Groups[1].Value;
475+
int from = Convert.ToInt32(m.Groups[2].Value);
476+
int to = Convert.ToInt32(m.Groups[3].Value);
476477

477-
r.AddRange(from, to);
478+
r.AddRange(rangeSpecifier, from, to);
478479
}
479480
#endif
480481
}

0 commit comments

Comments
 (0)