HTTP Reference
このドキュメントでは、Quarkusで利用可能なさまざまなHTTP機能について説明します。
Eclipse Vert.xは、基本的なHTTPレイヤーを提供します。 Servletのサポートのために、QuarkusはVert.xの上で動作するカスタマイズされたUndertowバージョンを使用し、Jakarta RESTのサポートはRESTEasyを通じて提供されます。
Undertowがある場合、RESTEasyはServletフィルタとして機能します。 Undertowがない場合、RESTEasyはServletを介さずにVert.x上で直接動作します。
1. 静的リソースの提供
Quarkus を Web アプリケーションに使用する場合は、Web 向け Quarkus ガイドを参照してください。
1.1. アプリケーションjarから
アプリケーションjarから静的リソースを提供するには、それらをアプリケーションの META-INF/resources ディレクトリに配置する必要があります。この場所は、Servlet仕様で定義されている jar ファイルのリソースの標準的な場所として選択されています。QuarkusはServletなしで使用できますが、この規約に従って、リソースをこの場所に配置する既存のコードを正しく機能させることができます。
1.2. webjars や mvnpm などの Web 依存関係から
WebJars、https://mvnpm.org[mvnpm]、https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap[importmaps] の使用方法の詳細は、Web 依存関係ロケーター ガイドを参照してください。
1.3. ローカルディレクトリから
Vert.xルーターに追加ルートをインストールすることで、静的リソースをローカルディレクトリから提供できます。
例えば、 http://localhost:8080/static/ でカレントパスから相対的に、 static/ ディレクトリからリソースを提供するには、以下のルートをインストールします:
package org.acme;
import io.quarkus.runtime.StartupEvent;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;
import jakarta.enterprise.event.Observes;
public class StaticResources {
void installRoute(@Observes StartupEvent startupEvent, Router router) {
router.route()
.path("/static/*")
.handler(StaticHandler.create("static/"));
}
}
1.4. ローカルファイルシステムの静的リソース
Serving static resources from a local filesystem directory is enabled
when quarkus.http.static-dir.path is set.
The quarkus.http.static-dir.enabled property can be used to explicitly
disable this feature.
|
Quarkus は、アプリケーション JAR や Java リソースの外部にあるローカルファイルシステムのディレクトリーから静的ファイルを提供できます。これは quarkus.http.static-dir.* プロパティーを介して設定されます。
static/ ディレクトリーの内容を公開するには、以下のようにします。
quarkus.http.static-dir.path=static
デフォルトでは、静的ファイルは /static エンドポイントの下で公開されます。
この設定では、 static/picture.jpg にあるファイルは http://localhost:8080/static/picture.jpg で利用可能になります。
デフォルトのエンドポイントを変更するには、以下のようにします。
quarkus.http.static-dir.endpoint=/
この設定では、 static/picture.jpg にあるファイルは http://localhost:8080/picture.jpg で利用可能になります。
quarkus.http.static-dir.endpoint の値には * や .. を含めることはできず、末尾のスラッシュを避けるために正規化されます。同様に、 quarkus.http.static-dir.path は .. を含まない相対パスである必要があります。Quarkus はビルド時にこれらの値を検証します。
この機能は、開発環境と本番環境の両方で使用できます。
1.5. HTTP圧縮
静的リソースのレスポンスボディは、デフォルトでは圧縮されません。 HTTP 圧縮のサポートは quarkus.http.enable-compression=true によって有効にすることができます。 圧縮サポートが有効な場合、リソースのファイル名から得られる Content-Type ヘッダーが quarkus.http.compress-media-types で設定された圧縮メディアタイプであれば、レスポンスボディは圧縮されます。
By default, the following list of media types is compressed: text/html, text/plain, text/xml, text/css, text/javascript, application/javascript, application/json, application/graphql+json and application/xhtml+xml.
|
If the client does not indicate its support for HTTP compression in a request header, e.g. Accept-Encoding: deflate, gzip, br, then the response body is not compressed.
|
Brotli compression is not available by default. You can enable it by setting quarkus.http.compressors=deflate,gzip,br. In case of building native image, it adds around 1MB to your executable size.
|
1.6. その他の設定
さらに、静的リソースのインデックスページをデフォルトの index.html から変更すること、隠しファイル(ドットファイルなど)を提供しないことを示すこと、範囲要求を無効にすること、キャッシュ対応(ヘッダーのキャッシュ、ファイルのプロパティのキャッシュなど)を設定することができます。
ビルド時に固定される設定プロパティ - それ以外の設定プロパティは実行時に上書き可能
Configuration property |
タイプ |
デフォルト |
|---|---|---|
Set the index page when serving static resources. Environment variable: Show more |
string |
|
Set whether hidden files should be served. Environment variable: Show more |
boolean |
|
Set whether range requests (resumable downloads; media streaming) should be enabled. Environment variable: Show more |
boolean |
|
Set whether cache handling is enabled. Environment variable: Show more |
boolean |
|
Set the cache entry timeout. The default is Environment variable: Show more |
|
|
Set value for max age in caching headers. The default is Environment variable: Show more |
|
|
Set the max cache size. Environment variable: Show more |
int |
|
Content encoding for text related files Environment variable: Show more |
|
|
期間フォーマットについて
期間の値を書くには、標準の 数字で始まる簡略化した書式を使うこともできます:
その他の場合は、簡略化されたフォーマットが解析のために
|
2. コンテキストパスの設定
デフォルトでは、 Quarkus はルートコンテキストの下からコンテンツを提供します。これを変更したい場合は、 quarkus.http.root-path 設定キーを使用してコンテキストパスを設定することができます。
Servlet を使用している場合は、quarkus.servlet.context-path を通して Servlet のコンテキストパスを制御することができます。この項目は、上記の http ルートに相対的で、Servlet と、Servlet の上で実行されるものにのみ影響します。多くのアプリケーションでは、Quarkus が提供するすべてのサービスに影響するため、HTTP ルートを使用することをお勧めします。
両方を指定した場合、サーブレット以外のすべてのウェブエンドポイントは quarkus.http.root-path からの相対的なものになり、サーブレットは {quarkus.http.root-path}/{quarkus.servlet.context-path} からの相対的なものになります。
テストに REST Assured を使用し、quarkus.http.root-path が設定されている場合、Quarkus は自動的に Quarkus テストで使用するためのベース URL を設定します。そのため、テストの URL はルートパスには含めないでください。
一般に、ウェブコンテンツのパス設定は、 quarkus.http.root-path ( デフォルトでは / ) からの相対パスとして解釈されます。
-
このコンテキストルート内のパスを指定するには、スラッシュで始まらない相対パスを使用します。
-
URIを明示的に指定し、
quarkus.http.root-pathの値にかかわらず常に同じになるようにしたい場合は、スラッシュで始まる絶対パスを使用します。
例として、エクステンションが service というパスを設定した場合、そのエンドポイントは ${quarkus.http.root-path}/service から提供されます。 そのパスの設定を /service に変更した場合、そのエンドポイントは /service から提供されるようになります。
Quarkus のパス解決に関するブログ記事では、ユーザー定義パスとエクステンション定義パスの両方に対するパス解決の仕組みについて詳しく説明しています。
|
マネジメントインターフェース
詳しくは、 マネジメントインターフェイスのリファレンス を参照してください。 |
3. TLS/SSLによる安全な接続のサポート
Quarkusで安全な接続をサポートするには、証明書と関連するキーファイルを提供するか、キーストアを提供する必要があります。
いずれの場合も、パスワードを提供する必要があります。提供方法の詳細については、提供方法に関する段落を参照してください。
|
ネイティブ実行可能ファイルでの TLS/SSL サポートを有効にするには、 ネイティブ実行可能ファイルでの SSL の使用ガイド を参照してください。 |
3.1. TLS 集中設定の使用
Quarkus は、サーバーの TLS コンテキストを設定するために使用できる TLS 集中設定 を提供します。 HTTPS を設定することが推奨される方法です。
HTTPS を使用するために HTTP サーバーを設定するには、次の設定を使用できます。
quarkus.tls.key-store.pem.0.cert=server.crt
quarkus.tls.key-store.pem.0.key=server.key
quarkus.http.insecure-requests=disabled # Reject HTTP requests
p12 (PKCS12) キーストアを使用するには、次の設定を適用します。
quarkus.tls.key-store.p12.path=server-keystore.p12
quarkus.tls.key-store.p12.password=secret
quarkus.http.insecure-requests=disabled # Reject HTTP requests
デフォルト設定の代わりに、名前付き設定を使用できます。
quarkus.tls.https.key-store.p12.path=server-keystore.p12
quarkus.tls.https.key-store.p12.password=secret
quarkus.http.insecure-requests=disabled
quarkus.http.tls-configuration-name=https
3.2. HTTP サーバーの直接設定
TLS レジストリーを使用しない場合は、HTTP サーバーを直接設定できます。
証明書がキーストアにロードされていない場合は、以下のプロパティーを使用して直接提供することができます。Quarkus はまず、与えられたファイルをリソースとしてロードしようとし、ファイルシステムをフォールバックとして使用します。証明書/キーペアは、起動時に新しく作成されたキーストアにロードされます。
application.properties は次のようになります。
quarkus.http.ssl.certificate.files=/path/to/certificate
quarkus.http.ssl.certificate.key-files=/path/to/key
別の解決策としては、すでに証明書付きのデフォルトのエントリーを含むキーストアを直接提供する方法もあります。 少なくともファイルとパスワードを提供する必要があります。
証明書とキーファイルの組み合わせと同様に、 Quarkus はまず、ファイルシステムからの読み込みを試みる前に、指定されたパスをリソースとして解決しようとします。
次のプロパティーを application.properties に追加します。
quarkus.http.ssl.certificate.key-store-file=/path/to/keystore
オプションのヒントとして、キーストアのタイプをオプションの1つとして指定できます。 タイプが指定されていない場合、Quarkusはファイルの拡張子から推測しようとします。
quarkus.http.ssl.certificate.key-store-file-type=[one of JKS, JCEKS, P12, PKCS12, PFX]
前述のいずれのシナリオでも、キーストアを作成/ロードするためにパスワードを指定する必要があります。パスワードは、以下のプロパティーを使用して application.properties で (プレーンテキストで) 設定できます。
quarkus.http.ssl.certificate.key-store-password=your-password
しかし、設定ファイルでパスワードをプレーンテキストとして提供する代わりに (これは悪い習慣と考えられています)、環境変数 QUARKUS_HTTP_SSL_CERTIFICATE_KEY_STORE_PASSWORD として ( MicroProfile config を使用して) パスワードを提供することができます。これは、 Kubernetes secrets と連動します。
注意:Quarkusの以前のバージョン(0.16以前)との互換性を保つため、デフォルトのパスワードは "password "に設定されています。そのため、必須パラメータではありません!
3.3. HTTP ポートの設定
デフォルトでは、Quarkusは、SSLで保護された接続にポート8443を、テストの実行時にはポート8444をリッスンします。
これらのポートは、 application.properties のプロパティ quarkus.http.ssl-port と quarkus.http.test-ssl-port で設定することができます。
3.4. HTTP ポートの無効化
HTTP ポートを無効にして、セキュアなリクエストのみをサポートすることも可能です。これは application.properties の quarkus.http.insecure-requests プロパティーで行います。3 つの値を利用できます。
enabled-
デフォルトでは、 HTTP は通常通りに動作します。
redirect-
HTTP リクエストは HTTPS ポートにリダイレクトされます。
disabled-
HTTP ポートは開放されません。
if you use redirect or disabled and have not added an SSL certificate or keystore, your server will not start!
|
3.5. 証明書の再読込
きーストア、トラスト・ストア、および証明書ファイルは、定期的にリロードできます。
quarkus.http.ssl.certificate.reload-period プロパティを設定して、証明書をリロードする間隔を指定します:
quarkus.http.ssl.certificate.files=/mount/certs/tls.crt
quarkus.http.ssl.certificate.key-files=/mount/certs/tls.key
quarkus.http.ssl.certificate.reload-period=1h
ファイルは最初に読み込まれたのと同じ場所から再読み込みされます。 内容に変更がない場合、リロードは失敗します。 リロードに失敗した場合、サーバは以前の証明書を使い続けます。
3.6. クライアントの再ネゴシエーションの防止
詳細は、クライアントの再ネゴシエーションの防止 を参照してください。
4. 追加の HTTP ヘッダー
すべてのレスポンスに HTTP ヘッダーを送信するようにするには、以下のプロパティーを追加します。
quarkus.http.header."X-Content-Type-Options".value=nosniff
これにより、アプリケーション内の任意のリソースに対して実行されるリクエストのレスポンスに、 X-Content-Type-Options: nosniff HTTP ヘッダーが含まれます。
また、ヘッダーを適用する必要がある path パターンと HTTP methods を指定することもできます。
quarkus.http.header.Pragma.value=no-cache
quarkus.http.header.Pragma.path=/headers/pragma
quarkus.http.header.Pragma.methods=GET,HEAD
これにより、 /headers/pragma リソースが GET または HEAD メソッドで呼び出された場合にのみ、 Pragma ヘッダーが適用されます。
ビルド時に固定される設定プロパティ - それ以外の設定プロパティは実行時に上書き可能
Configuration property |
タイプ |
デフォルト |
|---|---|---|
The path this header should be applied Environment variable: Show more |
string |
|
The value for this header configuration Environment variable: Show more |
string |
required |
The HTTP methods for this header configuration. If no HTTP methods are specified, the header will be always added. Environment variable: Show more |
文字列のリスト |
4.1. パスごとの追加の HTTP ヘッダー
パスによって異なるヘッダー値が必要な場合は、以下のように設定することができます。
quarkus.http.filter.index.header."Cache-Control"=none
quarkus.http.filter.index.matches=/index.html
これにより、 /index.html が呼び出されたときに、 Cache-Control のヘッダに none が設定されます。
The index after quarkus.http.filter in the key is used for grouping and (as an example) can be named as you like.
|
パスには正規表現を使用でき、また HTTP ヘッダーが設定される HTTP メソッドを指定することもできます。
quarkus.http.filter.static.header."Cache-Control"=max-age=31536000
quarkus.http.filter.static.methods=GET,HEAD
quarkus.http.filter.static.matches=/static/.*
設定でパスが重複している場合、順序を指定することができます ( 値の大きい方が優先されます ) 。例えば、以下のような設定を持つ場合を考えます。
quarkus.http.filter.just-order.order=10
quarkus.http.filter.just-order.header."Cache-Control"=max-age=5000
quarkus.http.filter.just-order.matches=/paths/order
quarkus.http.filter.any-order.order=11
quarkus.http.filter.any-order.header."Cache-Control"=max-age=1
quarkus.http.filter.any-order.matches=/paths/order.*
/paths/order が要求されたときに Cache-Control: max-age=1 ヘッダを含めます。
ビルド時に固定される設定プロパティ - それ以外の設定プロパティは実行時に上書き可能
Configuration property |
タイプ |
デフォルト |
|---|---|---|
A regular expression for the paths matching this configuration Environment variable: Show more |
string |
required |
Additional HTTP Headers always sent in the response Environment variable: Show more |
Map<String,String> |
|
The HTTP methods for this path configuration Environment variable: Show more |
文字列のリスト |
|
Order in which this path config is applied. Higher priority takes precedence Environment variable: Show more |
int |
5. Vert.xにおける 100-continue のサポート
100-continue をサポートするには、 quarkus.http.handle-100-continue-automatically オプションを明示的に有効にする必要があります。
詳細については、 100-continue と
関連する Vert.x ドキュメント を参照してください。
quarkus.http.handle-100-continue-automatically=true
6. HTTP/2 サポート
HTTP/2はデフォルトで有効になっており、SSLが使用されている場合はブラウザで使用されます。 SSL が使用されていない場合でも、クリアテキストアップグレードによる HTTP/2 はサポートされており、ブラウザ以外のクライアントで使用される可能性があります。
HTTP/2 を無効にしたい場合は、以下を設定します。
quarkus.http.http2=false
いくつかの設定属性はHTTP/2に固有であることに注意してください。例えば、最大ヘッダーリストサイズ (~ヘッダー) を設定するには、 quarkus.http.limits.max-header-list-size 属性を設定する必要があります。また、 quarkus.http.http2-push-enabled を使用して、HTTP/2プッシュを有効または無効にすることもできます。
7. ランダムポートでの待ち受け
ポートを指定したくない場合は、 quarkus.http.port=0 または quarkus.http.test-port=0 を設定できます。OS によってランダムな空きポートが選択され、コンソールにログメッセージが表示されます。
実際のポートを取得するには、 io.quarkus.vertx.http.HttpServer API を使用します。これは CDI Bean としてアプリケーションコードにインジェクションできます。
import jakarta.inject.Singleton;
import io.quarkus.vertx.http.HttpServer;
@Singleton
public class MyService {
@Inject
HttpServer httpServer;
public void connectToServer() {
int port = httpServer.getPort();
}
}
または、フィールドまたはテストパラメーターとして、あらゆる種類のテストにインジェクションできます。
import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.vertx.http.HttpServer;
@QuarkusTest
class HttpServerTest {
HttpServer httpServer;
@Test
void connectToServer(HttpServer httpServer) {
int port = httpServer.getPort();
}
}
Quarkus がサービスを提供している URI を取得するには、 HttpServer#getLocalBaseUri() を使用します。テストでは、 @TestHTTPResource を使用して URI を直接インジェクションできます。
@TestHTTPResource
URL testUrl;
REST Assured のように、実際の HTTP ポートを必要とするすべての Quarkus コンポーネントは、実際のポートで自動的に更新されます。
8. CORS フィルター
Quarkusアプリケーションを別のドメインで実行されている別のアプリケーションからアクセスできるようにするには、クロスオリジンリソース共有(CORS)を設定する必要があります。 Quarkusが提供するCORSフィルターの詳細については、クロスオリジンリソース共有ガイドのQuarkus CORSフィルター のセクションを参照してください。
9. HTTP Host header validation
Quarkus can validate the HTTP Host header on incoming requests to protect against DNS rebinding attacks and host header poisoning.
When quarkus.http.host is set to a localhost name (localhost, 127.0.0.1, or [::1]), host validation is automatically enabled in dev and production modes.
Only requests whose Host header matches one of the known localhost names are accepted; all others receive a 400 Bad Request response.
|
This automatic behavior is a change from previous Quarkus versions, where no
|
9.1. Configuring allowed hosts
To restrict requests to a specific set of host names, use allowed-hosts:
quarkus.http.host-validation.allowed-hosts=example.com,api.example.com
The check is case-insensitive and only validates the host name, not the port.
9.2. Requiring localhost only
To explicitly require that only localhost names are accepted:
quarkus.http.host-validation.require-localhost=true
To disable automatic localhost validation when the server is bound to a localhost address:
quarkus.http.host-validation.require-localhost=false
allowed-hosts and require-localhost are mutually exclusive.
Setting both results in a configuration error.
|
9.3. Reverse proxy considerations
When running behind a reverse proxy, enable proxy header forwarding so that Quarkus validates the forwarded host instead of the proxy’s internal host name:
quarkus.http.proxy.proxy-address-forwarding=true
quarkus.http.proxy.allow-forwarded=true
quarkus.http.host-validation.allowed-hosts=public-api.example.com
This works with both the standard Forwarded header and the X-Forwarded-Host header.
ビルド時に固定される設定プロパティ - それ以外の設定プロパティは実行時に上書き可能
Configuration property |
タイプ |
デフォルト |
|---|---|---|
Require that HTTP Host authority can only contain valid localhost names such as "localhost", "127.0.0.1" or "[::1]". This requirement is enforced in production and dev modes, when neither this nor the Note this property is mutually exclusive with the Environment variable: Show more |
boolean |
|
Allowed hosts. A comma-separated set of hosts, for example: "localhost", "quarkus.io". Note this property is mutually exclusive with the Environment variable: Show more |
文字列のリスト |
10. HTTP 制限の設定
ビルド時に固定される設定プロパティ - それ以外の設定プロパティは実行時に上書き可能
Configuration property |
タイプ |
デフォルト |
|---|---|---|
The maximum length of all headers, up to Environment variable: Show more |
|
|
The maximum size of a request body, up to Environment variable: Show more |
|
|
The max HTTP chunk size, up to Environment variable: Show more |
|
|
The maximum length of the initial line (e.g. Environment variable: Show more |
int |
|
The maximum length of a form attribute, up to Environment variable: Show more |
|
|
Set the maximum number of fields of a form. Set to Environment variable: Show more |
int |
|
Set the maximum number of bytes a server can buffer when decoding a form. Set to Environment variable: Show more |
|
|
The maximum number of HTTP request parameters permitted for incoming requests. If a client sends more than this number of parameters in a request, the connection is closed. Environment variable: Show more |
int |
|
The maximum size of the headers section within a single MIME part of a If a part’s headers exceed this limit, the request is rejected with HTTP 413. Environment variable: Show more |
|
|
The maximum number of headers allowed within a single MIME part of a If a part contains more headers than this limit, the request is rejected with HTTP 413. Environment variable: Show more |
int |
|
The maximum number of connections that are allowed at any one time. If this is set it is recommended to set a short idle timeout. Environment variable: Show more |
int |
|
Set the SETTINGS_HEADER_TABLE_SIZE HTTP/2 setting. Allows the sender to inform the remote endpoint of the maximum size of the header compression table used to decode header blocks, in octets. The encoder can select any size equal to or less than this value by using signaling specific to the header compression format inside a header block. The initial value is Environment variable: Show more |
long |
|
Set SETTINGS_MAX_CONCURRENT_STREAMS HTTP/2 setting. Indicates the maximum number of concurrent streams that the sender will allow. This limit is directional: it applies to the number of streams that the sender permits the receiver to create. Initially, there is no limit to this value. It is recommended that this value be no smaller than 100, to not unnecessarily limit parallelism. Environment variable: Show more |
long |
|
Set the SETTINGS_MAX_FRAME_SIZE HTTP/2 setting. Indicates the size of the largest frame payload that the sender is willing to receive, in octets. The initial value is Environment variable: Show more |
int |
|
Set the SETTINGS_MAX_HEADER_LIST_SIZE HTTP/2 setting. This advisory setting informs a peer of the maximum size of header list that the sender is prepared to accept, in octets. The value is based on the uncompressed size of header fields, including the length of the name and value in octets plus an overhead of 32 octets for each header field. The default value is Environment variable: Show more |
long |
|
Set the max number of RST frame allowed per time window, this is used to prevent HTTP/2 RST frame flood DDOS attacks. The default value is Environment variable: Show more |
int |
|
Set the duration of the time window when checking the max number of RST frames, this is used to prevent HTTP/2 RST frame flood DDOS attacks.. The default value is Environment variable: Show more |
|
期間フォーマットについて
期間の値を書くには、標準の 数字で始まる簡略化した書式を使うこともできます:
その他の場合は、簡略化されたフォーマットが解析のために
|
|
MemorySizeフォーマットについて
A size configuration option recognizes strings in this format (shown as a regular expression): If no suffix is given, assume bytes. |
11. トラフィックシェーピングの設定
トラフィックシェーピングを使用すると、開いているチャネルの数に関係なく、すべてのチャネル(つまり接続)の帯域幅を制限することができます。 これは、ネットワーク全体のトラフィックを制御して輻輳を防止したり、特定の種類のトラフィックを優先したりする場合に便利です。
トラフィック・シェーピングを有効にするには、アプリケーション・コンフィグレーションに以下のプロパティを追加する:
quarkus.http.traffic-shaping.enabled=true # Required to enable traffic shaping
トラフィックシェーピングでは、書き込みと読み取りの制限(1秒あたりのバイト数)、チェック間隔(帯域幅の2回の計算間の遅延)、最大待機時間など、さまざまなパラメータを設定できます:
quarkus.http.traffic-shaping.enabled=true # Required to enable traffic shaping
quarkus.http.traffic-shaping.check-interval=30s
quarkus.http.traffic-shaping.outbound-global-bandwidth=1M
quarkus.http.traffic-shaping.inbound-global-bandwidth=1M
quarkus.http.traffic-shaping.max-delay=10s
チェック間隔は、トラフィックが計算される期間を表し、間隔が大きいほど、トラフィックシェーピングの精度が低くなる可能性があります。 0が受け入れられるにもかかわらず(アカウンティングなし)、トラフィックシェーピングの精度はトラフィックが計算される期間に依存するため、チェック間隔には高くても正の値を設定することを推奨します。 この場合、5分または10分に近い値が推奨されます。
outbound-global-bandwidth 、 inbound-global-bandwidth パラメータは、それぞれ書き込みと読み出し操作の1秒あたりの最大バイト数を表します。
また、読み取りまたは書き込み操作のオブジェクト・サイズを、必要な帯域幅に比較的適合させることも考慮する必要があります。
例えば、10KB/秒に対して10MBのオブジェクトがあるとバースト効果が生じますが、1MB/秒に対して100KBのオブジェクトがあれば、トラフィックシェーピングによってスムーズに処理できるはずです。
さらに、最大待機時間 ( max-delay ) を設定できます。これは、タイムシェーピングの上限を指定するものです。
デフォルトでは 15 秒に設定されています。
これは HTTP タイムアウトより小さくなければなりません。
しきい値のいずれかに達すると、その期間書き込みは行われません。
12. HTTP アクセスログの設定
application.properties で設定することで、HTTP リクエストのロギングを追加することができます。ロギングには、標準の JBoss ロギング出力にロギングするか、専用ファイルにロギングするかの 2 つのオプションがあります。
ビルド時に固定される設定プロパティ - それ以外の設定プロパティは実行時に上書き可能
Configuration property |
タイプ |
デフォルト |
|---|---|---|
If access logging is enabled. By default this will log via the standard logging facility Environment variable: Show more |
boolean |
|
A regular expression that can be used to exclude some paths from logging. Environment variable: Show more |
string |
|
The access log pattern. If this is the string
Otherwise, consult the Quarkus documentation for the full list of variables that can be used. Note that enabling the HTTP Environment variable: Show more |
string |
|
Set of HTTP headers whose values must be masked when the Environment variable: Show more |
文字列のリスト |
|
Set of HTTP Cookie headers whose values must be masked when the Environment variable: Show more |
文字列のリスト |
|
If logging should be done to a separate file. Environment variable: Show more |
boolean |
|
The access log file base name, defaults to 'quarkus' which will give a log file name of 'quarkus.log'. Environment variable: Show more |
string |
|
The log directory to use when logging access to a file If this is not set then the current working directory is used. Environment variable: Show more |
string |
|
The log file suffix Environment variable: Show more |
string |
|
The log category to use if logging is being done via the standard log mechanism (i.e. if base-file-name is empty). Environment variable: Show more |
string |
|
If the log should be rotated daily Environment variable: Show more |
boolean |
|
If rerouted requests should be consolidated into one log entry Environment variable: Show more |
boolean |
|
| 属性 | ショートフォーム | 長い形式 |
|---|---|---|
リモート IP アドレス |
|
|
ローカル IP アドレス |
|
|
HTTP ヘッダーを除く送信済みバイト数。送信されなかった場合は '-' 。 |
|
|
HTTP ヘッダーを除く送信済みバイト数 |
|
|
リモートホスト名 |
|
|
Remote logical username from identd (always returns '-') |
|
|
リクエストプロトコル |
|
|
リクエストメソッド |
|
|
ローカルポート |
|
|
クエリー文字列 ( 存在する場合は '?' が前に付き、そうでない場合は空文字列 ) |
|
|
リクエストの最初の行 |
|
|
レスポンスの HTTP ステータスコード |
|
|
Common Log Format 形式の日時 |
|
|
DateTimeFormatter 準拠の文字列で定義された日付と時刻 |
|
|
認証されたリモートユーザー |
|
|
リクエストされた URL パス |
|
|
リクエストされた相対パス |
|
|
ローカルサーバー名 |
|
|
リクエストの処理にかかった時間 (ミリ秒 ) |
|
|
リクエストの処理にかかった時間 ( 秒単位 ) |
|
|
リクエストの処理にかかった時間 ( マイクロ秒 ) |
|
|
リクエストの処理にかかった時間 ( ナノ秒 ) |
|
|
現在のリクエストスレッド名 |
|
|
SSL 暗号 |
|
|
SSL クライアント証明書 |
|
|
SSL セッション ID |
|
|
すべてのリクエストヘッダー |
|
|
クッキーの値 |
|
|
クエリーパラメーター |
|
|
リクエストヘッダー |
|
|
レスポンスヘッダー |
|
|
Vert.x Routing Context の内部データ |
|
|
Vert.x Mapped Diagnostic Context ( MDC ) データ ( OpenTelemetry の 'traceId' など) |
|
修飾子 < のサポートを有効にするには quarkus.http.access-log.consolidate-rerouted-requests=true を設定します。この修飾子は、元のリクエストを参照するために内部的にリダイレクトされた リクエストに使用できます。
以下の属性がこの修飾子をサポートしています:
| 属性 | ショートフォーム | 長い形式 |
|---|---|---|
リクエストの最初の行 |
|
|
リクエストメソッド |
|
|
リクエストされた相対パス |
|
|
リクエストされた URL パス |
|
|
クエリー文字列 ( 存在する場合は '?' が前に付き、そうでない場合は空文字列 ) |
|
|
クエリーパラメーター |
|
|
リクエストの処理にかかった時間のロギングに関連する属性のいずれかを使用する場合は、 |
|
アプリケーションのセキュリティが設定されていると仮定すると(詳細は ガイド を参照)、
ロギング属性 |
|
|
13. 任意のカスタマイズ
Quarkusでは、 io.quarkus.vertx.http.HttpServerOptionsCustomizer を使用して、Quarkusが起動するHTTPサーバーのオプションを任意にカスタマイズできます。
例えば、HTTPポートをプログラムで設定する必要がある場合、次のコードを使用できます:
import jakarta.inject.Singleton;
import io.quarkus.vertx.http.HttpServerOptionsCustomizer;
@Singleton (1)
public class MyCustomizer implements HttpServerOptionsCustomizer {
@Override
public void customizeHttpServer(HttpServerOptions options) { (2)
options.setPort(9998);
}
}
| 1 | クラスをマネージドBeanにすることで、QuarkusはVert.xサーバーの起動時にカスタマイザーを考慮します。 |
| 2 | この場合、HTTPサーバーのカスタマイズにしか関心がないので、 customizeHttpServer メソッドをオーバーライドするだけですが、 HttpServerOptionsCustomizer ではHTTPSサーバーとドメイン・ソケット・サーバーも設定できることに注意して下さい。 |
14. HTTP サーバーの起動時にロジックを実行する方法
HTTP サーバーの起動時にカスタムアクションを実行するには、非同期 の CDI オブザーバーメソッドを宣言する必要があります。
Quarkus は、対応する HTTP サーバーが設定されたホストとポートでリッスンを開始すると、io.quarkus.vertx.http.HttpServerStart、io.quarkus.vertx.http.HttpsServerStart、および io.quarkus.vertx.http.DomainSocketServerStart タイプの CDI イベントを 非同期的 に起動します。
HttpServerStart example@ApplicationScoped
public class MyListener {
void httpStarted(@ObservesAsync HttpServerStart start) { (1)
// ...notified when the HTTP server starts listening
}
}
| 1 | 非同期の HttpServerStart オブザーバーメソッドは、HttpServerStart パラメーターに @jakarta.enterprise.event.ObservesAsync をアノテーションすることで宣言できます。 |
It’s not possible to use the StartupEvent for this particular use case because this CDI event is fired before the HTTP server is started.
|
15. リバースプロキシーの背後での実行
Quarkus は、プロキシーサーバーが関与すると変更されたり失われたりするクライアント側の情報を保持するために、追加でヘッダー ( 例: X-Forwarded-Host ) を生成するプロキシーを介してアクセスされる可能性があります。このようなシナリオでは、 Quarkus は、これらのヘッダーの値を反映して、プロトコル、ホスト、ポート、 URI などの情報を自動的に更新するように設定することができます。
| Activating this feature leaves the server exposed to several security issues (i.e. information spoofing). Consider activate it only when running behind a reverse proxy. |
この機能を設定するには、 src/main/resources/application.properties に以下の行を記述してください。
quarkus.http.proxy.proxy-address-forwarding=true
デファクトスタンダードのヘッダー ( Forwarded header ) だけを考慮するためには、 src/main/resources/application.properties に以下の行を記述してください。
quarkus.http.proxy.allow-forwarded=true
非標準のヘッダーのみを考慮するには、代わりに以下の行を src/main/resources/application.properties に記述してください。
quarkus.http.proxy.proxy-address-forwarding=true
quarkus.http.proxy.allow-x-forwarded=true
quarkus.http.proxy.enable-forwarded-host=true
quarkus.http.proxy.enable-forwarded-prefix=true
quarkus.http.proxy.trusted-proxies=127.0.0.1 (1)
| 1 | 信頼できるプロキシをIPアドレス 127.0.0.1 で設定します。それ以外のアドレスからのリクエストヘッダーは無視されます。 |
Alternatively, in mTLS environments where proxy IP addresses are not stable (e.g., Kubernetes), you can trust a proxy by its TLS client certificate Subject DN.
The proxy is trusted when its certificate’s Subject DN contains all components specified in any configured value.
For example, CN=my-proxy,O=MyOrg matches a certificate with Subject DN CN=my-proxy,O=MyOrg,C=US.
When no configured DN matches, forwarded headers are ignored and the original connection values are used:
quarkus.http.proxy.trusted-proxy[0].subject-dn=CN=my-proxy (1) (2) (3)
quarkus.http.proxy.trusted-proxy[1].subject-dn=CN=envoy-client,O=MyOrg
| 1 | DNs must be in RFC 2253 format. |
| 2 | This option cannot be combined with quarkus.http.proxy.trusted-proxies. |
| 3 | TLS client authentication must be enabled via quarkus.http.ssl.client-auth set to request or required. |
Configure enough DN components to uniquely identify your proxy. Using only CN=my-proxy will match any certificate with that CN, regardless of issuing organization.
|
When multiple CAs are trusted, different CAs could issue certificates with the same Subject DN. To also verify the trust anchor, reference a certificate alias in the HTTP server’s truststore. Both conditions must match — the Subject DN and the trust anchor. The following example uses the TLS centralized configuration to set up mTLS and proxy trust:
quarkus.tls.key-store.p12.path=server-keystore.p12
quarkus.tls.key-store.p12.password=secret
quarkus.tls.trust-store.p12.path=server-truststore.p12 (1)
quarkus.tls.trust-store.p12.password=secret
quarkus.http.ssl.client-auth=request
# Proxy trust
quarkus.http.proxy.proxy-address-forwarding=true
quarkus.http.proxy.allow-forwarded=true
quarkus.http.proxy.trusted-proxy[0].subject-dn=CN=my-proxy,O=MyOrg
quarkus.http.proxy.trusted-proxy[0].truststore-alias=my-proxy-ca (2)
| 1 | The truststore must be configured via the TLS registry and must contain a certificate entry with alias my-proxy-ca. |
| 2 | The alias is resolved from server-truststore.p12. |
When the truststore is configured with PEM certificates, aliases are assigned automatically as cert-0, cert-1, and so on, based on the order in the configuration:
quarkus.tls.trust-store.pem.certs=proxy-ca.crt,other-ca.crt (1)
quarkus.http.proxy.trusted-proxy[0].truststore-alias=cert-0 (2)
| 1 | proxy-ca.crt becomes cert-0, other-ca.crt becomes cert-1. |
| 2 | References proxy-ca.crt. |
Since PEM aliases depend on ordering, we recommend using a PKCS12 truststore to avoid certificate list ordering issues.
| The configured Subject DN is trusted to be unique only among clients signed by the CA referenced by the truststore alias. Only reference a CA that you control or trust not to issue another certificate with the same Subject DN. |
標準ヘッダーと非標準ヘッダーに関連する両方の設定を組み合わせることができますが、標準ヘッダーの設定が優先されます。ただし、これらを組み合わせると、プロキシーによって上書きされない forwarded ヘッダーを使用してクライアントがリクエストを偽造できるため、セキュリティーに影響があります。したがって、プロキシーはクライアントから予期しない Forwarded または X-Forwarded-* ヘッダーを削除する必要があります。
By default, the proto values from Forwarded and X-Forwarded-Proto headers are validated against the URI scheme syntax.
Requests with an invalid proto value receive a 400 Bad Request response.
To disable this validation, set the quarkus.http.proxy.forwarded-proto-validation configuration property to none.
サポートされている転送アドレスヘッダーは以下の通りです。
-
Forwarded -
X-Forwarded-Proto -
X-Forwarded-Host -
X-Forwarded-Port -
X-Forwarded-Ssl -
X-Forwarded-Prefix
16. SameSite クッキー
例えば、クッキー名と SameSite 属性を記載することで、 Quarkus のエンドポイントによって設定された任意のクッキーに SameSite クッキープロパティを簡単に追加することができます。
quarkus.http.same-site-cookie.jwt.value=Lax
quarkus.http.same-site-cookie.session.value=Strict
この設定では、 jwt クッキーは SameSite=Lax 属性を持ち、 session クッキーは SameSite=Strict 属性を持つことになります。
17. サーブレットの設定
サーブレットを使用するには、明示的に quarkus-undertow を含める必要があります。
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow</artifactId>
</dependency>
implementation("io.quarkus:quarkus-undertow")
17.1. undertow-handlers.conf
undertow-handlers.conf ファイルを使用することで、 Undertow 述語言語を利用することができます。このファイルは、アプリケーション jar の META-INF ディレクトリーに配置する必要があります。このファイルには、Undertow 述語言語 を使用して定義されたハンドラーが含まれています。
17.2. web.xml
設定ファイルとして web.xml を使用している場合は、src/main/resources/META-INF ディレクトリーに配置します。
17.3. 組み込みのルート・オーダー値
ルートオーダーの値は、Vert.x のルート io.vertx.ext.web.Route.order(int) 関数で指定される値です。
Quarkusは、特定のオーダー値を持ついくつかのルートを登録します。
定数は io.quarkus.vertx.http.runtime.RouteConstants クラスで定義され、以下の表に記載されています。
カスタムルートは、Quarkusやエクステンションが提供する機能を妨げないように、値20000以上のオーダーを定義する必要があります。
io.quarkus.vertx.http.runtime.RouteConstants で定義されているルート順定数および既知の拡張:
ルートオーダー値 |
定数名 |
起源 |
|
|
コンフィギュレーションで有効になっていれば、アクセスログハンドラ。 |
|
|
コンフィギュレーションで有効になっていれば、開始時間を追加するハンドラ。 |
|
|
-代替ボディ・ハンドラー。 |
|
|
コンフィギュレーションで指定されたヘッダーを追加するハンドラ。 |
|
|
Host validation handler of the management router. |
|
|
管理ルーターのCORS-Originハンドラ。 |
|
|
管理ルーターのボディハンドラ。 |
|
|
ボディハンドラー |
|
|
アップロードボディのサイズ制限を実施するルート。 |
|
|
圧縮ハンドラ。 |
|
|
デフォルトルートよりも優先されるルート(この値からオフセットを追加する)。 |
|
|
デフォルトのルート順序(すなわち、静的リソース、サーブレット)。 |
|
|
デフォルトルートより優先されないルート(この値からオフセットを追加) |
17.4. Undertow の設定
Undertow Servlet エクステンションを使用する場合、以下の設定プロパティーを使用できます。
| 設定プロパティ | タイプ | デフォルト | 説明 |
|---|---|---|---|
|
文字列のリスト |
|
例: ---- quarkus.undertow.disallowed-methods=TRACE,TRACK ---- |
|
boolean |
false |
有効にすると、 Undertow はリクエスト開始のタイムスタンプを記録します。タイミング計測、ロギング、およびリクエストトレースに役立ちます。 |
|
int |
1000 |
許可される HTTP パラメーターの最大数。パラメーターベースの DoS 攻撃に対する保護を提供します。 |