-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/make automatic header optional #542
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b9a4113
Make UserAgent request header optional.
KirovAir ea16b91
Changed to configurable user agent header.
KirovAir c7c9151
Update src/GraphQL.Client/GraphQLHttpClientOptions.cs
sungam3r 625f7fe
Update src/GraphQL.Client/GraphQLHttpRequest.cs
sungam3r f0bcc63
Update src/GraphQL.Client/GraphQLHttpRequest.cs
sungam3r 2df946f
Update src/GraphQL.Client/GraphQLHttpRequest.cs
sungam3r 2b63af3
Update src/GraphQL.Client/GraphQLHttpRequest.cs
sungam3r 188e94e
refactor test helpers to provide access to GraphQLHttpClientOptions w…
rose-a ea7611d
test user agent header
rose-a File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 12 additions & 0 deletions
12
tests/GraphQL.Client.Tests.Common/Properties/launchSettings.json
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,12 @@ | ||
{ | ||
"profiles": { | ||
"GraphQL.Client.Tests.Common": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:59034" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Net.Http.Headers; | ||
using FluentAssertions; | ||
using GraphQL.Client.Abstractions; | ||
using GraphQL.Client.Http; | ||
using GraphQL.Integration.Tests.Helpers; | ||
using Xunit; | ||
|
||
namespace GraphQL.Integration.Tests; | ||
|
||
public class UserAgentHeaderTests : IAsyncLifetime, IClassFixture<SystemTextJsonAutoNegotiateServerTestFixture> | ||
{ | ||
private readonly IntegrationServerTestFixture Fixture; | ||
private GraphQLHttpClient? ChatClient; | ||
|
||
public UserAgentHeaderTests(SystemTextJsonAutoNegotiateServerTestFixture fixture) | ||
{ | ||
Fixture = fixture; | ||
} | ||
|
||
public async Task InitializeAsync() => await Fixture.CreateServer().ConfigureAwait(false); | ||
|
||
public Task DisposeAsync() | ||
{ | ||
ChatClient?.Dispose(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
[Fact] | ||
public async void Can_set_custom_user_agent() | ||
{ | ||
const string userAgent = "CustomUserAgent"; | ||
ChatClient = Fixture.GetChatClient(options => options.DefaultUserAgentRequestHeader = ProductInfoHeaderValue.Parse(userAgent)); | ||
|
||
var graphQLRequest = new GraphQLRequest("query clientUserAgent { clientUserAgent }"); | ||
var response = await ChatClient.SendQueryAsync(graphQLRequest, () => new { clientUserAgent = string.Empty }).ConfigureAwait(false); | ||
|
||
response.Errors.Should().BeNull(); | ||
response.Data.clientUserAgent.Should().Be(userAgent); | ||
} | ||
|
||
[Fact] | ||
public async void Default_user_agent_is_set_as_expected() | ||
{ | ||
string? expectedUserAgent = new ProductInfoHeaderValue( | ||
typeof(GraphQLHttpClient).Assembly.GetName().Name, | ||
typeof(GraphQLHttpClient).Assembly.GetName().Version.ToString()).ToString(); | ||
|
||
ChatClient = Fixture.GetChatClient(); | ||
|
||
var graphQLRequest = new GraphQLRequest("query clientUserAgent { clientUserAgent }"); | ||
var response = await ChatClient.SendQueryAsync(graphQLRequest, () => new { clientUserAgent = string.Empty }).ConfigureAwait(false); | ||
|
||
response.Errors.Should().BeNull(); | ||
response.Data.clientUserAgent.Should().Be(expectedUserAgent); | ||
} | ||
|
||
[Fact] | ||
public async void No_Default_user_agent_if_set_to_null() | ||
{ | ||
ChatClient = Fixture.GetChatClient(options => options.DefaultUserAgentRequestHeader = null); | ||
|
||
var graphQLRequest = new GraphQLRequest("query clientUserAgent { clientUserAgent }"); | ||
var response = await ChatClient.SendQueryAsync(graphQLRequest, () => new { clientUserAgent = string.Empty }).ConfigureAwait(false); | ||
|
||
response.Errors.Should().HaveCount(1); | ||
response.Errors[0].Message.Should().Be("user agent header not set"); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change
<Project Sdk="Microsoft.NET.Sdk">
to<Project Sdk="Microsoft.NET.Sdk.Web">
to achive the same.