Skip to content

Commit

Permalink
Rename MqttWebSocketConfig.getHttpHeaders -> getHeaders
Browse files Browse the repository at this point in the history
Rename MqttWebSocketConfig.DEFAULT_HTTP_HEADERS -> DEFAULT_HEADERS
Rename MqttWebSocketConfigBuilderBase.httpHeaders -> headers
  • Loading branch information
SgtSilvio committed Nov 20, 2023
1 parent 19d34cb commit 3f2b6cb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface MqttWebSocketConfig {
*
* @since 1.2.3
*/
@Unmodifiable @NotNull Map<@NotNull String, @NotNull String> DEFAULT_HTTP_HEADERS = Collections.emptyMap();
@Unmodifiable @NotNull Map<@NotNull String, @NotNull String> DEFAULT_HEADERS = Collections.emptyMap();

/**
* Creates a builder for a WebSocket configuration.
Expand Down Expand Up @@ -97,7 +97,7 @@ public interface MqttWebSocketConfig {
* @return map of already set headers.
* @since 1.2.3
*/
@Unmodifiable @NotNull Map<@NotNull String, @NotNull String> getHttpHeaders();
@Unmodifiable @NotNull Map<@NotNull String, @NotNull String> getHeaders();

/**
* Creates a builder for extending this WebSocket configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public interface MqttWebSocketConfigBuilderBase<B extends MqttWebSocketConfigBui
@NotNull B handshakeTimeout(long timeout, @NotNull TimeUnit timeUnit);

/**
* Sets the {@link MqttWebSocketConfig#getHttpHeaders() headers}.
* Sets the {@link MqttWebSocketConfig#getHeaders() headers}.
*
* @param httpHeaders http headers.
* @param headers http headers.
* @return the builder.
*/
@CheckReturnValue
@NotNull B httpHeaders(@NotNull Map<@NotNull String, @NotNull String> httpHeaders);
@NotNull B headers(@NotNull Map<@NotNull String, @NotNull String> headers);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ public class MqttWebSocketConfigImpl implements MqttWebSocketConfig {

static final @NotNull MqttWebSocketConfigImpl DEFAULT =
new MqttWebSocketConfigImpl(DEFAULT_PATH, DEFAULT_QUERY, DEFAULT_SUBPROTOCOL, DEFAULT_HANDSHAKE_TIMEOUT_MS,
DEFAULT_HTTP_HEADERS);
DEFAULT_HEADERS);

private final @NotNull String path;
private final @NotNull String query;
private final @NotNull String subprotocol;
private final @Range(from = 0, to = Integer.MAX_VALUE) int handshakeTimeoutMs;
private final @Unmodifiable @NotNull Map<@NotNull String, @NotNull String> httpHeaders;
private final @Unmodifiable @NotNull Map<@NotNull String, @NotNull String> headers;

MqttWebSocketConfigImpl(
final @NotNull String path,
final @NotNull String query,
final @NotNull String subprotocol,
final @Range(from = 0, to = Integer.MAX_VALUE) int handshakeTimeoutMs,
final @Unmodifiable @NotNull Map<@NotNull String, @NotNull String> httpHeaders) {
final @Unmodifiable @NotNull Map<@NotNull String, @NotNull String> headers) {

this.path = path;
this.query = query;
this.subprotocol = subprotocol;
this.handshakeTimeoutMs = handshakeTimeoutMs;
this.httpHeaders = httpHeaders;
this.headers = headers;
}

@Override
Expand All @@ -76,8 +76,8 @@ public class MqttWebSocketConfigImpl implements MqttWebSocketConfig {
}

@Override
public @Unmodifiable @NotNull Map<@NotNull String, @NotNull String> getHttpHeaders() {
return httpHeaders;
public @Unmodifiable @NotNull Map<@NotNull String, @NotNull String> getHeaders() {
return headers;
}

@Override
Expand All @@ -96,7 +96,7 @@ public boolean equals(final @Nullable Object o) {
final MqttWebSocketConfigImpl that = (MqttWebSocketConfigImpl) o;

return path.equals(that.path) && query.equals(that.query) && subprotocol.equals(that.subprotocol) &&
(handshakeTimeoutMs == that.handshakeTimeoutMs) && httpHeaders.equals(that.httpHeaders);
(handshakeTimeoutMs == that.handshakeTimeoutMs) && headers.equals(that.headers);
}

@Override
Expand All @@ -105,7 +105,7 @@ public int hashCode() {
result = 31 * result + query.hashCode();
result = 31 * result + subprotocol.hashCode();
result = 31 * result + Integer.hashCode(handshakeTimeoutMs);
result = 31 * result + httpHeaders.hashCode();
result = 31 * result + headers.hashCode();
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public abstract class MqttWebSocketConfigImplBuilder<B extends MqttWebSocketConf
private @NotNull String subprotocol = MqttWebSocketConfigImpl.DEFAULT_SUBPROTOCOL;
private @Range(from = 0, to = Integer.MAX_VALUE) int handshakeTimeoutMs =
MqttWebSocketConfigImpl.DEFAULT_HANDSHAKE_TIMEOUT_MS;
private @Unmodifiable @NotNull Map<@NotNull String, @NotNull String> httpHeaders =
MqttWebSocketConfigImpl.DEFAULT_HTTP_HEADERS;
private @Unmodifiable @NotNull Map<@NotNull String, @NotNull String> headers =
MqttWebSocketConfigImpl.DEFAULT_HEADERS;

MqttWebSocketConfigImplBuilder() {}

Expand Down Expand Up @@ -78,15 +78,15 @@ public abstract class MqttWebSocketConfigImplBuilder<B extends MqttWebSocketConf
return self();
}

public @NotNull B httpHeaders(final @Nullable Map<@Nullable String, @Nullable String> httpHeaders) {
Checks.notNull(httpHeaders, "Http headers");
public @NotNull B headers(final @Nullable Map<@Nullable String, @Nullable String> headers) {
Checks.notNull(headers, "Headers");
// TODO check nullability of elements
this.httpHeaders = Collections.unmodifiableMap(new LinkedHashMap<>(httpHeaders));
this.headers = Collections.unmodifiableMap(new LinkedHashMap<>(headers));
return self();
}

public @NotNull MqttWebSocketConfigImpl build() {
return new MqttWebSocketConfigImpl(path, query, subprotocol, handshakeTimeoutMs, httpHeaders);
return new MqttWebSocketConfigImpl(path, query, subprotocol, handshakeTimeoutMs, headers);
}

public static class Default extends MqttWebSocketConfigImplBuilder<Default> implements MqttWebSocketConfigBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ public void initChannel(
return;
}

final Map<String, String> httpHeaders = webSocketConfig.getHttpHeaders();
final DefaultHttpHeaders headers;
if (httpHeaders.isEmpty()) {
headers = null;
final Map<String, String> headers = webSocketConfig.getHeaders();
final DefaultHttpHeaders httpHeaders;
if (headers.isEmpty()) {
httpHeaders = null;
} else {
headers = new DefaultHttpHeaders();
httpHeaders.forEach(headers::set);
httpHeaders = new DefaultHttpHeaders();
headers.forEach(httpHeaders::set);
}

final WebSocketClientHandshaker handshaker =
WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13,
webSocketConfig.getSubprotocol(), true, headers,
webSocketConfig.getSubprotocol(), true, httpHeaders,
MqttVariableByteInteger.MAXIMUM_PACKET_SIZE_LIMIT, true, false);

channel.pipeline()
Expand Down

0 comments on commit 3f2b6cb

Please sign in to comment.