Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thin.downloadmanager;

import android.os.Process;
import android.webkit.URLUtil;

import com.thin.downloadmanager.util.Log;

Expand All @@ -12,10 +13,12 @@
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.net.Proxy;
import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;
Expand Down Expand Up @@ -134,7 +137,7 @@ private void executeDownload(DownloadRequest request, String downloadUrl) {
HttpURLConnection conn = null;

try {
conn = (HttpURLConnection) url.openConnection();
conn = (HttpURLConnection) url.openConnection(request.getProxy());
File destinationFile = new File(request.getDestinationURI().getPath());
if (destinationFile.exists()) {
mDownloadedCacheSize = (int) destinationFile.length();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.thin.downloadmanager;

import android.net.Uri;
import android.util.Patterns;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.HashMap;

/**
Expand Down Expand Up @@ -71,6 +74,8 @@ public enum Priority {

private boolean isDownloadResumable = false;

private Proxy mProxy= Proxy.NO_PROXY;

public DownloadRequest(Uri uri) {
if (uri == null) {
throw new NullPointerException();
Expand Down Expand Up @@ -103,6 +108,21 @@ public DownloadRequest setPriority(Priority priority) {
return this;
}

/**
* set proxy so the request will be sent through this proxy
* @param host
* @param port
* @return request
*/

public DownloadRequest setProxy(String host,int port){
this.mProxy=new Proxy(Proxy.Type.HTTP,InetSocketAddress.createUnresolved(host,port));
return this;
}
public Proxy getProxy(){
return mProxy;
}

/**
* Adds custom header to request
*
Expand Down