2005-03-23 jrandom
* Added support for Transfer-Encoding: chunked to the EepGet, so that the cvsweb.cgi doesn't puke on us.
This commit is contained in:
@ -47,6 +47,7 @@ public class EepGet {
|
|||||||
private long _bytesRemaining;
|
private long _bytesRemaining;
|
||||||
private int _currentAttempt;
|
private int _currentAttempt;
|
||||||
private String _etag;
|
private String _etag;
|
||||||
|
private boolean _encodingChunked;
|
||||||
|
|
||||||
public EepGet(I2PAppContext ctx, String proxyHost, int proxyPort, int numRetries, String outputFile, String url) {
|
public EepGet(I2PAppContext ctx, String proxyHost, int proxyPort, int numRetries, String outputFile, String url) {
|
||||||
this(ctx, true, proxyHost, proxyPort, numRetries, outputFile, url);
|
this(ctx, true, proxyHost, proxyPort, numRetries, outputFile, url);
|
||||||
@ -304,13 +305,16 @@ public class EepGet {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Headers read completely, reading " + _bytesRemaining);
|
_log.debug("Headers read completely, reading " + _bytesRemaining);
|
||||||
|
|
||||||
|
int remaining = (int)_bytesRemaining;
|
||||||
byte buf[] = new byte[1024];
|
byte buf[] = new byte[1024];
|
||||||
while (_keepFetching) {
|
while (_keepFetching && remaining > 0) {
|
||||||
int read = _proxyIn.read(buf);
|
int toRead = buf.length;
|
||||||
|
int read = _proxyIn.read(buf, 0, (buf.length > remaining ? remaining : buf.length));
|
||||||
if (read == -1)
|
if (read == -1)
|
||||||
break;
|
break;
|
||||||
_out.write(buf, 0, read);
|
_out.write(buf, 0, read);
|
||||||
_bytesTransferred += read;
|
_bytesTransferred += read;
|
||||||
|
remaining -= read;
|
||||||
if (read > 0)
|
if (read > 0)
|
||||||
for (int i = 0; i < _listeners.size(); i++)
|
for (int i = 0; i < _listeners.size(); i++)
|
||||||
((StatusListener)_listeners.get(i)).bytesTransferred(_alreadyTransferred, read, _bytesTransferred, _bytesRemaining, _url);
|
((StatusListener)_listeners.get(i)).bytesTransferred(_alreadyTransferred, read, _bytesTransferred, _bytesRemaining, _url);
|
||||||
@ -323,7 +327,7 @@ public class EepGet {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Done transferring " + _bytesTransferred);
|
_log.debug("Done transferring " + _bytesTransferred);
|
||||||
|
|
||||||
if (_bytesRemaining == _bytesTransferred) {
|
if ( (_bytesRemaining == -1) || (remaining == 0) ){
|
||||||
for (int i = 0; i < _listeners.size(); i++)
|
for (int i = 0; i < _listeners.size(); i++)
|
||||||
((StatusListener)_listeners.get(i)).transferComplete(_alreadyTransferred, _bytesTransferred, _bytesRemaining, _url, _outputFile);
|
((StatusListener)_listeners.get(i)).transferComplete(_alreadyTransferred, _bytesTransferred, _bytesRemaining, _url, _outputFile);
|
||||||
} else {
|
} else {
|
||||||
@ -385,6 +389,9 @@ public class EepGet {
|
|||||||
if (isEndOfHeaders(lookahead)) {
|
if (isEndOfHeaders(lookahead)) {
|
||||||
if (!rcOk)
|
if (!rcOk)
|
||||||
throw new IOException("Invalid HTTP response code: " + responseCode);
|
throw new IOException("Invalid HTTP response code: " + responseCode);
|
||||||
|
if (_encodingChunked) {
|
||||||
|
readChunkLength();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -398,6 +405,36 @@ public class EepGet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void readChunkLength() throws IOException {
|
||||||
|
StringBuffer buf = new StringBuffer(8);
|
||||||
|
int nl = 0;
|
||||||
|
while (true) {
|
||||||
|
int cur = _proxyIn.read();
|
||||||
|
switch (cur) {
|
||||||
|
case -1:
|
||||||
|
throw new IOException("Chunk ended too soon");
|
||||||
|
case '\n':
|
||||||
|
case '\r':
|
||||||
|
nl++;
|
||||||
|
default:
|
||||||
|
buf.append((char)cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nl >= 2)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
String len = buf.toString().trim();
|
||||||
|
try {
|
||||||
|
long bytes = Long.parseLong(len, 16);
|
||||||
|
_bytesRemaining = bytes;
|
||||||
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Chunked length: " + bytes);
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
throw new IOException("Invalid chunk length [" + len + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parse the first status line and grab the response code.
|
* parse the first status line and grab the response code.
|
||||||
* e.g. "HTTP/1.1 206 OK" vs "HTTP/1.1 200 OK" vs
|
* e.g. "HTTP/1.1 206 OK" vs "HTTP/1.1 200 OK" vs
|
||||||
@ -438,6 +475,9 @@ public class EepGet {
|
|||||||
}
|
}
|
||||||
} else if (key.equalsIgnoreCase("ETag")) {
|
} else if (key.equalsIgnoreCase("ETag")) {
|
||||||
_etag = val.trim();
|
_etag = val.trim();
|
||||||
|
} else if (key.equalsIgnoreCase("Transfer-encoding")) {
|
||||||
|
if (val.indexOf("chunked") != -1)
|
||||||
|
_encodingChunked = true;
|
||||||
} else {
|
} else {
|
||||||
// ignore the rest
|
// ignore the rest
|
||||||
}
|
}
|
||||||
@ -505,6 +545,7 @@ public class EepGet {
|
|||||||
buf.append(_alreadyTransferred);
|
buf.append(_alreadyTransferred);
|
||||||
buf.append("-\n");
|
buf.append("-\n");
|
||||||
}
|
}
|
||||||
|
buf.append("Accept-Encoding: identity;q=1, *;q=0\n");
|
||||||
buf.append("Connection: close\n\n");
|
buf.append("Connection: close\n\n");
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Request: [" + buf.toString() + "]");
|
_log.debug("Request: [" + buf.toString() + "]");
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
$Id: history.txt,v 1.176 2005/03/23 20:51:58 Connelly Exp $
|
$Id: history.txt,v 1.177 2005/03/23 20:54:23 connelly Exp $
|
||||||
|
|
||||||
|
2005-03-23 jrandom
|
||||||
|
* Added support for Transfer-Encoding: chunked to the EepGet, so that the
|
||||||
|
cvsweb.cgi doesn't puke on us.
|
||||||
|
|
||||||
2005-03-23 Connelly
|
2005-03-23 Connelly
|
||||||
* Fixed Bugzilla Bug #99 in the SAM Bridge, which caused pending
|
* Fixed Bugzilla Bug #99 in the SAM Bridge, which caused pending
|
||||||
|
@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RouterVersion {
|
public class RouterVersion {
|
||||||
public final static String ID = "$Revision: 1.169 $ $Date: 2005/03/23 16:13:05 $";
|
public final static String ID = "$Revision: 1.170 $ $Date: 2005/03/23 20:19:53 $";
|
||||||
public final static String VERSION = "0.5.0.3";
|
public final static String VERSION = "0.5.0.3";
|
||||||
public final static long BUILD = 3;
|
public final static long BUILD = 4;
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
System.out.println("I2P Router version: " + VERSION);
|
System.out.println("I2P Router version: " + VERSION);
|
||||||
System.out.println("Router ID: " + RouterVersion.ID);
|
System.out.println("Router ID: " + RouterVersion.ID);
|
||||||
|
Reference in New Issue
Block a user