com.github.alexdlaird.ngrok.protocol.TunnelHeader Maven / Gradle / Ivy
/*
* Copyright (c) 2021-2024 Alex Laird
*
* SPDX-License-Identifier: MIT
*/
package com.github.alexdlaird.ngrok.protocol;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* An object that represents header configuration for a {@link CreateTunnel}.
*/
public class TunnelHeader {
private final List add;
private final List remove;
private TunnelHeader(final Builder builder) {
this.add = builder.add;
this.remove = builder.remove;
}
/**
* Get the list of headers to add.
*/
public List getAdd() {
return add;
}
/**
* Get the list of headers to remove.
*/
public List getRemove() {
return remove;
}
/**
* Builder for a {@link TunnelHeader}.
*/
public static class Builder {
private List add;
private List remove;
/**
* Construct a TunnelHeader Builder.
*/
public Builder() {
}
/**
* Construct a TunnelHeader Builder from tunnel definition of request_header
or
* response_header
.
*
* @param tunnelHeaderDefinition The map of Tunnel header attributes.
*/
public Builder(final Map tunnelHeaderDefinition) {
if (tunnelHeaderDefinition.containsKey("add")) {
this.add = Collections.unmodifiableList(
(List) tunnelHeaderDefinition.get("add")
);
}
if (tunnelHeaderDefinition.containsKey("remove")) {
this.remove = Collections.unmodifiableList(
(List) tunnelHeaderDefinition.get("remove")
);
}
}
/**
* The list of headers to add.
*/
public TunnelHeader.Builder withAdd(final List add) {
this.add = Collections.unmodifiableList(add);
return this;
}
/**
* The list of headers to remove.
*/
public TunnelHeader.Builder withRemove(final List remove) {
this.remove = Collections.unmodifiableList(remove);
return this;
}
/**
* Build the {@link TunnelHeader}.
*/
public TunnelHeader build() {
return new TunnelHeader(this);
}
}
}