Skip to content

Commit 812c344

Browse files
Move the instantiation of RequestContent after calling the Authenticator (#2062)
* Move the instantiation of RequestContent after calling the Authenticator * Add auth tests * Fix null content issues with .NET Framework
1 parent 794348e commit 812c344

File tree

75 files changed

+441
-573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+441
-573
lines changed

RestSharp.sln

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSharp.Tests.Serializers
2929
EndProject
3030
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSharp.Serializers.Xml", "src\RestSharp.Serializers.Xml\RestSharp.Serializers.Xml.csproj", "{4A35B1C5-520D-4267-BA70-2DCEAC0A5662}"
3131
EndProject
32-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSharp.Tests.Legacy", "test\RestSharp.Tests.Legacy\RestSharp.Tests.Legacy.csproj", "{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}"
33-
EndProject
3432
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSharp.Serializers.CsvHelper", "src\RestSharp.Serializers.CsvHelper\RestSharp.Serializers.CsvHelper.csproj", "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"
3533
EndProject
3634
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSharp.Tests.Serializers.Csv", "test\RestSharp.Tests.Serializers.Csv\RestSharp.Tests.Serializers.Csv.csproj", "{E6D94FFD-7811-40BE-ABC4-6D6AB41F0060}"
@@ -358,36 +356,6 @@ Global
358356
{4A35B1C5-520D-4267-BA70-2DCEAC0A5662}.Release|x64.Build.0 = Release|Any CPU
359357
{4A35B1C5-520D-4267-BA70-2DCEAC0A5662}.Release|x86.ActiveCfg = Release|Any CPU
360358
{4A35B1C5-520D-4267-BA70-2DCEAC0A5662}.Release|x86.Build.0 = Release|Any CPU
361-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|Any CPU.ActiveCfg = Debug|Any CPU
362-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|Any CPU.Build.0 = Debug|Any CPU
363-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|ARM.ActiveCfg = Debug|Any CPU
364-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|ARM.Build.0 = Debug|Any CPU
365-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|Mixed Platforms.ActiveCfg = Debug|Any CPU
366-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|Mixed Platforms.Build.0 = Debug|Any CPU
367-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|x64.ActiveCfg = Debug|Any CPU
368-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|x64.Build.0 = Debug|Any CPU
369-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|x86.ActiveCfg = Debug|Any CPU
370-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug.Appveyor|x86.Build.0 = Debug|Any CPU
371-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
372-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
373-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|ARM.ActiveCfg = Debug|Any CPU
374-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|ARM.Build.0 = Debug|Any CPU
375-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
376-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
377-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|x64.ActiveCfg = Debug|Any CPU
378-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|x64.Build.0 = Debug|Any CPU
379-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|x86.ActiveCfg = Debug|Any CPU
380-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Debug|x86.Build.0 = Debug|Any CPU
381-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
382-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|Any CPU.Build.0 = Release|Any CPU
383-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|ARM.ActiveCfg = Release|Any CPU
384-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|ARM.Build.0 = Release|Any CPU
385-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
386-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|Mixed Platforms.Build.0 = Release|Any CPU
387-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|x64.ActiveCfg = Release|Any CPU
388-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|x64.Build.0 = Release|Any CPU
389-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|x86.ActiveCfg = Release|Any CPU
390-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0}.Release|x86.Build.0 = Release|Any CPU
391359
{2150E333-8FDC-42A3-9474-1A3956D46DE8}.Debug.Appveyor|Any CPU.ActiveCfg = Debug|Any CPU
392360
{2150E333-8FDC-42A3-9474-1A3956D46DE8}.Debug.Appveyor|Any CPU.Build.0 = Debug|Any CPU
393361
{2150E333-8FDC-42A3-9474-1A3956D46DE8}.Debug.Appveyor|ARM.ActiveCfg = Debug|Any CPU
@@ -492,7 +460,6 @@ Global
492460
{6D7D1D60-4473-4C52-800C-9B892C6640A5} = {9051DDA0-E563-45D5-9504-085EBAACF469}
493461
{E6D94C12-9AD7-46E6-AB62-3676F25FDE51} = {9051DDA0-E563-45D5-9504-085EBAACF469}
494462
{4A35B1C5-520D-4267-BA70-2DCEAC0A5662} = {8C7B43EB-2F93-483C-B433-E28F9386AD67}
495-
{5A8A5BBE-28DA-4C89-B393-BE39A96E8DC0} = {9051DDA0-E563-45D5-9504-085EBAACF469}
496463
{2150E333-8FDC-42A3-9474-1A3956D46DE8} = {8C7B43EB-2F93-483C-B433-E28F9386AD67}
497464
{E6D94FFD-7811-40BE-ABC4-6D6AB41F0060} = {9051DDA0-E563-45D5-9504-085EBAACF469}
498465
{FE778406-ADCF-45A1-B775-A054B55BFC50} = {55B8F371-B2BA-4DEE-AB98-5BAB8A21B1C2}

RestSharp.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
103103
See the License for the specific language governing permissions and
104104
limitations under the License.
105105
</s:String>
106+
<s:Boolean x:Key="/Default/UserDictionary/Words/=usings/@EntryIndexedValue">True</s:Boolean>
106107
<s:Boolean x:Key="/Default/UserDictionary/Words/=Zimarev/@EntryIndexedValue">True</s:Boolean>
107108
</wpf:ResourceDictionary>

benchmarks/RestSharp.Benchmarks/Requests/AddObjectToRequestParametersBenchmarks.cs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,30 @@
22
using BenchmarkDotNet.Order;
33
using System.Globalization;
44

5-
namespace RestSharp.Benchmarks.Requests {
6-
[MemoryDiagnoser, RankColumn, Orderer(SummaryOrderPolicy.FastestToSlowest)]
7-
public partial class AddObjectToRequestParametersBenchmarks {
8-
Data _data;
5+
namespace RestSharp.Benchmarks.Requests;
96

10-
[GlobalSetup]
11-
public void GlobalSetup() {
12-
const string @string = "random string";
13-
const int arraySize = 10_000;
14-
var strings = new string[arraySize];
15-
Array.Fill(strings, @string);
16-
var ints = new int[arraySize];
17-
Array.Fill(ints, int.MaxValue);
7+
[MemoryDiagnoser, RankColumn, Orderer(SummaryOrderPolicy.FastestToSlowest)]
8+
public class AddObjectToRequestParametersBenchmarks {
9+
Data _data;
1810

19-
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
20-
var dateTime = DateTime.Parse("01/01/2013 03:03:12");
11+
[GlobalSetup]
12+
public void GlobalSetup() {
13+
const string @string = "random string";
14+
const int arraySize = 10_000;
15+
var strings = new string[arraySize];
16+
Array.Fill(strings, @string);
17+
var ints = new int[arraySize];
18+
Array.Fill(ints, int.MaxValue);
2119

22-
_data = new Data(@string, int.MaxValue, strings, ints, dateTime, strings);
23-
}
20+
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
21+
var dateTime = DateTime.Parse("01/01/2013 03:03:12");
2422

25-
[Benchmark(Baseline = true)]
26-
public void AddObject() => new RestRequest().AddObject(_data);
23+
_data = new Data(@string, int.MaxValue, strings, ints, dateTime, strings);
24+
}
2725

28-
[Benchmark]
29-
public void AddObjectStatic() => new RestRequest().AddObjectStatic(_data);
26+
[Benchmark(Baseline = true)]
27+
public void AddObject() => new RestRequest().AddObject(_data);
3028

31-
}
32-
}
29+
[Benchmark]
30+
public void AddObjectStatic() => new RestRequest().AddObjectStatic(_data);
31+
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace RestSharp.Benchmarks.Requests {
2-
sealed record Data(
3-
string String,
4-
[property: RequestProperty(Name = "PropertyName")] int Int32,
5-
string[] Strings,
6-
[property: RequestProperty(Format = "00000", ArrayQueryType = RequestArrayQueryType.ArrayParameters)] int[] Ints,
7-
[property: RequestProperty(Name = "DateTime", Format = "hh:mm tt")] object DateTime,
8-
object StringArray);
9-
}
1+
namespace RestSharp.Benchmarks.Requests;
2+
3+
sealed record Data(
4+
string String,
5+
[property: RequestProperty(Name = "PropertyName")] int Int32,
6+
string[] Strings,
7+
[property: RequestProperty(Format = "00000", ArrayQueryType = RequestArrayQueryType.ArrayParameters)] int[] Ints,
8+
[property: RequestProperty(Name = "DateTime", Format = "hh:mm tt")] object DateTime,
9+
object StringArray);

benchmarks/RestSharp.Benchmarks/Serializers/JsonNetSerializeBenchmarks.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
using BenchmarkDotNet.Attributes;
33
using RestSharp.Serializers.NewtonsoftJson;
44

5-
namespace RestSharp.Benchmarks.Serializers
5+
namespace RestSharp.Benchmarks.Serializers;
6+
7+
[MemoryDiagnoser]
8+
public class JsonNetSerializeBenchmarks
69
{
7-
[MemoryDiagnoser]
8-
public class JsonNetSerializeBenchmarks
9-
{
10-
readonly JsonNetSerializer _serializer = new();
10+
readonly JsonNetSerializer _serializer = new();
1111

12-
List<TestClass> _fakeData;
12+
List<TestClass> _fakeData;
1313

14-
[Params(1, 10, 20)]
15-
public int N { get; set; }
14+
[Params(1, 10, 20)]
15+
public int N { get; set; }
1616

17-
[GlobalSetup]
18-
public void GlobalSetup() => _fakeData = new Fixture().CreateMany<TestClass>(N).ToList();
17+
[GlobalSetup]
18+
public void GlobalSetup() => _fakeData = new Fixture().CreateMany<TestClass>(N).ToList();
1919

20-
[Benchmark(Baseline = true)]
21-
public string Serialize() => _serializer.Serialize(_fakeData);
22-
}
23-
}
20+
[Benchmark(Baseline = true)]
21+
public string Serialize() => _serializer.Serialize(_fakeData);
22+
}

benchmarks/RestSharp.Benchmarks/Serializers/TestClass.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ReSharper disable UnusedMember.Global
12
namespace RestSharp.Benchmarks.Serializers;
23

34
public class TestClass {

src/RestSharp.Serializers.Xml/XmlExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class XmlExtensions {
3030
public static XName? AsNamespaced(this string? name, string? @namespace) {
3131
XName? xName = name;
3232

33-
if (name != null && @namespace.IsNotEmpty()) xName = XName.Get(name, @namespace!);
33+
if (name != null && @namespace.IsNotEmpty()) xName = XName.Get(name, @namespace);
3434

3535
return xName;
3636
}

src/RestSharp.Serializers.Xml/XmlSerializer.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void Map(XContainer root, object obj) {
110110

111111
var props = objType.GetProperties()
112112
.Select(p => new { p, indexAttribute = p.GetAttribute<SerializeAsAttribute>() })
113-
.Where(t => t.p.CanRead && t.p.CanWrite)
113+
.Where(t => t.p is { CanRead: true, CanWrite: true })
114114
.OrderBy(t => t.indexAttribute?.Index ?? int.MaxValue)
115115
.Select(t => t.p);
116116
var globalOptions = objType.GetAttribute<SerializeAsAttribute>();
@@ -177,7 +177,7 @@ void Map(XContainer root, object obj) {
177177
? setting.Name
178178
: type.Name;
179179

180-
var instance = new XElement(itemTypeName!.AsNamespaced(Namespace)!);
180+
var instance = new XElement(itemTypeName.AsNamespaced(Namespace)!);
181181

182182
Map(instance, item);
183183

@@ -228,17 +228,17 @@ static string SerializeNumber(object number)
228228
/// </summary>
229229
static bool IsNumeric(object value)
230230
=> value switch {
231-
sbyte _ => true,
232-
byte _ => true,
233-
short _ => true,
234-
ushort _ => true,
235-
int _ => true,
236-
uint _ => true,
237-
long _ => true,
238-
ulong _ => true,
239-
float _ => true,
240-
double _ => true,
241-
decimal _ => true,
242-
_ => false
231+
sbyte => true,
232+
byte => true,
233+
short => true,
234+
ushort => true,
235+
int => true,
236+
uint => true,
237+
long => true,
238+
ulong => true,
239+
float => true,
240+
double => true,
241+
decimal => true,
242+
_ => false
243243
};
244244
}

src/RestSharp/Authenticators/OAuth/Extensions/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static class StringExtensions {
2121

2222
public static string Then(this string input, string value) => string.Concat(input, value);
2323

24-
public static Uri AsUri(this string value) => new Uri(value);
24+
public static Uri AsUri(this string value) => new(value);
2525

2626
public static byte[] GetBytes(this string input) => Encoding.UTF8.GetBytes(input);
2727

src/RestSharp/Authenticators/OAuth/OAuth1Authenticator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public static OAuth1Authenticator ForRequestToken(
7575
Type = OAuthType.RequestToken
7676
};
7777

78+
[PublicAPI]
7879
public static OAuth1Authenticator ForRequestToken(string consumerKey, string? consumerSecret, string callbackUrl) {
7980
var authenticator = ForRequestToken(consumerKey, consumerSecret);
8081

@@ -102,6 +103,7 @@ public static OAuth1Authenticator ForAccessToken(
102103
Type = OAuthType.AccessToken
103104
};
104105

106+
[PublicAPI]
105107
public static OAuth1Authenticator ForAccessToken(
106108
string consumerKey,
107109
string? consumerSecret,
@@ -167,6 +169,7 @@ public static OAuth1Authenticator ForClientAuthentication(
167169
Type = OAuthType.ClientAuthentication
168170
};
169171

172+
[PublicAPI]
170173
public static OAuth1Authenticator ForProtectedResource(
171174
string consumerKey,
172175
string? consumerSecret,

0 commit comments

Comments
 (0)