veron-li / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

AsyncResumableUploadData missing HTTP headers - causes server exceptions #552

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. call ResumableUpload.Insert with stream for payload, slug for file name

What is the expected output? What do you see instead?

the server will throw exceptions (411, etc)

What version of the product are you using? On what operating system?

.net library 1.9 on Win7

Please provide any additional information below.

The code has several bugs in ResumableUploader.PrepareRequest:

1. Missing GData-Version http header 
2. if slug is present, need to create a DocumentEntry XML node and add to the 
request 
3. if no slug, then ContentLength http header is missing. Need to set 
contentLength to 0

see below patched source code for the method: (the Gdata-version probably needs 
to be derived from DataGAuthRequestFactory.GDataVersion.... didn't have time...)

private HttpWebRequest PrepareRequest(Uri target,
            Authenticator authentication,
            string slug,
            string contentType,
            long contentLength,
            string httpMethod)
        {
            HttpWebRequest request = authentication.CreateHttpWebRequest(httpMethod, target);

            request.Headers.Add(GDataRequestFactory.ContentOverrideHeader + ": " + contentType);

            request.Headers.Add("GData-Version: 3.0");

            if (contentLength != -1)
            {
                request.Headers.Add(GDataRequestFactory.ContentLengthOverrideHeader + ": " + contentLength);
            }

            if (slug != null)
            {
                request.ContentType = "application/atom+xml";
                DocumentEntry en = new DocumentEntry();
                en.Title.Text = slug;
                en.SaveToXml(request.GetRequestStream());
            }

            else
            {
                request.ContentLength = 0;
            }

            return request;
        }

Original issue reported on code.google.com by m...@jobaline.com on 28 Oct 2011 at 2:32

GoogleCodeExporter commented 8 years ago
Your patched method hardcodes "GData-Version: 3.0", but this won't work with 
all APIs. Can it be dynamic instead?

The rest of the code seems fine, thanks for sending it

Original comment by ccherub...@google.com on 28 Oct 2011 at 4:39

GoogleCodeExporter commented 8 years ago
Gdata-vesrion needs to be derived from DataGAuthRequestFactory.GDataVersion

Original comment by m...@mullor.org on 28 Oct 2011 at 5:12

GoogleCodeExporter commented 8 years ago
Can you please provide a patch that handles the GData-Version parameter 
correctly?

Original comment by ccherub...@google.com on 28 Oct 2011 at 6:39

GoogleCodeExporter commented 8 years ago
Hi ,  how / from where  I wil use this?

Thanks for reply 

Original comment by mehmetol...@gmail.com on 22 Dec 2012 at 9:05