All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.datahub.client.http.interceptor.HttpAuthInterceptor Maven / Gradle / Ivy

The newest version!
package com.aliyun.datahub.client.http.interceptor;

import com.aliyun.datahub.client.auth.Account;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

public class HttpAuthInterceptor implements Interceptor {
    private final Account account;

    public HttpAuthInterceptor( Account account) {
        this.account = account;
    }

    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        Request request = addAuthHeaders(chain.request());
        return chain.proceed(request);
    }

    private Request addAuthHeaders(Request request) {
        if (this.account == null) {
            return request;
        }

        Request.Builder reqBuilder = request.newBuilder();
        account.addAuthHeaders(reqBuilder);
        return reqBuilder.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy