determine if server supports resume get request

故事扮演 提交于 2019-12-02 15:51:55

To probe the download resume feature of a server, you may send a HEAD request to the server supplying a Range header with arbitrary values. If the response code is 206, then resume is supported.

Example with curl:

$ curl -i -X HEAD --header "Range: bytes=50-100" http://mirrors.melbourne.co.uk/ubuntu-releases//raring/ubuntu-13.04-desktop-amd64.iso

Update:

Here's an example in Java:

import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpClient;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;

public class ResumeChecker {

    public final static void main(String[] args) throws Exception {

        HttpClient httpclient = new DefaultHttpClient();
        HttpHead httpRequest = new HttpHead("http://www.google.com");
        httpRequest.addHeader(new BasicHeader("Range", "bytes=10-20"));

        System.out.println("Executing request " + httpRequest.getURI());

        HttpResponse response = httpclient.execute(httpRequest);

        // Check here that response.getStatusLine() contains 206 code
    }
}

However, I haven't tested it mysqlf.

Nika Kasradze

Adding to @aadel's answer:

Most of the servers nowadays respond with Accept-Ranges: bytes header in case they support resuming. RequestMaker or Insomnia can help you in examining request/response headers.

You can test it out, starting, stopping, then restarting a download:

curl --continue-at - http://... >> file.out

For whatever reason, this (from another answer) gave me a 403:

curl -i -X HEAD --header "Range: bytes=50-100" http://...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!