Permalink
Browse files

Fixes for socket close and 204

  • Loading branch information...
1 parent e704570 commit c5db3ebe95c6824c1128b0c645385848064c69da @gabriel committed Mar 5, 2009
@@ -99,7 +99,8 @@ package org.httpclient {
_closed = true;
Log.debug("Called close");
_timer.stop();
- if (_socket) {
+ // Need to check if connected (otherwise closing on unconnected socket throws error)
+ if (_socket && _socket.connected) {
_socket.close();
_socket = null;
}
@@ -93,6 +93,9 @@ package org.httpclient.io {
_buffer.truncate();
_responseHeader = null;
_isPayloadDone = false;
+ } else if (_responseHeader.code == "204") {
+ // A 204 is a successful response with No Content
+ _hasResponseBody = false;
} else {
// Pass any extra as payload
var payload:ByteArray = _buffer.readAvailable();
@@ -114,9 +117,8 @@ package org.httpclient.io {
}
// Check if complete
- Log.debug("Payload done? " + _isPayloadDone);
- if (!_hasResponseBody) _onResponseComplete(_responseHeader);
- else if (_isPayloadDone) _onResponseComplete(_responseHeader);
+ Log.debug("Has response body? " + _hasResponseBody + "; Payload done? " + _isPayloadDone);
+ if (!_hasResponseBody || _isPayloadDone) _onResponseComplete(_responseHeader);
}
/**
View
@@ -26,7 +26,7 @@
var ts:TestSuite = new TestSuite();
// Toggle this for suite vs single test
- var singleTest:Boolean = true;
+ var singleTest:Boolean = false;
if (!singleTest) {
ts.addTest(new S3Tests());
@@ -98,15 +98,19 @@ package httpclient.http {
client.get(uri);
client.cancel();
// TODO(gabe): Assert canceled
+
+ client.listener.onClose = addAsync(function(event:Event):void {
+ Log.debug("On Close");
+ }, 20 * 1000);
}
public function testClose():void {
var client:HttpClient = new HttpClient();
var uri:URI = new URI("http://www.amazon.com/");
- client.listener.onClose = function(event:Event):void {
+ client.listener.onClose = addAsync(function(event:Event):void {
Log.debug("On Close");
- };
+ }, 5 * 1000);
client.listener.onComplete = function(event:Event):void {
Log.debug("On Complete");
@@ -127,7 +131,7 @@ package httpclient.http {
if (failListener) fail("Should be canceled");
};
- var uri:URI = new URI("http://www.amazon.com/");
+ var uri:URI = new URI("http://www.google.com/");
client.get(uri);
failListener = true;
@@ -141,11 +145,11 @@ package httpclient.http {
client1.listener.onComplete = addAsync(function(event:Event):void {
Log.debug("On Complete #1");
- }, 5 * 1000);
+ }, 10 * 1000);
client2.listener.onComplete = addAsync(function(event:Event):void {
Log.debug("On Complete #2");
- }, 5 * 1000);
+ }, 10 * 1000);
client1.get(new URI("http://www.google.com/"));
client2.get(new URI("http://www.yahoo.com/"));

0 comments on commit c5db3eb

Please sign in to comment.