2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.remoteopenhab.internal.rest;
15 import java.io.IOException;
17 import javax.ws.rs.client.ClientRequestContext;
18 import javax.ws.rs.client.ClientRequestFilter;
19 import javax.ws.rs.core.HttpHeaders;
20 import javax.ws.rs.core.MultivaluedMap;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
26 * Inserts Authorization and Cache-Control headers for requests on the streaming REST API.
28 * @author Laurent Garnier - Initial contribution
31 public class RemoteopenhabStreamingRequestFilter implements ClientRequestFilter {
33 private final String credentialToken;
35 public RemoteopenhabStreamingRequestFilter(String credentialToken) {
36 this.credentialToken = credentialToken;
40 public void filter(@Nullable ClientRequestContext requestContext) throws IOException {
41 if (requestContext != null) {
42 MultivaluedMap<String, Object> headers = requestContext.getHeaders();
43 if (!credentialToken.isEmpty()) {
44 headers.putSingle(HttpHeaders.AUTHORIZATION, "Basic " + credentialToken);
46 headers.putSingle(HttpHeaders.CACHE_CONTROL, "no-cache");