How make sure that the for 307 http code the Buffer body of the redirected url

37 views
Skip to first unread message

Prince

unread,
Aug 7, 2018, 8:15:58 AM8/7/18
to vert.x
Hi all,

I am using some API in my project which sometimes becomes unavailable but the client will provide an alternate link for that API as 307 status code. 

My understanding is that if I set "setFollowRedirects(true)" as true then when I am reading the buffer the buffer should contain the body of redirected API link. But this is not what is happening. 

Can anyone help me on this 

The code Snippet is as follows
HttpClientRequest  httpClientRequest =  clien.requestAbs(Methord,APIURI.toString(),response ->{
         
Buffer totalBuffer = Buffer.buffer();
         response
.handler(buffer -> {
             totalBuffer
.append(buffer);
         
}
         response
.endHandler((v) -> {
             ///logic using the totalBuffer.
         
});
});
httpClientRequest
.setFollowRedirects(true).end();


If my understanding is wrong the is there any way that I could use the buffer of redirect URI

Regards

Julien Viet

unread,
Aug 7, 2018, 9:00:37 AM8/7/18
to ve...@googlegroups.com
Hi,

the current redirect logic does not take this in account, it reads the redirect URL from the Location header.

you can set your own redirect handler logic to achieve it by calling the HttpClient#redirectHandler(Function<HttpClientResponse, Future<HttpClientRequest>) and do pretty much what you want

HTH

Julien



--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/ca0ced6e-2d85-4f8b-b2fc-7ff2f215051d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paulo Lopes

unread,
Aug 7, 2018, 10:01:16 AM8/7/18
to vert.x
The semantics of redirect do not look at the response body, just to the `Location` header and the status code.

For more info see:


The only way to redirect using the body is for user agents (browsers) which will parse the HTML and look at the meta fields in the head of the document.

Prajeesh K P

unread,
Aug 7, 2018, 10:07:28 AM8/7/18
to ve...@googlegroups.com
Hi Paul 

The problem is that a bunch of my code is based on the result of that API call response. Since that is unavailable for sometime the project is effectively having down time. 

Is there any work around that I could make sure I can caputre the response of that redirect also.

Regards



--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.

Prajeesh K P

unread,
Aug 8, 2018, 1:34:26 AM8/8/18
to ve...@googlegroups.com, jul...@julienviet.com
Hi Julien,

I tried implementing the redirect Handler this thing works partially i.e For the first 307 response it doesn't work. But after that, this thing works fines.

I am attaching the latest implementation. I am doing something wrong.

HttpClientRequest  httpClientRequest =  client.requestAbs(Methord,APIURI.toString(),response ->{ 
             
client.redirectHandler(resp -> {
Future<HttpClientRequest> fut = Future.future();
HttpClientRequest req = client.requestAbs(Method,response.getHeader("Location").toString());
fut.complete(req);
return fut;
     });
             Buffer totalBuffer = Buffer.buffer();           
             response.handler(buffer -> {
             totalBuffer
.append(buffer);
       
         
}
         response
.endHandler((v) -> {
             ///logic using the totalBuffer.
         
});
});
httpClientRequest
.setFollowRedirects(true).end();  

Julien Viet

unread,
Aug 8, 2018, 3:21:01 AM8/8/18
to Prajeesh K P, ve...@googlegroups.com
you should complete the future in the response endHandler (and fail it in the response exceptionHandler).

Julien
Reply all
Reply to author
Forward
0 new messages