-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix meta header and support rest api compatibility (#59)
* Fix meta header client version detection * Support default mime type and ES rest API compatibility
- Loading branch information
1 parent
8682b3d
commit 88a4b31
Showing
12 changed files
with
111 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tests/Elastic.Transport.IntegrationTests/Http/MetaHeaderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Elastic.Transport.IntegrationTests.Plumbing; | ||
using Elastic.Transport.IntegrationTests.Plumbing.Stubs; | ||
using Elastic.Transport.Products.Elasticsearch; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Xunit; | ||
|
||
namespace Elastic.Transport.IntegrationTests.Http; | ||
|
||
/// <summary> | ||
/// Tests that the test framework loads a controller and the exposed transport can talk to its endpoints. | ||
/// Tests runs against a server that started up once and its server instance shared among many test classes | ||
/// </summary> | ||
public class MetaHeaderTests : AssemblyServerTestsBase | ||
{ | ||
public MetaHeaderTests(TransportTestServer instance) : base(instance) { } | ||
|
||
[Fact] | ||
public async Task AddsExpectedMetaHeader() | ||
{ | ||
var connection = new TestableHttpConnection(responseMessage => | ||
{ | ||
responseMessage.RequestMessage.Content.Headers.ContentType.MediaType.Should().Be("application/vnd.elasticsearch+json"); | ||
var parameter = responseMessage.RequestMessage.Content.Headers.ContentType.Parameters.Single(); | ||
parameter.Name.Should().Be("compatible-with"); | ||
parameter.Value.Should().Be("8"); | ||
|
||
var acceptValues = responseMessage.RequestMessage.Headers.GetValues("Accept"); | ||
acceptValues.Single().Replace(" ", "").Should().Be("application/vnd.elasticsearch+json;compatible-with=8"); | ||
|
||
var contentTypeValues = responseMessage.RequestMessage.Content.Headers.GetValues("Content-Type"); | ||
contentTypeValues.Single().Replace(" ", "").Should().Be("application/vnd.elasticsearch+json;compatible-with=8"); | ||
}); | ||
|
||
var connectionPool = new SingleNodePool(Server.Uri); | ||
var config = new TransportConfiguration(connectionPool, connection, productRegistration: new ElasticsearchProductRegistration(typeof(Clients.Elasticsearch.ElasticsearchClient))); | ||
var transport = new DefaultHttpTransport(config); | ||
|
||
var response = await transport.PostAsync<StringResponse>("/metaheader", PostData.String("{}")); | ||
} | ||
} | ||
|
||
[ApiController, Route("[controller]")] | ||
public class MetaHeaderController : ControllerBase | ||
{ | ||
[HttpPost()] | ||
public async Task<int> Post() => await Task.FromResult(100); | ||
} |