Borislav Nikolaev Borislav Nikolaev - 9 months ago 86
HTTP Question

Not getting Range header

I am trying to resume an upload from google drive, I have the id of the file when I close the connection I make this session after the Internet is connected again:

var request = (HttpWebRequest)WebRequest.Create(fileUri);
request.Method = "PUT";
request.ContentLength = 0;
request.Headers.Add("Content-Range", "bytes */" + FileByteArray.Length);
var response = request.GetResponse();
catch (WebException e)
fileRange = e.Response.Headers.Get("Range");


I am not getting the Range header, why is that?

Answer Source

Content-Range indicates which range of the original entity is contained in the body of either a request (like your PUT request) or a 206 partial response. Range is set by the client not the server in order to request a sub-range. I would assume that the server you are talking to will not respond with the uploaded chunk, so a Content-Range (and Range in no case) will not be present as a response header.

In your code snippet the actual upload range is missing for Content-Range (see the updated HTTP RFC). It has to have the form of:

Content-Range: bytes 42-1233/1234

which means: upload byte 42-1233 of an entity whose total size is 1234 byte.

Or when the complete length is unknown:

 Content-Range: bytes 42-1233/*

So remove the check for the Range header and specify the complete upload range and you should be fine.