Moved http response header set to the end of endpoint func