Skip to end of metadata
Go to start of metadata

Since Android SDK build it is possible to add custom HTTP headers while establishing Websocket connection to WCS server. To do this, use the following function

Session.connect(Connection connection, java.util.Map<java.lang.String,java.lang.String> customHeaders)

Suppose that Websocket traffic proxying with user authentication is configured on the server using nginx. In this case, user credentials should be passed in Websocket URL


Authorization HTTP header should be formed from Websocket URL as follows:


    private Map<String, String> getBasicAuthHeader(String url) {
        if (url.contains("@")) {
            String authorization = url.substring(url.indexOf(":")+3, url.indexOf("@"));
            String base64Auth = Base64.getEncoder().encodeToString(authorization.getBytes());
            String header = "Basic " + base64Auth;
            Map<String, String> basicAuthheader = new HashMap<>();
            basicAuthheader.put("Authorization", header);

            return basicAuthheader;

        return null;

and should be sent while connecting to the server


                    session.connect(new Connection(), getBasicAuthHeader(url));