Skip to content

Commit

Permalink
Merge #3083 into 2.0.0-M4
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Mar 7, 2024
2 parents c7060c8 + 85562b1 commit e1a8d1b
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 27 deletions.
3 changes: 3 additions & 0 deletions docs/asciidoc/http-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and adds Reactive Streams backpressure.

To connect the `HTTP` client to a given `HTTP` endpoint, you must create and configure a
{javadoc}/reactor/netty5/http/client/HttpClient.html[`HttpClient`] instance.
By default, the host is configured for `localhost` and the port is `80`.
The following example shows how to do so:

====
Expand Down Expand Up @@ -56,6 +57,8 @@ include::{examplesdir}/address/Application.java[lines=18..33]
<2> Configures the `HTTP` port
====

NOTE: The port can be specified also with *PORT* environment variable.

== Eager Initialization

By default, the initialization of the `HttpClient` resources happens on demand. This means that the `first
Expand Down
2 changes: 2 additions & 0 deletions docs/asciidoc/tcp-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ include::{examplesdir}/address/Application.java[lines=18..33]
<2> Configures the `TCP` port
====

NOTE: The port can be specified also with *PORT* environment variable.

== Eager Initialization

By default, the initialization of the `TcpClient` resources happens on demand. This means that the `connect
Expand Down
2 changes: 2 additions & 0 deletions docs/asciidoc/udp-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ include::{examplesdir}/address/Application.java[lines=18..34]
<2> Configures the `port` to which this client should connect
====

NOTE: The port can be specified also with *PORT* environment variable.

== Eager Initialization

By default, the initialization of the `UdpClient` resources happens on demand. This means that the `connect
Expand Down
2 changes: 2 additions & 0 deletions docs/asciidoc/udp-server.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ include::{examplesdir}/address/Application.java[lines=18..34]
<2> Configures the `UDP` server port
====

NOTE: The port can be specified also with *PORT* environment variable.

== Eager Initialization

By default, the initialization of the `UdpServer` resources happens on demand. This means that the `bind
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2021-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -156,6 +156,8 @@ public final QuicClient host(String host) {

/**
* The port to which this client should connect.
* If a port is not specified, the default port {@code 12012} is used.
* <p><strong>Note:</strong> The port can be specified also with {@code QUIC_PORT} environment variable.
*
* @param port the port to connect to
* @return a {@link QuicClient} reference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2021-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -114,13 +114,6 @@ static void validate(QuicClientConfig config) {
Objects.requireNonNull(config.sslEngineProvider, "sslEngineProvider");
}

/**
* The default port for reactor-netty QUIC clients. Defaults to 12012 but can be tuned via
* the {@code QUIC_PORT} <b>environment variable</b>.
*/
static final int DEFAULT_PORT =
System.getenv("QUIC_PORT") != null ? Integer.parseInt(System.getenv("QUIC_PORT")) : 12012;

static final class DisposableConnect implements CoreSubscriber<Channel>, Disposable {

final Map<AttributeKey<?>, ?> attributes;
Expand Down Expand Up @@ -279,4 +272,22 @@ public void onUncaughtException(Connection connection, Throwable error) {
childObs.onUncaughtException(connection, error);
}
}

/**
* The default port for reactor-netty QUIC clients. Defaults to 12012 but can be tuned via
* the {@code QUIC_PORT} <b>environment variable</b>.
*/
static final int DEFAULT_PORT;
static {
int port;
String portStr = null;
try {
portStr = System.getenv("QUIC_PORT");
port = portStr != null ? Integer.parseInt(portStr) : 12012;
}
catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid environment variable [QUIC_PORT=" + portStr + "].", e);
}
DEFAULT_PORT = port;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2021-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -148,6 +148,7 @@ public final QuicServer host(String host) {

/**
* The port to which this server should bind.
* If a port is not specified, the system picks up an ephemeral port.
*
* @param port The port to bind to.
* @return a {@link QuicServer} reference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2011-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -199,6 +199,14 @@ public <O> TcpClient option(ChannelOption<O> key, @Nullable O value) {
return super.option(key, value);
}

/**
* The port to which this client should connect.
* If a port is not specified, the default port {@code 12012} is used.
* <p><strong>Note:</strong> The port can be specified also with {@code PORT} environment variable.
*
* @param port the port to connect to
* @return a new {@link TcpClient}
*/
@Override
public TcpClient port(int port) {
return super.port(port);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2017-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,8 +54,20 @@ protected TcpClient duplicate() {
}

/**
* The default port for reactor-netty servers. Defaults to 12012 but can be tuned via
* The default port for reactor-netty TCP clients. Defaults to 12012 but can be tuned via
* the {@code PORT} <b>environment variable</b>.
*/
static final int DEFAULT_PORT = System.getenv("PORT") != null ? Integer.parseInt(System.getenv("PORT")) : 12012;
static final int DEFAULT_PORT;
static {
int port;
String portStr = null;
try {
portStr = System.getenv("PORT");
port = portStr != null ? Integer.parseInt(portStr) : 12012;
}
catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid environment variable [PORT=" + portStr + "].", e);
}
DEFAULT_PORT = port;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2011-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -146,6 +146,13 @@ public TcpServer noSSL() {
return this;
}

/**
* The port to which this server should bind.
* If a port is not specified, the system picks up an ephemeral port.
*
* @param port The port to bind to.
* @return a new {@link TcpServer}
*/
@Override
public TcpServer port(int port) {
return super.port(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ public final <O> UdpClient option(ChannelOption<O> key, @Nullable O value) {
return super.option(key, value);
}

/**
* The port to which this client should connect.
* If a port is not specified, the default port {@code 12012} is used.
* <p><strong>Note:</strong> The port can be specified also with {@code PORT} environment variable.
*
* @param port the port to connect to
* @return a new {@link UdpClient} reference
*/
@Override
public final UdpClient port(int port) {
return super.port(port);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2017-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,8 +56,20 @@ protected UdpClient duplicate() {
}

/**
* The default port for reactor-netty servers. Defaults to 12012 but can be tuned via
* The default port for reactor-netty UDP clients. Defaults to 12012 but can be tuned via
* the {@code PORT} <b>environment variable</b>.
*/
static final int DEFAULT_PORT = System.getenv("PORT") != null ? Integer.parseInt(System.getenv("PORT")) : 12012;
static final int DEFAULT_PORT;
static {
int port;
String portStr = null;
try {
portStr = System.getenv("PORT");
port = portStr != null ? Integer.parseInt(portStr) : 12012;
}
catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid environment variable [PORT=" + portStr + "].", e);
}
DEFAULT_PORT = port;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2011-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -214,6 +214,8 @@ public final <O> UdpServer option(ChannelOption<O> key, @Nullable O value) {

/**
* The port to which this server should bind.
* If a port is not specified, the default port {@code 12012} is used.
* <p><strong>Note:</strong> The port can be specified also with {@code PORT} environment variable.
*
* @param port The port to bind to.
* @return a new {@link UdpServer} reference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2017-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,8 +72,20 @@ protected UdpServer duplicate() {
}

/**
* The default port for reactor-netty servers. Defaults to 12012 but can be tuned via
* The default port for reactor-netty UDP servers. Defaults to 12012 but can be tuned via
* the {@code PORT} <b>environment variable</b>.
*/
static final int DEFAULT_PORT = System.getenv("PORT") != null ? Integer.parseInt(System.getenv("PORT")) : 12012;
static final int DEFAULT_PORT;
static {
int port;
String portStr = null;
try {
portStr = System.getenv("PORT");
port = portStr != null ? Integer.parseInt(portStr) : 12012;
}
catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid environment variable [PORT=" + portStr + "].", e);
}
DEFAULT_PORT = port;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2011-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1161,6 +1161,14 @@ public final RequestSender patch() {
return request(HttpMethod.PATCH);
}

/**
* The port to which this client should connect.
* If a port is not specified, the default port {@code 80} is used.
* <p><strong>Note:</strong> The port can be specified also with {@code PORT} environment variable.
*
* @param port the port to connect to
* @return a new {@link HttpClient}
*/
@Override
public final HttpClient port(int port) {
return super.port(port);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2017-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -629,9 +629,25 @@ public String toString() {

static final AsciiString ALL = new AsciiString("*/*");

static final int DEFAULT_PORT = System.getenv("PORT") != null ? Integer.parseInt(System.getenv("PORT")) : 80;

static final Logger log = Loggers.getLogger(HttpClientConnect.class);

static final BiFunction<String, Integer, InetSocketAddress> URI_ADDRESS_MAPPER = AddressUtils::createUnresolved;

/**
* The default port for reactor-netty HTTP clients. Defaults to 80 but can be tuned via
* the {@code PORT} <b>environment variable</b>.
*/
static final int DEFAULT_PORT;
static {
int port;
String portStr = null;
try {
portStr = System.getenv("PORT");
port = portStr != null ? Integer.parseInt(portStr) : 80;
}
catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid environment variable [PORT=" + portStr + "].", e);
}
DEFAULT_PORT = port;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2011-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -642,6 +642,13 @@ public final HttpServer noSSL() {
return this;
}

/**
* The port to which this server should bind.
* If a port is not specified, the system picks up an ephemeral port.
*
* @param port The port to bind to.
* @return a new {@link HttpServer}
*/
@Override
public final HttpServer port(int port) {
return super.port(port);
Expand Down

0 comments on commit e1a8d1b

Please sign in to comment.