You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by "Paya, Ashkan" <As...@dell.com> on 2016/11/10 21:27:45 UTC

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

Re: HTTP Headers

Posted by "Paya, Ashkan" <As...@dell.com>.
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" <ga...@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 +0000, 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/

Re: HTTP Headers

Posted by Andrew Gaul <ga...@apache.org>.
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 +0000, 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(\u201cBLAH\u201d.getBytes(StandardCharsets.UTF_8));
> 
>  Blob blob = blobStore
> 
> 
>     .blobBuilder(\u201cNAME")
> 
> 
>     .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, \u201ccustom agent")
> 
> 
>     .payload(input)
> 
> 
>     .build();
> 
> 
>  HttpClient httpClient = blobStore.getContext().utils().http());
> 
> httpClient.invoke(request);
> 
> 
> 
> 
> 
> Thank you,
> Ashkan

-- 
Andrew Gaul
http://gaul.org/

Re: HTTP Headers

Posted by "Paya, Ashkan" <As...@dell.com>.
Hi Andrew,

No there is no error or problem with the headers that jclouds sets. I just want to add a custom user-agent string to all put/get requests for some analysis/tracking purposes.

Sincerely,
Ashkan



On 11/10/16, 1:30 PM, "Andrew Phillips" <an...@apache.org> wrote:

>Hi Ashkan
>
>> Can we use/overwrite HTTP headers such as USER_AGENT when invoking
>> methods like BlobStore.putBlob()
>
>Just out of curiosity: what is your use case here? Do things not work 
>with the headers that jclouds sets? If so, what is the error?
>
>Regards
>
>ap

Re: HTTP Headers

Posted by Andrew Phillips <an...@apache.org>.
Hi Ashkan

> Can we use/overwrite HTTP headers such as USER_AGENT when invoking
> methods like BlobStore.putBlob()

Just out of curiosity: what is your use case here? Do things not work 
with the headers that jclouds sets? If so, what is the error?

Regards

ap