Grrrr
Grrrr

Reputation: 2536

Sending a response without calling render() from a Mojolicious::Lite application

I am writing a "partial proxy" in Mojolicious::Lite. Certain requests (depending on the query path, and on the values of the parameters) generate a request to another server, while others are handled locally.

There is a nice proxy example, but it totally overrides the request/response handling and thus is not suitable to my needs.

Currently, I am marshalling the response via

$self->render(data => $res->body, code => $res->code);

Unfortunately, this does not take into account different content types. Using Mojolicious::Type does not help, because I need a reverse mapping from the content type in $res to the format in render(); besides, the number of possible render formats is significantly smaller than the number of possible content types.

So ideally, instead of the $self->render() call above I need a way to say "here, I got a response in $res; please return it back to the client as is".

Any ideas? Thanks!

Upvotes: 1

Views: 508

Answers (1)

Grrrr
Grrrr

Reputation: 2536

Ok, the trick was to replace render() call with

$self->tx->res($res);
$self->rendered($res->code);

Upvotes: 4

Related Questions