Skip to content
Merged

v109 #1963

Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix the media type issue with .NET 7 #1969
  • Loading branch information
alexeyzimarev committed Nov 16, 2022
commit 193b6caa2210bc2421dbb38ee202d76432e8cf46
2 changes: 1 addition & 1 deletion src/RestSharp/Parameters/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract record Parameter(string? Name, object? Value, ParameterType Type
/// <summary>
/// MIME content type of the parameter
/// </summary>
public string? ContentType { get; protected init; }
public string ContentType { get; protected init; } = "text/plain";

/// <summary>
/// Return a human-readable representation of this parameter
Expand Down
6 changes: 4 additions & 2 deletions src/RestSharp/Request/BodyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace RestSharp;

using System.Diagnostics.CodeAnalysis;

static class BodyExtensions {
public static bool TryGetBodyParameter(this RestRequest request, out BodyParameter? bodyParameter) {
bodyParameter = request.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody) as BodyParameter;
Expand All @@ -23,5 +25,5 @@ public static bool TryGetBodyParameter(this RestRequest request, out BodyParamet

public static bool HasFiles(this RestRequest request) => request.Files.Count > 0;

public static bool IsEmpty(this ParametersCollection? parameters) => parameters == null || parameters.Count == 0;
}
public static bool IsEmpty([NotNullWhen(false)]this ParametersCollection? parameters) => parameters == null || parameters.Count == 0;
}
4 changes: 2 additions & 2 deletions src/RestSharp/Request/RequestContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ void AddPostParameters(ParametersCollection? postParameters) {

if (Content is MultipartFormDataContent mpContent) {
// we got the multipart form already instantiated, just add parameters to it
foreach (var postParameter in postParameters!) {
foreach (var postParameter in postParameters) {
var parameterName = postParameter.Name!;

mpContent.Add(
new StringContent(postParameter.Value!.ToString()!, _client.Options.Encoding, postParameter.ContentType),
new StringContent(postParameter.Value?.ToString() ?? "", _client.Options.Encoding, postParameter.ContentType),
_request.MultipartFormQuoteParameters ? $"\"{parameterName}\"" : parameterName
);
}
Expand Down
12 changes: 8 additions & 4 deletions src/RestSharp/RestSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup Condition="$(TargetFramework) != 'net6.0' And $(TargetFramework) != 'net7.0'">
<PackageReference Include="System.Text.Json" Version="5.0.1" />
<PackageReference Include="System.Text.Json" Version="5.0.1"/>
</ItemGroup>
<ItemGroup>
<None Remove="RestSharp.csproj.DotSettings" />
<None Remove="RestSharp.csproj.DotSettings"/>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net471'">
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<Reference Include="System.Net.Http"/>
<Reference Include="System.Web"/>
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="All"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<IsTestProject>true</IsTestProject>
<IsPackable>false</IsPackable>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net6.0;net7.0</TargetFrameworks>
<Nullable>disable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Nullable>disable</Nullable>
<TargetFrameworks>net6</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\RestSharp.Serializers.Xml\RestSharp.Serializers.Xml.csproj"/>
Expand Down