jclouds-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ignasi Barrera <ignasi.barr...@gmail.com>
Subject Re: Re:Is there any way to add custom headers on HTTP headers to Rackspace Cloudfiles?
Date Thu, 02 Feb 2017 22:36:31 GMT
Hi Jeff,

There is no default way to add arbitrary headers to the requests generated
by jclouds. The approach I'd recommend is to use the OkHttp driver and its
interceptor mechanism. Here is how you can set it up:

* First, configure the OkHttp driver when creating the context by adding
its module to the list of modules, as explained in the driver's README [1].
* Then, create your OkHttp interceptor class that will add the required
headers. You will find good examples here [2].
* Finally, initialize the OkHttp client used by the driver to use your
interceptor. You can do this by adding a custom module to the list of
modules used to create the context. It could be something like:

*Module customInterceptorModule = new AbstractModule() {   @Override
 protected void configure() {
bind(OkHttpClientSupplier.class).toInstance(new OkHttpClientSupplier() {
     @Override         public OkHttpClient get() {            OkHttpClient
client = new OkHttpClient();            client.interceptors().add(new
MyInterceptor());            return client;         }      });   }};*

*ContextBuilder.newBuilder("provider")   .endpoint("endpoint")
 .credentials("identity", "credential")   .modules(ImmutableSet.of(new
OkHttpCommandExecutorServiceModule(), customInterceptorModule))*
*   .build();*



[1] https://github.com/jclouds/jclouds/tree/master/drivers/okhttp
[2] https://github.com/square/okhttp/wiki/Interceptors

On 2 February 2017 at 22:35, Andrew Phillips <aphillips@qrmedia.com> wrote:

> Er, that should have been "user@..." - sorry!
> ap
> -------- Original Message --------
> Subject: Re:Is there any way to add custom headers on HTTP headers to
> Rackspace Cloudfiles?
> Date: 2017-02-02 15:59
> From: Andrew Phillips <andrewp@apache.org>
> To: users@jclouds.apache.org
> Copy: jwolfeld@gmail.com
> [Forwarding Jeff's email to users@. @Jeff: notifications@ is just for
> automated emails.]
> "In order to troubleshoot some issues downloading objects from Rackspace
> Cloudfiles, they are requesting that I add a "x-trans-id" header to my API
> requests.  Is there any way to instruct the jclouds client library to do
> this for me?  Seems like it should be straightforward to insert a custom
> HTTP header, but I can't find any way to do it."

View raw message