   import com.axis.Logger;
   import com.axis.ErrorManager;
   import com.axis.http.request;
+  import com.axis.http.auth;
 
   [Event(name="image",type="flash.events.Event")]
   [Event(name="connect",type="flash.events.Event")]

    private var headers:Vector.<String> = new Vector.<String>();
    private var clen:int;
    private var parseSubheaders:Boolean = true;

    public var image:ByteArray = null;


    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;
      }

