Package com.ngrok
Class HttpBuilder
- java.lang.Object
-
- com.ngrok.MetadataBuilder<T>
-
- com.ngrok.EndpointBuilder<HttpBuilder>
-
- com.ngrok.HttpBuilder
-
- All Implemented Interfaces:
Forwarder.Builder<Forwarder.Endpoint>
,Listener.Builder<Listener.Endpoint>
public class HttpBuilder extends EndpointBuilder<HttpBuilder> implements Listener.Builder<Listener.Endpoint>, Forwarder.Builder<Forwarder.Endpoint>
A builder for creating a HTTP endpoint listener
-
-
Constructor Summary
Constructors Constructor Description HttpBuilder(Session session)
Creates a newHttpBuilder
with a given session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpBuilder
addRequestHeader(String name, String value)
Adds a header to the list of added request headers for this HTTP endpoint.HttpBuilder
addResponseHeader(String name, String value)
Adds a header to the list of added response headers for this HTTP endpoint.HttpBuilder
basicAuthOptions(Http.BasicAuth options)
Sets basic authentication for this HTTP endpoint.HttpBuilder
circuitBreaker(double value)
Sets the circuit breaker value for this HTTP endpoint.HttpBuilder
compression()
Enables HTTP response compression for this HTTP endpoint.HttpBuilder
domain(String domain)
Sets the domain to request for this HTTP endpoint.Forwarder.Endpoint
forward(URL url)
Start listening and forwarding connections to given url.Http.BasicAuth
getBasicAuth()
Returns the basic authentication options for this HTTP endpoint.Optional<Double>
getCircuitBreaker()
Returns the circuit breaker value for this HTTP endpoint.Optional<String>
getDomain()
Returns the domain on this HTTP endpoint.byte[]
getMutualTLSCA()
Returns the certificates to use for client authentication for this HTTP endpoint.Http.OAuth
getOauth()
Returns the OAuth options for this HTTP endpoint.Http.OIDC
getOidc()
Returns the OIDC options for this HTTP endpoint.List<String>
getRemoveRequestHeaders()
Returns the list of request headers to remove for this HTTP endpoint.List<String>
getRemoveResponseHeaders()
Returns the list of response headers to remove for this HTTP endpoint.List<Http.Header>
getRequestHeaders()
Returns the list of request headers to add for this HTTP endpoint.List<Http.Header>
getResponseHeaders()
Returns the list of response headers to add for this HTTP endpoint.Http.Scheme
getScheme()
Returns the scheme for this HTTP endpoint.Optional<String>
getSchemeName()
Returns the scheme name for this HTTP endpoint.Http.WebhookVerification
getWebhookVerification()
Returns the webhook verification options for this HTTP endpoint.boolean
isCompression()
Returns whether compression is enabled for this HTTP endpoint.boolean
isWebsocketTcpConversion()
Returns whether WebSocket to TCP conversion is enabled for this HTTP endpoint.Listener.Endpoint
listen()
Starts listening and accepting new connections.HttpBuilder
mutualTLSCA(byte[] mutualTLSCA)
Sets the certificates to use for client authentication for this HTTP endpoint.HttpBuilder
oauthOptions(Http.OAuth options)
Sets OAuth for this HTTP endpoint.HttpBuilder
oidcOptions(Http.OIDC options)
Sets OIDC for this HTTP endpoint.HttpBuilder
removeRequestHeader(String name)
Adds a header to the list of removed request headers for this HTTP endpoint.HttpBuilder
removeResponseHeader(String name)
Adds a header to the list of removed response headers for this HTTP endpoint.HttpBuilder
scheme(Http.Scheme scheme)
Sets the scheme for this HTTP endpoint.HttpBuilder
webhookVerification(Http.WebhookVerification webhookVerification)
Sets webhook verification for this HTTP endpoint.HttpBuilder
websocketTcpConversion()
Enables Websocket to TCP conversion for this HTTP endpoint.-
Methods inherited from class com.ngrok.EndpointBuilder
allowCIDR, denyCIDR, getAllowCIDR, getDenyCIDR, getPolicy, getProxyProto, getProxyProtoVersion, getTrafficPolicy, policy, proxyProto, trafficPolicy
-
Methods inherited from class com.ngrok.MetadataBuilder
forwardsTo, getForwardsTo, getMetadata, metadata
-
-
-
-
Constructor Detail
-
HttpBuilder
public HttpBuilder(Session session)
Creates a newHttpBuilder
with a given session.- Parameters:
session
- the session over which this listener will connect. Ifnull
,listen()
andforward(URL)
will throwNullPointerException
, use the corresponding methods on theSession
object directly.
-
-
Method Detail
-
scheme
public HttpBuilder scheme(Http.Scheme scheme)
Sets the scheme for this HTTP endpoint. The default scheme isHttp.Scheme.HTTPS
.- Parameters:
scheme
- the scheme- Returns:
- the builder instance
-
domain
public HttpBuilder domain(String domain)
Sets the domain to request for this HTTP endpoint. Any valid domain or hostname that you have previously registered with ngrok. If using a custom domain, this requires registering in the ngrok dashboard and setting a DNS CNAME value.- Parameters:
domain
- the domain- Returns:
- the builder instance
-
mutualTLSCA
public HttpBuilder mutualTLSCA(byte[] mutualTLSCA)
Sets the certificates to use for client authentication for this HTTP endpoint.- Parameters:
mutualTLSCA
- the TLS certificate, in bytes- Returns:
- the builder instance
- See Also:
- Mutual TLS in the ngrok docs for additional details.
-
compression
public HttpBuilder compression()
Enables HTTP response compression for this HTTP endpoint.- Returns:
- the builder instance
- See Also:
- Compression in the ngrok docs for additional details.
-
websocketTcpConversion
public HttpBuilder websocketTcpConversion()
Enables Websocket to TCP conversion for this HTTP endpoint.- Returns:
- the builder instance
- See Also:
- Websocket TCP Converter in the ngrok docs for additional details.
-
circuitBreaker
public HttpBuilder circuitBreaker(double value)
Sets the circuit breaker value for this HTTP endpoint. ngrok will reject requests when 5XX responses exceed this ratio.- Parameters:
value
- the circuit breaker value, between 0 and 1- Returns:
- the builder instance
- See Also:
- Circuit Breaker in the ngrok docs for additional details.
-
addRequestHeader
public HttpBuilder addRequestHeader(String name, String value)
Adds a header to the list of added request headers for this HTTP endpoint.- Parameters:
name
- the name of the header to addvalue
- the value of the header to add- Returns:
- the builder instance
- See Also:
- Request Headers in the ngrok docs for additional details.
-
addResponseHeader
public HttpBuilder addResponseHeader(String name, String value)
Adds a header to the list of added response headers for this HTTP endpoint.- Parameters:
name
- the name of the header to addvalue
- the value of the header to add- Returns:
- the builder instance
- See Also:
- Response Headers in the ngrok docs for additional details.
-
removeRequestHeader
public HttpBuilder removeRequestHeader(String name)
Adds a header to the list of removed request headers for this HTTP endpoint.- Parameters:
name
- the name of the header to remove- Returns:
- the builder instance
- See Also:
- Request Headers in the ngrok docs for additional details.
-
removeResponseHeader
public HttpBuilder removeResponseHeader(String name)
Adds a header to the list of removed response headers for this HTTP endpoint.- Parameters:
name
- the name of the header to remove- Returns:
- the builder instance
- See Also:
- Response Headers in the ngrok docs for additional details.
-
basicAuthOptions
public HttpBuilder basicAuthOptions(Http.BasicAuth options)
Sets basic authentication for this HTTP endpoint.- Parameters:
options
- the basic authentication options- Returns:
- the builder instance
- See Also:
- Basic Auth in the ngrok docs for additional details.
-
oauthOptions
public HttpBuilder oauthOptions(Http.OAuth options)
Sets OAuth for this HTTP endpoint.- Parameters:
options
- the OAuth options- Returns:
- the builder instance
- See Also:
- OAuth in the ngrok docs for additional details.
-
oidcOptions
public HttpBuilder oidcOptions(Http.OIDC options)
Sets OIDC for this HTTP endpoint.- Parameters:
options
- the OIDC options- Returns:
- the builder instance
- See Also:
- OpenID Connect in the ngrok docs for additional details.
-
webhookVerification
public HttpBuilder webhookVerification(Http.WebhookVerification webhookVerification)
Sets webhook verification for this HTTP endpoint.- Parameters:
webhookVerification
- the webhook verification options- Returns:
- the builder instance
- See Also:
- Webhook Verification in the ngrok docs for additional details.
-
getScheme
public Http.Scheme getScheme()
Returns the scheme for this HTTP endpoint.- Returns:
- the scheme
-
getSchemeName
public Optional<String> getSchemeName()
Returns the scheme name for this HTTP endpoint.- Returns:
- the scheme name, either empty, HTTPS or HTTP
-
getDomain
public Optional<String> getDomain()
Returns the domain on this HTTP endpoint.- Returns:
- the domain
-
getMutualTLSCA
public byte[] getMutualTLSCA()
Returns the certificates to use for client authentication for this HTTP endpoint.- Returns:
- the TLS certificates, in bytes.
-
isCompression
public boolean isCompression()
Returns whether compression is enabled for this HTTP endpoint.- Returns:
true
if compression is enabled,false
otherwise
-
isWebsocketTcpConversion
public boolean isWebsocketTcpConversion()
Returns whether WebSocket to TCP conversion is enabled for this HTTP endpoint.- Returns:
true
if WebSocket to TCP conversion is enabled,false
otherwise
-
getCircuitBreaker
public Optional<Double> getCircuitBreaker()
Returns the circuit breaker value for this HTTP endpoint.- Returns:
- the circuit breaker value
-
getRequestHeaders
public List<Http.Header> getRequestHeaders()
Returns the list of request headers to add for this HTTP endpoint.- Returns:
- the list of headers
-
getResponseHeaders
public List<Http.Header> getResponseHeaders()
Returns the list of response headers to add for this HTTP endpoint.- Returns:
- the list of headers
-
getRemoveRequestHeaders
public List<String> getRemoveRequestHeaders()
Returns the list of request headers to remove for this HTTP endpoint.- Returns:
- the list of headers
-
getRemoveResponseHeaders
public List<String> getRemoveResponseHeaders()
Returns the list of response headers to remove for this HTTP endpoint.- Returns:
- the list of headers
-
getBasicAuth
public Http.BasicAuth getBasicAuth()
Returns the basic authentication options for this HTTP endpoint.- Returns:
- the basic authentication options
-
getOauth
public Http.OAuth getOauth()
Returns the OAuth options for this HTTP endpoint.- Returns:
- the OAuth options
-
getOidc
public Http.OIDC getOidc()
Returns the OIDC options for this HTTP endpoint.- Returns:
- the OIDC options
-
getWebhookVerification
public Http.WebhookVerification getWebhookVerification()
Returns the webhook verification options for this HTTP endpoint.- Returns:
- the webhook verification options
-
listen
public Listener.Endpoint listen() throws IOException
Description copied from interface:Listener.Builder
Starts listening and accepting new connections.- Specified by:
listen
in interfaceListener.Builder<Listener.Endpoint>
- Returns:
- the concrete
Listener
instance - Throws:
IOException
- if an I/O error occurs
-
forward
public Forwarder.Endpoint forward(URL url) throws IOException
Description copied from interface:Forwarder.Builder
Start listening and forwarding connections to given url.- Specified by:
forward
in interfaceForwarder.Builder<Forwarder.Endpoint>
- Parameters:
url
- to forward connections to- Returns:
- the concrete
Forwarder
instance - Throws:
IOException
- if an I/O error occurs
-
-