Skip to content

Commit

Permalink
Revert "fix: Edgegap Plugin 'InvalidOperationException: This instance…
Browse files Browse the repository at this point in the history
… has already started one or more requests.' when trying to Connect->Disconnect->Reconnect"

This reverts commit 68d768b.
  • Loading branch information
mischa committed Nov 6, 2023
1 parent bd85c74 commit bccebc6
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions Assets/Mirror/Hosting/Edgegap/Editor/EdgegapWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,29 +250,16 @@ string selectedApiTokenValue
{
SetToolUIState(ToolState.Connecting);

_httpClient.BaseAddress = new Uri(selectedApiEnvironment.GetApiUrl());

// MIRROR CHANGE ///////////////////////////////////////////////////
// the old code throws an exception when trying to connect again after disconnecting:
// "InvalidOperationException: This instance has already started one or more requests. Properties can only be modified before sending the first request."
// _httpClient.BaseAddress = new Uri(selectedApiEnvironment.GetApiUrl());
// string path = $"/v1/app/{selectedAppName}/version/{selectedAppVersionName}";
// _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("token", selectedApiTokenValue);
// HttpResponseMessage response = await _httpClient.GetAsync(path);
//
// solution: https://stackoverflow.com/questions/51478525/httpclient-this-instance-has-already-started-one-or-more-requests-properties-ca
// "Rather than setting DefaultRequestHeaders, set the headers on each HttpRequestMessage you are sending."

// Create the request message
string baseUrl = selectedApiEnvironment.GetApiUrl();
string path = $"/v1/app/{selectedAppName}/version/{selectedAppVersionName}";
Uri fullUrl = new Uri(new Uri(baseUrl), path);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, fullUrl);
request.Headers.Accept.Clear();
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
request.Headers.Authorization = new AuthenticationHeaderValue("token", selectedApiTokenValue);
HttpResponseMessage response = await _httpClient.SendAsync(request);
// END MIRROR CHANGE ///////////////////////////////////////////////

// Headers
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("token", selectedApiTokenValue);

// Make HTTP request
HttpResponseMessage response = await _httpClient.GetAsync(path);

if (response.IsSuccessStatusCode)
{
Expand Down

0 comments on commit bccebc6

Please sign in to comment.