Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:

- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: latest
dotnet-channel: lts

- name: Build
run: dotnet build src/FlareSolverrSharp --configuration Release
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>FlareSolverrSharp.Sample</RootNamespace>
<AssemblyName>FlareSolverrSharp.Sample</AssemblyName>
<Version>3.0.7</Version>
Expand Down
5 changes: 3 additions & 2 deletions src/FlareSolverrSharp/FlareSolverrSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>FlareSolverrSharp</PackageId>
<RootNamespace>FlareSolverrSharp</RootNamespace>
<Version>4.0.0</Version>
<Version>5.0.0</Version>
<Authors>Diego Heras (ngosang)</Authors>
<Description>FlareSolverr .Net / Proxy server to bypass Cloudflare protection.</Description>
<PackageTags>flaresolverr, flaresolver, cloudflare, solver, bypass, protection, solving, library, cloudflaresolver, delegatinghandler, recaptcha, captcha, javascript, challenge, utilities</PackageTags>
Expand All @@ -15,6 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="System.Net.Http.Json" Version="10.0.14" />
<PackageReference Include="System.Text.Json" Version="10.0.14" />
</ItemGroup>
</Project>
17 changes: 9 additions & 8 deletions src/FlareSolverrSharp/Solvers/FlareSolverr.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using FlareSolverrSharp.Exceptions;
using FlareSolverrSharp.Types;
using FlareSolverrSharp.Utilities;
using Newtonsoft.Json;

namespace FlareSolverrSharp.Solvers
{
Expand Down Expand Up @@ -101,14 +103,13 @@ await Locker.LockAsync(async () =>
throw new FlareSolverrException("HTTP StatusCode not 200 or 500. Status is :" + response.StatusCode);
}

var resContent = await response.Content.ReadAsStringAsync();
try
{
result = JsonConvert.DeserializeObject<FlareSolverrResponse>(resContent);
result = await response.Content.ReadFromJsonAsync<FlareSolverrResponse>();
}
catch (Exception)
{
throw new FlareSolverrException("Error parsing response, check FlareSolverr. Response: " + resContent);
throw new FlareSolverrException("Error parsing response, check FlareSolverr. Response: " + await response.Content.ReadAsStringAsync());
}

try
Expand Down Expand Up @@ -170,12 +171,12 @@ private FlareSolverrRequestProxy GetProxy()

private HttpContent GetSolverRequestContent(FlareSolverrRequest request)
{
var payload = JsonConvert.SerializeObject(request, new JsonSerializerSettings
var payload = JsonSerializer.Serialize(request, new JsonSerializerOptions
{
NullValueHandling = NullValueHandling.Ignore
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
});
HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");
return content;

return new StringContent(payload, Encoding.UTF8, "application/json");
}

private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, string sessionId = "")
Expand Down
18 changes: 9 additions & 9 deletions src/FlareSolverrSharp/Types/FlareSolverrRequest.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace FlareSolverrSharp.Types
{
public class FlareSolverrRequest
{
[JsonProperty("cmd")]
public string Cmd;
[JsonPropertyName("cmd")]
public string Cmd { get; set; }

[JsonProperty("url")]
public string Url;
[JsonPropertyName("url")]
public string Url { get; set; }

[JsonProperty("session")]
public string Session;
[JsonPropertyName("session")]
public string Session { get; set; }

[JsonProperty("proxy")]
public FlareSolverrRequestProxy Proxy;
[JsonPropertyName("proxy")]
public FlareSolverrRequestProxy Proxy { get; set; }
}
}
8 changes: 4 additions & 4 deletions src/FlareSolverrSharp/Types/FlareSolverrRequestGet.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace FlareSolverrSharp.Types
{
public class FlareSolverrRequestGet : FlareSolverrRequest
{
[JsonProperty("maxTimeout")]
public int MaxTimeout;
[JsonPropertyName("maxTimeout")]
public int MaxTimeout { get; set; }
}
}
}
12 changes: 6 additions & 6 deletions src/FlareSolverrSharp/Types/FlareSolverrRequestPost.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace FlareSolverrSharp.Types
{
public class FlareSolverrRequestPost : FlareSolverrRequest
{
[JsonProperty("postData")]
public string PostData;
[JsonPropertyName("postData")]
public string PostData { get; set; }

[JsonProperty("maxTimeout")]
public int MaxTimeout;
[JsonPropertyName("maxTimeout")]
public int MaxTimeout { get; set; }
}
}
}
14 changes: 7 additions & 7 deletions src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace FlareSolverrSharp.Types
{
public class FlareSolverrRequestProxy
{
[JsonProperty("url")]
public string Url;
[JsonPropertyName("url")]
public string Url { get; set; }

[JsonProperty("username")]
public string Username;
[JsonPropertyName("username")]
public string Username { get; set; }

[JsonProperty("password")]
public string Password;
[JsonPropertyName("password")]
public string Password { get; set; }
}
}
109 changes: 79 additions & 30 deletions src/FlareSolverrSharp/Types/FlareSolverrResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

// ReSharper disable UnusedMember.Global
// ReSharper disable UnassignedField.Global
Expand All @@ -7,38 +7,83 @@ namespace FlareSolverrSharp.Types
{
public class FlareSolverrResponse
{
public string Status;
public string Message;
public long StartTimestamp;
public long EndTimestamp;
public string Version;
public Solution Solution;
public string Session;
public string[] Sessions;
[JsonPropertyName("status")]
public string Status { get; set; }

[JsonPropertyName("message")]
public string Message { get; set; }

[JsonPropertyName("startTimestamp")]
public long StartTimestamp { get; set; }

[JsonPropertyName("endTimestamp")]
public long EndTimestamp { get; set; }

[JsonPropertyName("version")]
public string Version { get; set; }

[JsonPropertyName("solution")]
public Solution Solution { get; set; }

[JsonPropertyName("session")]
public string Session { get; set; }

[JsonPropertyName("sessions")]
public string[] Sessions { get; set; }
}

public class Solution
{
public string Url;
public string Status;
public Headers Headers;
public string Response;
public Cookie[] Cookies;
public string UserAgent;
[JsonPropertyName("url")]
public string Url { get; set; }

[JsonPropertyName("status")]
public string Status { get; set; }

[JsonPropertyName("headers")]
public Headers Headers { get; set; }

[JsonPropertyName("response")]
public string Response { get; set; }

[JsonPropertyName("cookies")]
public Cookie[] Cookies { get; set; }

[JsonPropertyName("userAgent")]
public string UserAgent { get; set; }
}

public class Cookie
{
public string Name;
public string Value;
public string Domain;
public string Path;
public double Expires;
public int Size;
public bool HttpOnly;
public bool Secure;
public bool Session;
public string SameSite;
[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("value")]
public string Value { get; set; }

[JsonPropertyName("domain")]
public string Domain { get; set; }

[JsonPropertyName("path")]
public string Path { get; set; }

[JsonPropertyName("expiry")]
public double Expires { get; set; }

[JsonPropertyName("size")]
public int Size { get; set; }

[JsonPropertyName("httpOnly")]
public bool HttpOnly { get; set; }

[JsonPropertyName("secure")]
public bool Secure { get; set; }

[JsonPropertyName("session")]
public bool Session { get; set; }

[JsonPropertyName("sameSite")]
public string SameSite { get; set; }

public string ToHeaderValue() => $"{Name}={Value}";
public System.Net.Cookie ToCookieObj() => new System.Net.Cookie(Name, Value);
Expand All @@ -47,9 +92,13 @@ public class Cookie

public class Headers
{
public string Status;
public string Date;
[JsonProperty(PropertyName = "content-type")]
public string ContentType;
[JsonPropertyName("status")]
public string Status { get; set; }

[JsonPropertyName("date")]
public string Date { get; set; }

[JsonPropertyName("content-type")]
public string ContentType { get; set; }
}
}
}
3 changes: 1 addition & 2 deletions src/FlareSolverrSharp/Types/FlareSolverrStatusCode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

// ReSharper disable InconsistentNaming
// ReSharper disable InconsistentNaming
namespace FlareSolverrSharp.Types
{
public enum FlareSolverrStatusCode
Expand Down
8 changes: 4 additions & 4 deletions test/FlareSolverrSharp.Tests/FlareSolverrSharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
<AssemblyName>FlareSolverrSharp.Tests</AssemblyName>
<RootNamespace>FlareSolverrSharp.Tests</RootNamespace>
<Version>3.0.7</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="4.5.2" />
<PackageReference Include="MSTest.TestFramework" Version="4.5.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading