Skip to content

Commit

Permalink
No need for thread safety in most cases. (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen authored May 30, 2020
1 parent a362e02 commit 97d3d8d
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/GitLabApiClient/Internal/Http/GitLabHttpFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ internal sealed class GitLabHttpFacade
{
private const string PrivateToken = "PRIVATE-TOKEN";

private readonly object _locker = new object();
private readonly HttpClient _httpClient;
private GitLabApiRequestor _requestor;
private GitLabApiPagedRequestor _pagedRequestor;
Expand Down Expand Up @@ -91,13 +90,10 @@ public async Task<AccessTokenResponse> LoginAsync(AccessTokenRequest accessToken
string url = $"{_httpClient.BaseAddress.GetLeftPart(UriPartial.Authority)}/oauth/token";
var accessTokenResponse = await _requestor.Post<AccessTokenResponse>(url, accessTokenRequest);

lock (_locker)
{
if (_httpClient.DefaultRequestHeaders.Contains(PrivateToken))
_httpClient.DefaultRequestHeaders.Remove(PrivateToken);
if (_httpClient.DefaultRequestHeaders.Contains(PrivateToken))
_httpClient.DefaultRequestHeaders.Remove(PrivateToken);

_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessTokenResponse.AccessToken);
}
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessTokenResponse.AccessToken);

return accessTokenResponse;
}
Expand Down

0 comments on commit 97d3d8d

Please sign in to comment.