I just realized there can be a bit easier solution to this issue.
$tyk_context contains headers_Host
value already, so maybe you can do it without middleware like this:
"url_rewrites": [
{
"path": "/.*",
"method": "POST",
"match_pattern": "/(.*)",
"rewrite_to": "$tyk_context.headers_Host/$1",
"triggers": []
}
],