Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
Pass along the byte range and user agent headers through the proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Steele committed Jun 29, 2012
1 parent 7f7395c commit 9de9774
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/src/fm/last/android/player/StreamProxy.java
Expand Up @@ -139,11 +139,25 @@ private HttpRequest readRequest(Socket client) {
HttpRequest request = null;
InputStream is;
String firstLine;
String range = null;
String ua = null;
try {
is = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is),
8192);
firstLine = reader.readLine();

String line = null;

do {
line = reader.readLine();
if(line != null && line.toLowerCase().startsWith("range: ")) {
range = line.substring(7);
}
if(line != null && line.toLowerCase().startsWith("user-agent: ")) {
ua = line.substring(12);
}
} while(line != null && reader.ready());
} catch (IOException e) {
Log.e(LOG_TAG, "Error parsing request", e);
return request;
Expand All @@ -160,7 +174,11 @@ private HttpRequest readRequest(Socket client) {
Log.d(LOG_TAG, uri);
String realUri = uri.substring(1);
Log.d(LOG_TAG, realUri);
request = new BasicHttpRequest(method, realUri);
request = new BasicHttpRequest(method, realUri, new ProtocolVersion("HTTP", 1,1));
if(range != null)
request.addHeader("Range", range);
if(ua != null)
request.addHeader("User-Agent", ua);
return request;
}

Expand All @@ -180,6 +198,9 @@ private void processRequest(HttpRequest request, Socket client)
registry);
DefaultHttpClient http = new DefaultHttpClient(mgr, seed.getParams());
HttpGet method = new HttpGet(url);
for (Header h : request.getAllHeaders()) {
method.addHeader(h);
}
HttpResponse realResponse = null;
try {
Log.d(LOG_TAG, "starting download");
Expand Down

0 comments on commit 9de9774

Please sign in to comment.