Skip to content

Commit

Permalink
Fixes; refactoring; updates; integrates PR FlareSolverr#22, FlareSolv…
Browse files Browse the repository at this point in the history
  • Loading branch information
Decimation committed Nov 20, 2024
1 parent 9e7c3a1 commit 0df38d8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<Version>3.0.8</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\FlareSolverrSharp\FlareSolverrSharp.csproj" />
</ItemGroup>
Expand Down
24 changes: 12 additions & 12 deletions sample/FlareSolverrSharp.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ public static async Task Main()

var client = new HttpClient(handler);

var x = await client.GetAsync(Settings.ProtectedUri);

Console.WriteLine(x);
Console.WriteLine( ChallengeDetector.IsClearanceRequiredAsync(x));
/*foreach (KeyValuePair<string, IEnumerable<string>> pair in x.Headers) {
Console.WriteLine(pair);
}*/
foreach (var y in x.Headers.Server) {

Console.WriteLine(y.Product.Name);
}
// Assert.IsTrue(c.Message.Contains("Error connecting to FlareSolverr server"));
HttpRequestMessage[] rg =
[
new(HttpMethod.Get, "https://ascii2d.net/search/url/https://pomf2.lain.la/f/fy32pj5e.png"),
new(HttpMethod.Get, "https://ascii2d.net/search/url/https://i.redd.it/xixxli0axz7b1.jpg"),
];

await Parallel.ForEachAsync(rg, async (x, y) =>
{
var res = await client.SendAsync(x, y);
Console.WriteLine($"{x.RequestUri} -> {res.StatusCode}");
return;
});
}

}
10 changes: 8 additions & 2 deletions src/FlareSolverrSharp/FlareSolverrSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageId>FlareSolverrSharp</PackageId>
<RootNamespace>FlareSolverrSharp</RootNamespace>
<LangVersion>latest</LangVersion>
<Version>3.0.8</Version>
<Version>3.0.9</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 @@ -14,6 +14,11 @@
<PackageLicenseUrl>https://github.com/ngosang/FlareSolverrSharp/blob/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyName>FlareSolverrSharp</AssemblyName>
<DefineConstants>JETBRAINS_ANNOTATIONS;TRACE</DefineConstants>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<PublishSingleFile Condition="'$(Configuration)' == 'Release|AnyCPU'">true</PublishSingleFile>
<PublishTrimmed>True</PublishTrimmed>
<!-- <PublishSingleFile>true</PublishSingleFile> -->
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -26,7 +31,8 @@

<ItemGroup>
<PackageReference Include="Flurl.Http" Version="4.0.2" />
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

</Project>
</Project>
16 changes: 8 additions & 8 deletions src/FlareSolverrSharp/Solvers/FlareSolverr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ private async Task<T> SendFlareSolverrRequestInternalAsync<T>(HttpContent flareS
T result = default;

//https://github.com/FlareSolverr/FlareSolverrSharp/pull/27/files
await Func();

//todo: what is this "semaphore locker" for
await s_locker.LockAsync(async () =>
// await s_locker.LockAsync(Func);
return result;

async Task Func()
{
HttpResponseMessage response;

Expand Down Expand Up @@ -219,8 +223,7 @@ await s_locker.LockAsync(async () =>
}

// Don't try parsing if FlareSolverr hasn't returned 200 or 500
if (!AllowAnyStatusCode
&& (response.StatusCode is not (HttpStatusCode.OK or HttpStatusCode.InternalServerError))) {
if (!AllowAnyStatusCode && (response.StatusCode is not (HttpStatusCode.OK or HttpStatusCode.InternalServerError))) {
throw new FlareSolverrException($"Status code: {response.StatusCode}");
}

Expand All @@ -231,7 +234,7 @@ await s_locker.LockAsync(async () =>

// result = await JsonSerializer.DeserializeAsync<FlareSolverrResponse>(resContent, options);

result = JsonSerializer.Deserialize<T>(resContent, typeInfo);
result = JsonSerializer.Deserialize(resContent, typeInfo);
}
catch (Exception) {
throw new FlareSolverrException($"Error parsing response, check FlareSolverr. Response: {resContent}");
Expand Down Expand Up @@ -273,10 +276,7 @@ await s_locker.LockAsync(async () =>
// return SendRequestAsync(flareSolverrRequest);*/


});
return result;


}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
<PackageReference Include="MSTest" Version="3.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
</ItemGroup>
Expand Down

0 comments on commit 0df38d8

Please sign in to comment.