Skip to content

Commit

Permalink
Fix ContentType detection for POST requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ngosang committed Jul 31, 2022
1 parent 67388a5 commit 32f319f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/FlareSolverrSharp/Solvers/FlareSolverr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, stri
}
else if (request.Method == HttpMethod.Post)
{
var contentTypeType = request.Content.GetType();
if (contentTypeType == typeof(FormUrlEncodedContent))
// request.Content.GetType() doesn't work well when encoding != utf-8
var contentMediaType = request.Content.Headers.ContentType?.MediaType.ToLower() ?? "<null>";
if (contentMediaType.Contains("application/x-www-form-urlencoded"))
{
req = new FlareSolverrRequestPost
{
Expand All @@ -203,19 +204,15 @@ private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, stri
Session = sessionId
};
}
else if (contentTypeType == typeof(MultipartFormDataContent))
else if (contentMediaType.Contains("multipart/form-data")
|| contentMediaType.Contains("text/html"))
{
//TODO Implement - check if we just need to pass the content-type with the relevant headers
throw new FlareSolverrException("Unimplemented POST Content-Type: " + request.Content.Headers.ContentType);
}
else if (contentTypeType == typeof(StringContent))
{
//TODO Implement - check if we just need to pass the content-type with the relevant headers
throw new FlareSolverrException("Unimplemented POST Content-Type: " + request.Content.Headers.ContentType);
throw new FlareSolverrException("Unimplemented POST Content-Type: " + contentMediaType);
}
else
{
throw new FlareSolverrException("Unsupported POST Content-Type: " + request.Content.Headers.ContentType);
throw new FlareSolverrException("Unsupported POST Content-Type: " + contentMediaType);
}
}
else
Expand Down

0 comments on commit 32f319f

Please sign in to comment.