/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/SampleServer/Controllers/HttpController.cs
75 строк
2 KB
Chris Ross
Add .NET 8 TFM, clean up new warnings (#2105)
19 апр 2023, 00:52
Не верифицирован
19 апр 2023, 00:52
f282206
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; namespace SampleServer.Controllers { /// <summary> /// Sample controller. /// </summary> [ApiController] public class HttpController : ControllerBase { /// <summary> /// Returns a 200 response. /// </summary> [HttpGet] [Route("/api/noop")] public void NoOp() { } /// <summary> /// Returns a 200 response dumping all info from the incoming request. /// </summary> [HttpGet, HttpPost] [Route("/api/dump")] [Route("/{**catchall}", Order = int.MaxValue)] // Make this the default route if nothing matches public async Task<IActionResult> Dump() { var result = new { Request.Protocol, Request.Method, Request.Scheme, Host = Request.Host.Value, PathBase = Request.PathBase.Value, Path = Request.Path.Value, Query = Request.QueryString.Value, Headers = Request.Headers.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToArray()), Time = DateTimeOffset.UtcNow, Body = await new StreamReader(Request.Body).ReadToEndAsync(), }; return Ok(result); } /// <summary> /// Returns a 200 response dumping all info from the incoming request. /// </summary> [HttpGet] [Route("/api/statuscode")] public void Status(int statusCode) { Response.StatusCode = statusCode; } /// <summary> /// Returns a 200 response dumping all info from the incoming request. /// </summary> [HttpGet] [Route("/api/headers")] public void Headers([FromBody] Dictionary<string, string> headers) { foreach (var (key, value) in headers) { Response.Headers[key] = value; } } } }