javavert.xvertx-httpclient

Vertx HttpRequest .basicAuthentication() vs .putHeader("Authorization", "...")


Why does the following results in an "Unauthorized" response:

 webClient
            .getAbs("http://hello.com")
            .basicAuthentication("user", "pw")
            .rxSend()
            .subscribe();

Whereas the following works fine:

 webClient
                .getAbs("http://hello.com")
                .putHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("user:pw".getBytes()) )
                .rxSend()
                .subscribe();

Solution

  • This is the implementation for basicAuthentication

        Buffer buff = Buffer.buffer().appendBuffer(id).appendString("-").appendBuffer(password);
        String credentials =  new String(Base64.getEncoder().encode(buff.getBytes()));
        return putHeader(HttpHeaders.AUTHORIZATION.toString(), "Basic " + credentials);
    

    It puts user-pw not user:pw.