Skip to content

Instantly share code, notes, and snippets.

@changhuixu
Created June 26, 2020 19:08
Show Gist options
  • Save changhuixu/c2b39fd7f01b606113f2053210b24d0b to your computer and use it in GitHub Desktop.
Save changhuixu/c2b39fd7f01b606113f2053210b24d0b to your computer and use it in GitHub Desktop.
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapGet("/", async context =>
{
context.Response.ContentType = "text/plain";
// Host info
var name = Dns.GetHostName(); // get container id
var ip = Dns.GetHostEntry(name).AddressList.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);
Console.WriteLine($"Host Name: { Environment.MachineName} \t {name}\t {ip}");
await context.Response.WriteAsync($"Host Name: {Environment.MachineName}{Environment.NewLine}");
await context.Response.WriteAsync(Environment.NewLine);
// Request method, scheme, and path
await context.Response.WriteAsync($"Request Method: {context.Request.Method}{Environment.NewLine}");
await context.Response.WriteAsync($"Request Scheme: {context.Request.Scheme}{Environment.NewLine}");
await context.Response.WriteAsync($"Request URL: {context.Request.GetDisplayUrl()}{Environment.NewLine}");
await context.Response.WriteAsync($"Request Path: {context.Request.Path}{Environment.NewLine}");
// Headers
await context.Response.WriteAsync($"Request Headers:{Environment.NewLine}");
foreach (var (key, value) in context.Request.Headers)
{
await context.Response.WriteAsync($"\t {key}: {value}{Environment.NewLine}");
}
await context.Response.WriteAsync(Environment.NewLine);
// Connection: RemoteIp
await context.Response.WriteAsync($"Request Remote IP: {context.Connection.RemoteIpAddress}");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment