Re: Re:Is there any way to add custom headers on HTTP headers to Rackspace Cloudfiles?
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();* HTH! I. [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 <aphill...@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 <andr...@apache.org> > To: us...@jclouds.apache.org > Copy: jwolf...@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." >
Fwd: Re:Is there any way to add custom headers on HTTP headers to Rackspace Cloudfiles?
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 <andr...@apache.org> To: us...@jclouds.apache.org Copy: jwolf...@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."
Re: HTTP Headers
Hi Andrew, Thank you for your response. I will put it on my list of TODOs for sure. Sincerely, Ashkan On 11/10/16, 5:19 PM, "Andrew Gaul" <g...@apache.org> wrote: >jclouds does not allow arbitrary HTTP headers; we generally provide a >mechanism to set any vendor-specific header in the provider >implementation. Specifically for User-Agent, we have an open feature >request: > >https://issues.apache.org/jira/browse/JCLOUDS-819 > >This is a well-scoped task and we would appreciate a pull request to >include it. Would you be willing to address this? > >On Thu, Nov 10, 2016 at 09:27:45PM +, Paya, Ashkan wrote: >> Hello, >> >> Can we use/overwrite HTTP headers such as USER_AGENT when invoking methods >> like BlobStore.putBlob() or we need to specify the BlobRequestSigner and use >> HttpClient instead? >> For example, if I want to include the HTTP headers in the following >> operation: >> >> >> ByteSource input = ByteSource.wrap(“BLAH”.getBytes(StandardCharsets.UTF_8)); >> >> Blob blob = blobStore >> >> >> .blobBuilder(“NAME") >> >> >> .payload(input) >> >> >> .contentLength(input.size()) >> >> >> .contentMD5(input.hash(Hashing.md5())) >> >> >> .contentType("text/plain") >> >> >> .build(); >> >> >> blobStore.putBlob(container, blob); >> >> >> Should I use the BlobRequestSigner as follows? Is this the right approach? >> >> >> final BlobRequestSigner signer = blobStoreInfo.getBlobRequestSigner(); >> >> >> HttpRequest request = signer.signPutBlob(container, blob) >> >> >> .toBuilder() >> >> >> .addHeader(HttpHeaders.CONTENT_LENGTH, >> >> >> String.valueOf(input.size())) >> >> >> .addHeader(HttpHeaders.USER_AGENT, “custom agent") >> >> >> .payload(input) >> >> >> .build(); >> >> >> HttpClient httpClient = blobStore.getContext().utils().http()); >> >> httpClient.invoke(request); >> >> >> >> >> >> Thank you, >> Ashkan > >-- >Andrew Gaul >http://gaul.org/
HTTP Headers
Hello, Can we use/overwrite HTTP headers such as USER_AGENT when invoking methods like BlobStore.putBlob() or we need to specify the BlobRequestSigner and use HttpClient instead? For example, if I want to include the HTTP headers in the following operation: ByteSource input = ByteSource.wrap(“BLAH”.getBytes(StandardCharsets.UTF_8)); Blob blob = blobStore .blobBuilder(“NAME") .payload(input) .contentLength(input.size()) .contentMD5(input.hash(Hashing.md5())) .contentType("text/plain") .build(); blobStore.putBlob(container, blob); Should I use the BlobRequestSigner as follows? Is this the right approach? final BlobRequestSigner signer = blobStoreInfo.getBlobRequestSigner(); HttpRequest request = signer.signPutBlob(container, blob) .toBuilder() .addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(input.size())) .addHeader(HttpHeaders.USER_AGENT, “custom agent") .payload(input) .build(); HttpClient httpClient = blobStore.getContext().utils().http()); httpClient.invoke(request); Thank you, Ashkan