// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace CorsMiddlewareWebSite
{
public class EchoMiddleware
{
///
/// Instantiates a new .
///
/// The next middleware in the pipeline.
public EchoMiddleware(RequestDelegate next)
{
}
///
/// Echo the request's path in the response. Does not invoke later middleware in the pipeline.
///
/// The of the current request.
/// A that completes when writing to the response is done.
public Task Invoke(HttpContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.Response.ContentType = "text/plain; charset=utf-8";
var path = context.Request.PathBase + context.Request.Path + context.Request.QueryString;
return context.Response.WriteAsync(path, Encoding.UTF8);
}
}
}