Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RestSharp.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Zimarev/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<Using Include="JetBrains.Annotations"/>
</ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">
<PackageReference Include="IsExternalInit" Version="1.0.1" PrivateAssets="All"/>
<PackageReference Include="IsExternalInit" Version="1.0.2" PrivateAssets="All"/>
</ItemGroup>
<Target Name="CustomVersion" AfterTargets="MinVer">
<PropertyGroup>
Expand Down
24 changes: 21 additions & 3 deletions src/RestSharp.Serializers.NewtonsoftJson/JsonNetSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Newtonsoft.Json.Serialization;

namespace RestSharp.Serializers.NewtonsoftJson;
namespace RestSharp.Serializers.NewtonsoftJson;

public class JsonNetSerializer : IRestSerializer {
public class JsonNetSerializer : IRestSerializer, ISerializer, IDeserializer {
/// <summary>
/// Default serialization settings:
/// - Camel-case contract resolver
Expand Down Expand Up @@ -37,7 +51,7 @@ public class JsonNetSerializer : IRestSerializer {

public string? Serialize(object? obj) {
if (obj == null) return null;

using var writerBuffer = _writerBuffer ??= new WriterBuffer(_serializer);

_serializer.Serialize(writerBuffer.GetJsonTextWriter(), obj, obj.GetType());
Expand All @@ -50,11 +64,15 @@ public class JsonNetSerializer : IRestSerializer {
public T? Deserialize<T>(RestResponse response) {
if (response.Content == null)
throw new DeserializationException(response, new InvalidOperationException("Response content is null"));

using var reader = new JsonTextReader(new StringReader(response.Content)) { CloseInput = true };

return _serializer.Deserialize<T>(reader);
}

public ISerializer Serializer => this;
public IDeserializer Deserializer => this;

public string[] SupportedContentTypes { get; } = {
"application/json", "text/json", "text/x-json", "text/javascript", "*+json"
};
Expand Down
14 changes: 14 additions & 0 deletions src/RestSharp.Serializers.NewtonsoftJson/RestClientExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace RestSharp.Serializers.NewtonsoftJson;

[PublicAPI]
Expand Down
14 changes: 14 additions & 0 deletions src/RestSharp.Serializers.NewtonsoftJson/WriterBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Globalization;
using System.Text;

Expand Down
16 changes: 15 additions & 1 deletion src/RestSharp.Serializers.Xml/DeserializeAsAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// ReSharper disable once CheckNamespace
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// ReSharper disable once CheckNamespace
namespace RestSharp.Serializers;

/// <summary>
Expand Down
16 changes: 15 additions & 1 deletion src/RestSharp.Serializers.Xml/SerializeAsAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using System.Globalization;
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Globalization;
using RestSharp.Extensions;

// ReSharper disable once CheckNamespace
Expand Down
16 changes: 15 additions & 1 deletion src/RestSharp.Serializers.Xml/XmlAttributeDeserializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using System.Reflection;
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Reflection;
using System.Xml.Linq;
using RestSharp.Extensions;

Expand Down
16 changes: 15 additions & 1 deletion src/RestSharp.Serializers.Xml/XmlDeserializer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections;
using System.ComponentModel;
using System.Globalization;
Expand All @@ -8,7 +22,7 @@

namespace RestSharp.Serializers.Xml;

public class XmlDeserializer : IXmlDeserializer {
public class XmlDeserializer : IXmlDeserializer, IWithRootElement, IWithDateFormat {
public XmlDeserializer() => Culture = CultureInfo.InvariantCulture;

public CultureInfo Culture { get; set; }
Expand Down
16 changes: 15 additions & 1 deletion src/RestSharp.Serializers.Xml/XmlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using System.Xml.Linq;
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Xml.Linq;
using RestSharp.Extensions;

namespace RestSharp.Serializers.Xml;
Expand Down
18 changes: 16 additions & 2 deletions src/RestSharp.Serializers.Xml/XmlSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using System.Collections;
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections;
using System.Globalization;
using System.Reflection;
using System.Xml.Linq;
Expand All @@ -9,7 +23,7 @@ namespace RestSharp.Serializers.Xml;
/// <summary>
/// Default XML Serializer
/// </summary>
public class XmlSerializer : IXmlSerializer {
public class XmlSerializer : IXmlSerializer, IWithRootElement, IWithDateFormat {
/// <summary>
/// Default constructor, does not specify namespace
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2009-2020 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions src/RestSharp/Authenticators/AuthenticatorBase.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace RestSharp.Authenticators;

public abstract class AuthenticatorBase : IAuthenticator {
Expand Down
21 changes: 17 additions & 4 deletions src/RestSharp/Authenticators/HttpBasicAuthenticator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
using System.Text;
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace RestSharp.Authenticators;
using System.Text;

namespace RestSharp.Authenticators;

/// <summary>
/// Allows "basic access authentication" for HTTP requests.
Expand All @@ -10,8 +24,7 @@ namespace RestSharp.Authenticators;
/// UTF-8 is used by default but some servers might expect ISO-8859-1 encoding.
/// </remarks>
[PublicAPI]
public class HttpBasicAuthenticator : AuthenticatorBase
{
public class HttpBasicAuthenticator : AuthenticatorBase {
public HttpBasicAuthenticator(string username, string password) : this(username, password, Encoding.UTF8) { }

public HttpBasicAuthenticator(string username, string password, Encoding encoding)
Expand Down
16 changes: 15 additions & 1 deletion src/RestSharp/Authenticators/IAuthenticator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
namespace RestSharp.Authenticators;
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace RestSharp.Authenticators;

public interface IAuthenticator {
ValueTask Authenticate(RestClient client, RestRequest request);
Expand Down
14 changes: 14 additions & 0 deletions src/RestSharp/Authenticators/JwtAuthenticator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace RestSharp.Authenticators;

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions src/RestSharp/Authenticators/OAuth/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace RestSharp.Authenticators.OAuth;

public enum OAuthSignatureMethod { HmacSha1, HmacSha256, PlainText, RsaSha1 }
Expand Down
14 changes: 14 additions & 0 deletions src/RestSharp/Authenticators/OAuth/Extensions/OAuthExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Security.Cryptography;
using System.Text;

Expand Down
19 changes: 16 additions & 3 deletions src/RestSharp/Authenticators/OAuth/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
// Copyright © 2009-2021 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Text;

namespace RestSharp.Authenticators.OAuth.Extensions;
namespace RestSharp.Authenticators.OAuth.Extensions;

static class StringExtensions
{
static class StringExtensions {
public static bool EqualsIgnoreCase(this string left, string right) => string.Equals(left, right, StringComparison.InvariantCultureIgnoreCase);

public static string Then(this string input, string value) => string.Concat(input, value);
Expand Down
Loading