Here is an example of how you can create a custom processor to remove the lang cookie for Layout Service requests:
Create a new class that inherits from JssGetLayoutServiceContextProcessor.
Override the Process method and remove the lang cookie from the response object.
Register your custom processor in the httpRequestBegin pipeline after the JssGetLayoutServiceContextProcessor processor.
Here is an example of what the code for the custom processor might look like:
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Sitecore.JavaScriptServices.Configuration;
using Sitecore.JavaScriptServices.Core;
using Sitecore.JavaScriptServices.ViewEngine.LayoutService.Pipelines.GetLayoutServiceContext;
namespace MyCustom.Processors
{
public class RemoveLangCookieProcessor : JssGetLayoutServiceContextProcessor
{
public override void Process(GetLayoutServiceContextArgs args)
{
base.Process(args);
var httpContext = args.Context.RequestServices.GetService<IHttpContextAccessor>().HttpContext;
httpContext.Response.Cookies.Delete("{website}#lang");
}
}
}
Remember to register your custom processor in the httpRequestBegin pipeline after the JssGetLayoutServiceContextProcessor processor:
<httpRequestBegin>
<processor type="Sitecore.JavaScriptServices.ViewEngine.LayoutService.Pipelines.Services.GetLayoutServiceContext.JssGetLayoutServiceContextProcessor, Sitecore.JavaScriptServices.ViewEngine"/>
<processor type="MyCustom.Processors.RemoveLangCookieProcessor, MyCustom"/>
</httpRequestBegin>