package net.gotev.uploadservice;

import android.content.Context;
import android.content.Intent;
import android.util.Base64;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import net.gotev.uploadservice.HttpUploadRequest;
/* loaded from: classes.dex */
public abstract class HttpUploadRequest<B extends HttpUploadRequest<B>> extends UploadRequest<B> {
    protected final HttpUploadTaskParameters httpParams;

    public HttpUploadRequest(Context context, String str, String str2) throws MalformedURLException, IllegalArgumentException {
        super(context, str, str2);
        this.httpParams = new HttpUploadTaskParameters();
        if (!this.params.getServerUrl().startsWith("http://") && !this.params.getServerUrl().startsWith("https://")) {
            throw new IllegalArgumentException("Specify either http:// or https:// as protocol");
        }
        new URL(this.params.getServerUrl());
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // net.gotev.uploadservice.UploadRequest
    public void initializeIntent(Intent intent) {
        super.initializeIntent(intent);
        intent.putExtra("httpTaskParameters", this.httpParams);
    }

    public B addHeader(String str, String str2) {
        this.httpParams.addRequestHeader(str, str2);
        return (B) self();
    }

    public B setBasicAuth(String str, String str2) {
        String encodeToString = Base64.encodeToString((str + ":" + str2).getBytes(), 2);
        HttpUploadTaskParameters httpUploadTaskParameters = this.httpParams;
        httpUploadTaskParameters.addRequestHeader("Authorization", "Basic " + encodeToString);
        return (B) self();
    }

    public B addParameter(String str, String str2) {
        this.httpParams.addRequestParameter(str, str2);
        return (B) self();
    }

    public B addArrayParameter(String str, String... strArr) {
        for (String str2 : strArr) {
            this.httpParams.addRequestParameter(str, str2);
        }
        return (B) self();
    }

    public B addArrayParameter(String str, List<String> list) {
        for (String str2 : list) {
            this.httpParams.addRequestParameter(str, str2);
        }
        return (B) self();
    }

    public B setMethod(String str) {
        this.httpParams.setMethod(str);
        return (B) self();
    }

    public B setCustomUserAgent(String str) {
        this.httpParams.setCustomUserAgent(str);
        return (B) self();
    }

    public B setUsesFixedLengthStreamingMode(boolean z) {
        this.httpParams.setUsesFixedLengthStreamingMode(z);
        return (B) self();
    }
}
