mirror of
https://github.com/bitwarden/server.git
synced 2025-05-22 20:11:04 -05:00
use custom http client that follows redirects
This commit is contained in:
parent
5e23334a11
commit
a448b3bc9b
@ -51,13 +51,7 @@ public class ChangePasswordUriService : IChangePasswordUriService
|
|||||||
Path = "/.well-known/resource-that-should-not-exist-whose-status-code-should-not-be-200"
|
Path = "/.well-known/resource-that-should-not-exist-whose-status-code-should-not-be-200"
|
||||||
};
|
};
|
||||||
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Get, url.ToString())
|
var request = new HttpRequestMessage(HttpMethod.Get, url.ToString());
|
||||||
{
|
|
||||||
Headers =
|
|
||||||
{
|
|
||||||
{ "Cache-Control", "no-store" },
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var response = await _httpClient.SendAsync(request);
|
var response = await _httpClient.SendAsync(request);
|
||||||
return !response.IsSuccessStatusCode;
|
return !response.IsSuccessStatusCode;
|
||||||
@ -84,13 +78,7 @@ public class ChangePasswordUriService : IChangePasswordUriService
|
|||||||
Path = "/.well-known/change-password"
|
Path = "/.well-known/change-password"
|
||||||
};
|
};
|
||||||
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Get, url.ToString())
|
var request = new HttpRequestMessage(HttpMethod.Get, url.ToString());
|
||||||
{
|
|
||||||
Headers =
|
|
||||||
{
|
|
||||||
{ "Cache-Control", "no-store" },
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var response = await _httpClient.SendAsync(request);
|
var response = await _httpClient.SendAsync(request);
|
||||||
return response.IsSuccessStatusCode ? url.ToString() : null;
|
return response.IsSuccessStatusCode ? url.ToString() : null;
|
||||||
|
@ -28,6 +28,24 @@ public static class ServiceCollectionExtension
|
|||||||
AllowAutoRedirect = false,
|
AllowAutoRedirect = false,
|
||||||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
|
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The CreatePasswordUri handler wants similar headers as Icons to portray coming from a browser but
|
||||||
|
// needs to follow redirects to get the final URL.
|
||||||
|
services.AddHttpClient("ChangePasswordUri", client =>
|
||||||
|
{
|
||||||
|
client.Timeout = TimeSpan.FromSeconds(20);
|
||||||
|
client.MaxResponseContentBufferSize = 5000000; // 5 MB
|
||||||
|
// Let's add some headers to look like we're coming from a web browser request. Some websites
|
||||||
|
// will block our request without these.
|
||||||
|
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
|
||||||
|
"(KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36");
|
||||||
|
client.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.8");
|
||||||
|
client.DefaultRequestHeaders.Add("Cache-Control", "no-cache");
|
||||||
|
client.DefaultRequestHeaders.Add("Pragma", "no-cache");
|
||||||
|
}).ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
|
||||||
|
{
|
||||||
|
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddHtmlParsing(this IServiceCollection services)
|
public static void AddHtmlParsing(this IServiceCollection services)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user