ManelBrull
ManelBrull

Reputation: 31

How to force read operation to request always the whole file

I'm currently upgrading our former webdav implementation to use IT-HIT.

In the process I noticed that read operation of a File can request the whole file or a part of it. I was wondering if there is a way to force to request always the whole file. Our webdav handles small files and there isn't much need for it.

I'm asking because in the documentation I'm using (Java client version 3.2.2420 ) I think it only specifies it for the write operation.

Thanks for your help.

Upvotes: 3

Views: 109

Answers (1)

Yaroslav Chyzh
Yaroslav Chyzh

Reputation: 174

The read operation is an HTTP GET request, which can contain a Range header. WebDAV clients as well as any other clients, like web browsers, can utilize GET requests to read and download file content. As part of the GET request, they can attach the Range header, specifying which part of the file content they want to get. For example, when you pause and then resume a download or when the download is broken and then restored, the Range request can be specified by the client:

GET https://webdavserv/file.ext 
Range: bytes=12345-45678

To test if the server supports the Range header, the client app can send the HEAD request. If the server response contains Accept-Ranges: bytes header, the Range header is supported:

HEAD https://webdavserv/file.ext 
...
Accept-Ranges: bytes

So the solution is to remove the Accept-Ranges header from the HEAD response. If the client can properly process the absence of the Accept-Ranges header, it will always request an entire file.

If you can not remove it directly from the code, in many cases you can remove or filter the header from the response before it is sent. The specific header removal code depends on your server (Java, ASP.NET, ASP.NET Core, OWIN, etc). For example for ASP.NET it will look like this:

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
    HttpContext.Current.Response.Headers.Remove("Accept-Ranges");
}

For Java, you will need to create a filter: How do delete a HTTP response header?

Upvotes: 6

Related Questions