add server name
This commit is contained in:
parent
0e189f5541
commit
27c777676d
@ -43,14 +43,16 @@ namespace FastGithub.Http
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
public override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.Headers.UserAgent.Contains(userAgent))
|
||||
{
|
||||
throw new FastGithubException($"由于{request.RequestUri}实际指向了{nameof(FastGithub)}自身,{nameof(FastGithub)}已中断本次转发");
|
||||
}
|
||||
request.Headers.UserAgent.Add(userAgent);
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
var response = await base.SendAsync(request, cancellationToken);
|
||||
response.Headers.Server.TryParseAdd(nameof(FastGithub));
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,24 +9,6 @@ namespace FastGithub
|
||||
/// </summary>
|
||||
public static class ApplicationBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用服务头
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="serverHeader"></param>
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseServerHeader(this IApplicationBuilder app, string serverHeader = nameof(FastGithub))
|
||||
{
|
||||
return app.Use(next => context =>
|
||||
{
|
||||
if (context.Response.HasStarted == false)
|
||||
{
|
||||
context.Response.Headers.Server = serverHeader;
|
||||
}
|
||||
return next(context);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用http代理中间件
|
||||
/// </summary>
|
||||
|
||||
@ -56,13 +56,11 @@ namespace FastGithub
|
||||
var httpProxyPort = app.ApplicationServices.GetRequiredService<IOptions<FastGithubOptions>>().Value.HttpProxyPort;
|
||||
app.MapWhen(context => context.Connection.LocalPort == httpProxyPort, appBuilder =>
|
||||
{
|
||||
appBuilder.UseServerHeader();
|
||||
appBuilder.UseHttpProxy();
|
||||
});
|
||||
|
||||
app.MapWhen(context => context.Connection.LocalPort != httpProxyPort, appBuilder =>
|
||||
{
|
||||
appBuilder.UseServerHeader();
|
||||
appBuilder.UseRequestLogging();
|
||||
appBuilder.UseHttpReverseProxy();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user