Skip to content

Introduce ConnectionInterceptor for individual connection processing#129

Open
vtuan10 wants to merge 3 commits into
Countly:masterfrom
vtuan10:interceptor
Open

Introduce ConnectionInterceptor for individual connection processing#129
vtuan10 wants to merge 3 commits into
Countly:masterfrom
vtuan10:interceptor

Conversation

@vtuan10

@vtuan10 vtuan10 commented Mar 1, 2021

Copy link
Copy Markdown

Motivation

Currently, it is only possible to set static http header values once. It is not possible to add header values which change with each network request.
We have the need to add headers which change with each request, because we sign each request (request method, request body and some other meta information) with a timestamp in our app.

What changed

Similarly to Okhttp, this introduces an interceptor interface ConnectionInterceptor to process each connection, i.e. add custom header which change with each request. It can be set at the beginning and will be called for each network request.

Example

ConnectionInterceptor interceptor = new ConnectionInterceptor() {
    @Override public HttpURLConnection intercept(HttpURLConnection connection, byte[] body) {
        connection.setRequestProperty("Prop", new Date().toString() + " super secret signature");
        return connection;
    }
};
Countly.sharedInstance().setConnectionInterceptor(interceptor)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet