ChaithanyaGK commented on this pull request.


> @@ -779,6 +782,22 @@ private static void addHeader(Multimap<String, String> 
> headers, Headers header,
       return parts.build();
    }
 
+   private static GeneratedHttpRequest 
stripExpectHeaderIfContentZero(GeneratedHttpRequest request) {
+      boolean isBodyEmpty = false;
+      if (request.getPayload() != null) {
+         Long length = 
request.getPayload().getContentMetadata().getContentLength();
+         if (length != null && length == 0) {
+            isBodyEmpty = true;
+         }
+      } else {
+         isBodyEmpty = true;
+      }

@nacx I've debugged this further and below are my findings:

1. `content-length` is always set for non-stream payloads like 
[String](https://github.com/jclouds/jclouds/blob/0bc935dd57dc8009731d05c533edd831c8642664/core/src/main/java/org/jclouds/io/payloads/StringPayload.java#L38),
  
[ByteArray](https://github.com/jclouds/jclouds/blob/4bbca9edf943852ce1ea5aa579fa0554f770a3ea/core/src/main/java/org/jclouds/io/payloads/ByteArrayPayload.java#L31)
 etc.,
2. The only scenario I'm worried is in the case of `chunked` transfer with 
Stream payloads (like 
[InputStream](https://github.com/jclouds/jclouds/blob/4bbca9edf943852ce1ea5aa579fa0554f770a3ea/core/src/main/java/org/jclouds/io/payloads/InputStreamPayload.java#L23),
 [ByteSource 
](https://github.com/jclouds/jclouds/blob/4bbca9edf943852ce1ea5aa579fa0554f770a3ea/core/src/main/java/org/jclouds/io/payloads/ByteSourcePayload.java#L30)etc.,
 ) how to check the body is empty?

Just to verify the case, I tried to do azure putBlob without setting the 
content-length for ByteSource payload:

```
ByteSource payload = ByteSource.wrap("testdata".getBytes(Charsets.UTF_8));
Blob blob = blobStore.blobBuilder(blobName)
                        .payload(payload)
                        //.contentLength(payload.size())
                        .build();
blobStore.putBlob(containerName, blob);
```

I'm getting the below error saying I've to specify the content-length (which is 
not the case with non-stream payloads):
```
Exception in thread "main" java.lang.IllegalArgumentException: size must be set
        at 
com.google.common.base.Preconditions.checkArgument(Preconditions.java:125)
        at 
org.jclouds.azureblob.binders.BindAzureBlobMetadataToRequest.bindToRequest(BindAzureBlobMetadataToRequest.java:56)
        at 
org.jclouds.rest.internal.RestAnnotationProcessor.decorateRequest(RestAnnotationProcessor.java:660)
        at 
org.jclouds.rest.internal.RestAnnotationProcessor.apply(RestAnnotationProcessor.java:354)
        at 
org.jclouds.rest.internal.RestAnnotationProcessor.apply(RestAnnotationProcessor.java:137)
```
So, I'm wondering whether there would be a scenario where content-length is not 
set ?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/1120#discussion_r128252872

Reply via email to