Skip to content

Commit

Permalink
Added middleware to automatically use utf-8 if no content-type is in …
Browse files Browse the repository at this point in the history
…the response
  • Loading branch information
The-EDev committed Aug 15, 2021
1 parent 719ecfa commit 17819e6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions include/crow/middlewares/utf-8.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include "crow/http_request.h"
#include "crow/http_response.h"

namespace crow
{

struct UTF8
{
struct context
{
};

void before_handle(request& /*req*/, response& /*res*/, context& /*ctx*/)
{
}

void after_handle(request& /*req*/, response& res, context& ctx)
{
if (get_header_value(res.headers, "Content-Type").empty())
{
res.set_header("Content-Type", "text/plain; charset=utf-8");
}
}
};

}

0 comments on commit 17819e6

Please sign in to comment.