-  private Uri mUri;\r
-  private Credentials mCredentials;
-  final private static String TAG = "WebdavClient";\r
-  private static final String USER_AGENT = "Android-ownCloud";
-  
-  public WebdavClient(Uri uri) {
-    mUri = uri;\r
-    getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
-  }
-  
-  public void setCredentials(String username, String password) {\r
-    getParams().setAuthenticationPreemptive(true);
-    getState().setCredentials(AuthScope.ANY, getCredentials(username, password));
-  }
-  
-  private Credentials getCredentials(String username, String password) {\r
-    if (mCredentials == null)\r
-      mCredentials = new UsernamePasswordCredentials(username, password); \r
-    return mCredentials;\r
-  }\r
-\r
-  public void allowUnsignedCertificates() {
-    // https\r
-    Protocol.registerProtocol("https", new Protocol("https", new EasySSLSocketFactory(), 443));
-  }
-  
-  public boolean downloadFile(String filepath, File targetPath) {
-    //HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ", "%20"));\r
-   \r
-    Log.e("ASD", mUri.toString() + URLDecoder.decode(filepath) + "");\r
-    GetMethod get = new GetMethod(mUri.toString() + URLEncoder.encode(filepath));\r
+    private static final int MAX_REDIRECTIONS_COUNT = 3;
+    
+    private Uri mUri;
+    private Credentials mCredentials;
+    private boolean mFollowRedirects;
+    private String mSsoSessionCookie;
+    private String mAuthTokenType;
+    final private static String TAG = "WebdavClient";
+    public static final String USER_AGENT = "Android-ownCloud";
+    
+    static private byte[] sExhaustBuffer = new byte[1024];
+    
+    /**
+     * Constructor
+     */
+    public WebdavClient(HttpConnectionManager connectionMgr) {
+        super(connectionMgr);
+        Log_OC.d(TAG, "Creating WebdavClient");
+        getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
+        getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
+        mFollowRedirects = true;
+        mSsoSessionCookie = null;
+        mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD;
+    }
+
+    public void setBearerCredentials(String accessToken) {
+        AuthPolicy.registerAuthScheme(BearerAuthScheme.AUTH_POLICY, BearerAuthScheme.class);
+        
+        List<String> authPrefs = new ArrayList<String>(1);
+        authPrefs.add(BearerAuthScheme.AUTH_POLICY);
+        getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);        
+        
+        mCredentials = new BearerCredentials(accessToken);
+        getState().setCredentials(AuthScope.ANY, mCredentials);
+        mSsoSessionCookie = null;
+        mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN;
+    }
+
+    public void setBasicCredentials(String username, String password) {
+        List<String> authPrefs = new ArrayList<String>(1);
+        authPrefs.add(AuthPolicy.BASIC);
+        getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);        
+        
+        getParams().setAuthenticationPreemptive(true);
+        mCredentials = new UsernamePasswordCredentials(username, password);
+        getState().setCredentials(AuthScope.ANY, mCredentials);
+        mSsoSessionCookie = null;
+        mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD;
+    }