I am working on jwt login session management with .net core 2.1 backend and angular 6 front-end , when i send the jwt my browser throws this error et::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK). But by checking on postman it works properly. This started to happen since i added a middleware in my backend code which handles the tokens
Middleware Code:
public class JwtTokenMiddleware : IMiddleware
{
private readonly ISessionManager _sessionManager;
public JwtTokenMiddleware(ISessionManager sessionManager)
{
_sessionManager = sessionManager;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (context.Request.Path.Value.Contains("/api/values/loginuser"))
{
await next(context);
}
else if (_sessionManager.IsCurrentActiveToken())
{
_sessionManager.UpdateTokenExpiryTime();
await next(context);
}
context.Response.StatusCode = (int)HttpStatusCode.OK;
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(new ErrorDetails()
{
StatusCode = (int)HttpStatusCode.Unauthorized,
Type = 3,
Message = "Expired Token"
}.ToString());
}
Update: My code works perfectly fine if i remove the middleware , The issue is not because of the transfer-encoding = chunked. But the middleware is very important to my code
Problem Resolved: The issue was that my backend was taking a lot of time to give the response So, i had to optimize the code so that it gives the output under 300 ms of time