Created
January 30, 2025 13:16
-
-
Save dj-nitehawk/be15f1125cafc4ddd1c233eca26c0a8a to your computer and use it in GitHub Desktop.
Global response modifier
This file contains hidden or 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
var bld = WebApplication.CreateBuilder(args); | |
bld.Services | |
.SwaggerDocument() | |
.AddFastEndpoints(); | |
var app = bld.Build(); | |
app.UseFastEndpoints( | |
c => c.Endpoints.GlobalResponseModifier | |
= (ctx, content) => | |
{ | |
ctx.Response.Headers.Append("x-some-header", content as string); | |
}) | |
.UseSwaggerGen(); | |
app.Run(); | |
sealed class SomeEndpoint : Ep.NoReq.Res<string> | |
{ | |
public override void Configure() | |
{ | |
Get("some-endpoint"); | |
AllowAnonymous(); | |
} | |
public override async Task HandleAsync(CancellationToken ct) | |
{ | |
await SendAsync("hello world!"); | |
} | |
} |
Author
dj-nitehawk
commented
Jan 30, 2025
Is it possible to substitute the content object for another object before sending the response? Maybe for encrypting the payload? Example.
var decryptedResponseStr = JsonSerializer.Serialize(content);
var encryptedResponseStr = AES.Encrypt(decryptedResponseStr, "secretKey");
content = new EncryptedBody { Data = encryptedResponseStr };
That worked perfectly. Thank you for your help.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment