2

I am new to Vertx, I am writing a proxy server, which will take request, update header, and send to another server. On receiving response, send the complete response as it is to client.

In vertx, Is there a way I do this straign forward or I need to implement handler for each http method and content type, to create new request and send using new client?

1 Answers1

1

If you are using vertx-web of version 3.x and below, then you can do:

void redirect( RoutingContext rc, String url ) {
  if( !rc.response().ended() ) 
    rc.response().setStatusCode( 303 ).putHeader( 'Location', url ).end()
}
injecteer
  • 20,038
  • 4
  • 45
  • 89
  • 3
    in vert.x 4 there's a similar method on the `RoutingContext` so you can just do: `ctx.redirect(destination)` – Paulo Lopes Nov 13 '20 at 08:39
  • @injecteer I tried, `rc.response().setStatusCode( 303 ).putHeader( 'Location', url ).end()` I tried with status code 307, 308 also since http method is post. I am also setting jwt token in header `.putHeader( "Authorization","Bearer "+token)`. But on target server, (non vertx) its throwing 401, with message "Authentication header value is not valid". How can set correct header with jwt token ? – Abhay Mishra Nov 16 '20 at 11:08
  • you can add your token as GET param: `putHeader( 'Location', url + '/' + token )` – injecteer Nov 16 '20 at 11:25
  • 1
    I don't think a client can delegate headers to the other server, only the url, so you can use standard redirect functionality or re-issue the request from client using ajax or alike – injecteer Nov 16 '20 at 11:36
  • Thanks, since I am using vertx 3.9, I used the suggested solution and Redirect works. – Abhay Mishra Nov 16 '20 at 12:00