Skip to content

Commit 3b1c7f8

Browse files
authored
Fix content-type validation for API versioning on NETFX (#6263)
1 parent 91cacb5 commit 3b1c7f8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ public class RequestData
2323
private static readonly string MimeType = "application/vnd.elasticsearch+json; compatible-with="
2424
+ ClientVersionInfo.LowLevelClientVersionInfo.Version.Major;
2525

26+
private static readonly string TrimmedMimeType = "application/vnd.elasticsearch+json;compatible-with="
27+
+ ClientVersionInfo.LowLevelClientVersionInfo.Version.Major;
28+
2629
public static readonly string DefaultJsonMimeType =
2730
ClientVersionInfo.LowLevelClientVersionInfo.Version.Major >= 8 ? MimeType : MimeTypeOld;
2831

29-
3032
private readonly string _path;
3133
private Node _node;
3234
private Uri _requestUri;
@@ -209,13 +211,16 @@ public static bool ValidResponseContentType(string acceptMimeType, string respon
209211

210212
//vendored check
211213
if (acceptMimeType == MimeType)
214+
{
212215
// we check both vendored and nonvendored since on 7.x the response does not return a
213-
// vendored Content-Type header on the response
216+
// vendored Content-Type header on the response.
214217
return
215-
responseMimeType == MimeType
216-
|| responseMimeType == MimeTypeOld
218+
responseMimeType.Equals(MimeType, StringComparison.Ordinal)
219+
|| responseMimeType.Equals(TrimmedMimeType, StringComparison.Ordinal) // Required for .NET FX as the whitespace in the response Content-Type header is stripped
220+
|| responseMimeType.Equals(MimeTypeOld, StringComparison.Ordinal)
217221
|| responseMimeType.StartsWith(MimeTypeOld, StringComparison.OrdinalIgnoreCase)
218222
|| responseMimeType.StartsWith(MimeType, StringComparison.OrdinalIgnoreCase);
223+
}
219224

220225
return responseMimeType.StartsWith(acceptMimeType, StringComparison.OrdinalIgnoreCase);
221226
}

0 commit comments

Comments
 (0)