-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drop /trace, change /httptrace to /httpexchanges (except on TPCF)
- Loading branch information
Showing
68 changed files
with
1,346 additions
and
1,743 deletions.
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
107 changes: 107 additions & 0 deletions
107
src/Management/src/Endpoint/Actuators/HttpExchanges/ConfigureHttpExchangesEndpointOptions.cs
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,107 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Net.Http.Headers; | ||
using Steeltoe.Management.Endpoint.Configuration; | ||
|
||
namespace Steeltoe.Management.Endpoint.Actuators.HttpExchanges; | ||
|
||
internal sealed class ConfigureHttpExchangesEndpointOptions(IConfiguration configuration) | ||
: ConfigureEndpointOptions<HttpExchangesEndpointOptions>(configuration, ManagementInfoPrefix, "httpexchanges") | ||
{ | ||
private const string ManagementInfoPrefix = "management:endpoints:httpexchanges"; | ||
private const int DefaultCapacity = 100; | ||
|
||
private static readonly string[] DefaultAllowedRequestHeaders = | ||
[ | ||
HeaderNames.Accept, | ||
HeaderNames.AcceptCharset, | ||
HeaderNames.AcceptEncoding, | ||
HeaderNames.AcceptLanguage, | ||
HeaderNames.Allow, | ||
HeaderNames.CacheControl, | ||
HeaderNames.Connection, | ||
HeaderNames.ContentEncoding, | ||
HeaderNames.ContentLength, | ||
HeaderNames.ContentType, | ||
HeaderNames.Date, | ||
HeaderNames.DNT, | ||
HeaderNames.Expect, | ||
HeaderNames.Host, | ||
HeaderNames.MaxForwards, | ||
HeaderNames.Range, | ||
HeaderNames.SecWebSocketExtensions, | ||
HeaderNames.SecWebSocketVersion, | ||
HeaderNames.TE, | ||
HeaderNames.Trailer, | ||
HeaderNames.TransferEncoding, | ||
HeaderNames.Upgrade, | ||
HeaderNames.UserAgent, | ||
HeaderNames.Warning, | ||
HeaderNames.XRequestedWith, | ||
HeaderNames.XUACompatible | ||
]; | ||
|
||
private static readonly string[] DefaultAllowedResponseHeaders = | ||
[ | ||
HeaderNames.AcceptRanges, | ||
HeaderNames.Age, | ||
HeaderNames.Allow, | ||
HeaderNames.AltSvc, | ||
HeaderNames.Connection, | ||
HeaderNames.ContentDisposition, | ||
HeaderNames.ContentLanguage, | ||
HeaderNames.ContentLength, | ||
HeaderNames.ContentLocation, | ||
HeaderNames.ContentRange, | ||
HeaderNames.ContentType, | ||
HeaderNames.Date, | ||
HeaderNames.Expires, | ||
HeaderNames.LastModified, | ||
HeaderNames.Location, | ||
HeaderNames.Server, | ||
HeaderNames.TransferEncoding, | ||
HeaderNames.Upgrade, | ||
HeaderNames.XPoweredBy | ||
]; | ||
|
||
public override void Configure(HttpExchangesEndpointOptions options) | ||
{ | ||
ArgumentNullException.ThrowIfNull(options); | ||
|
||
base.Configure(options); | ||
|
||
if (options.Capacity == -1) | ||
{ | ||
options.Capacity = DefaultCapacity; | ||
} | ||
|
||
// It's not possible to distinguish between null and an empty list in configuration. | ||
// See https://github.com/dotnet/extensions/issues/1341. | ||
// As a workaround, we interpret a single empty string element to clear the defaults. | ||
if (options.RequestHeaders.Count == 0) | ||
{ | ||
foreach (string defaultKey in DefaultAllowedRequestHeaders) | ||
{ | ||
options.RequestHeaders.Add(defaultKey); | ||
} | ||
} | ||
else if (options.RequestHeaders is [""]) | ||
{ | ||
options.RequestHeaders.Clear(); | ||
} | ||
if (options.ResponseHeaders.Count == 0) | ||
{ | ||
foreach (string defaultKey in DefaultAllowedResponseHeaders) | ||
{ | ||
options.ResponseHeaders.Add(defaultKey); | ||
} | ||
} | ||
else if (options.ResponseHeaders is [""]) | ||
{ | ||
options.ResponseHeaders.Clear(); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/Management/src/Endpoint/Actuators/HttpExchanges/EndpointServiceCollectionExtensions.cs
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,54 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Steeltoe.Management.Diagnostics; | ||
|
||
namespace Steeltoe.Management.Endpoint.Actuators.HttpExchanges; | ||
|
||
public static class EndpointServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Adds the HttpExchanges actuator to the service container. | ||
/// </summary> | ||
/// <param name="services"> | ||
/// The <see cref="IServiceCollection" /> to add services to. | ||
/// </param> | ||
/// <returns> | ||
/// The incoming <paramref name="services" /> so that additional calls can be chained. | ||
/// </returns> | ||
public static IServiceCollection AddHttpExchangesActuator(this IServiceCollection services) | ||
{ | ||
return services.AddHttpExchangesActuator(_ => { }); | ||
} | ||
|
||
/// <summary> | ||
/// Adds the HttpExchanges (formerly known as Trace or HttpTrace) actuator to the service container. | ||
/// </summary> | ||
/// <param name="services"> | ||
/// The <see cref="IServiceCollection" /> to add services to. | ||
/// </param> | ||
/// <param name="configureOptions">A delegate to configure the <see cref="HttpExchangesEndpointOptions"/>.</param> | ||
/// <returns> | ||
/// The incoming <paramref name="services" /> so that additional calls can be chained. | ||
/// </returns> | ||
public static IServiceCollection AddHttpExchangesActuator(this IServiceCollection services, Action<HttpExchangesEndpointOptions> configureOptions) | ||
{ | ||
ArgumentNullException.ThrowIfNull(services); | ||
|
||
services.TryAddSingleton<IDiagnosticsManager, DiagnosticsManager>(); | ||
services.AddHostedService<DiagnosticsService>(); | ||
|
||
services.AddCommonActuatorServices(); | ||
services.AddHttpExchangesActuatorServices(configureOptions); | ||
|
||
services.TryAddEnumerable(ServiceDescriptor.Singleton<IDiagnosticObserver, HttpExchangesDiagnosticObserver>()); | ||
|
||
services.TryAddSingleton<IHttpExchangesRepository>(provider => | ||
provider.GetServices<IDiagnosticObserver>().OfType<HttpExchangesDiagnosticObserver>().Single()); | ||
|
||
return services; | ||
} | ||
} |
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
Oops, something went wrong.