     private function onHttpHeaders(event:ProgressEvent):void {
       var parsed:* = request.readHeaders(socket, dataBuffer);
       if (false === parsed) {
+        return;
+      }
+
+      if (401 === parsed.code) {
+        Logger.log('Unauthorized using auth method: ' + authState);
+        /* Unauthorized, change authState and (possibly) try again */
+        authOpts = parsed.headers['www-authenticate'];
+        var newAuthState:String = auth.nextMethod(authState, authOpts);
+        if (authState === newAuthState) {
+          ErrorManager.dispatchError(parsed.code);
+          return;
+        }
+
+        Logger.log('switching http-authorization from ' + authState + ' to ' + newAuthState);
+        authState = newAuthState;
+        connect();
         return;
       }
 

  import com.axis.Logger;
  import com.axis.ErrorManager;
  import com.axis.http.request;

  [Event(name="image",type="flash.events.Event")]
  [Event(name="connect",type="flash.events.Event")]

      headers.length = 0;
      parseHeaders = true;
      parseSubheaders = true;

      var authHeader:String =
                    auth.authorizationHeader(method, authState, authOpts, urlParsed, digestNC++);

      socket.writeUTFBytes("GET " + urlParsed.urlpath + " HTTP/1.0\r\n");
      socket.writeUTFBytes("Host: " + urlParsed.host + ':' + urlParsed.port + "\r\n");
      socket.writeUTFBytes(authHeader);
      socket.writeUTFBytes("Accept: multipart/x-mixed-replace\r\n");
      socket.writeUTFBytes("User-Agent: Locomote\r\n");
      socket.writeUTFBytes("\r\n");
