armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Reuse VirtualHostBuilder on the same hostnamePattern

Open yejinio opened this issue 1 year ago โ€ข 3 comments

Motivation:

I registered each virtual host with the same hostname, the registered routes cannot be not found. Because VirtualHostBuilder creates new builder even if hostname is the same. However, it does reuse them on the same port. So, I think it's better to reuse them on the same hostname.

Modifications:

  • ServerBuilder.virtualHost(hostnamePattern) and ServerBuilder.virtualHost(defaultHostname, hostnamePattern) checks whether there is builders with the same hostname. If there is, returns this builder.

Result:

  • Reuse VirtualHostBuilder on the same hostname.
  • Even if you register each one on a virtual host with the same hostname, they will be merged.

yejinio avatar Jan 29 '24 05:01 yejinio

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jan 29 '24 05:01 CLAassistant

๐Ÿ” Build Scanยฎ (commit: 33630faf637607483ab753e890723dcc799eeda6)

Job name Status Build Scanยฎ
build-windows-latest-jdk-19 โœ… https://ge.armeria.dev/s/ipk5uvwhx7mqg
build-self-hosted-unsafe-jdk-8 โŒ (failure) https://ge.armeria.dev/s/hitgjcglcsyee
build-self-hosted-unsafe-jdk-17-min-java-17-coverage โœ… https://ge.armeria.dev/s/yhbdtw5o2clse
build-self-hosted-unsafe-jdk-17-min-java-11 โœ… https://ge.armeria.dev/s/34cbrqddglqli
build-self-hosted-unsafe-jdk-17-leak โœ… https://ge.armeria.dev/s/3jlcdhfdi25oi
build-self-hosted-unsafe-jdk-11 โœ… https://ge.armeria.dev/s/6hrvtkpzq5g4c
build-macos-12-jdk-19 โœ… https://ge.armeria.dev/s/xzeyacjvivcn2

github-actions[bot] avatar Jan 30 '24 07:01 github-actions[bot]

Codecov Report

Attention: Patch coverage is 80.00000% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 74.09%. Comparing base (8678567) to head (283b7ec). Report is 16 commits behind head on main.

Files Patch % Lines
...om/linecorp/armeria/server/VirtualHostBuilder.java 63.63% 1 Missing and 3 partials :warning:
.../java/com/linecorp/armeria/server/VirtualHost.java 62.50% 0 Missing and 3 partials :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5418      +/-   ##
============================================
+ Coverage     74.04%   74.09%   +0.04%     
- Complexity    20871    20986     +115     
============================================
  Files          1809     1819      +10     
  Lines         76857    77332     +475     
  Branches       9809     9880      +71     
============================================
+ Hits          56912    57300     +388     
- Misses        15304    15375      +71     
- Partials       4641     4657      +16     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 07 '24 06:02 codecov[bot]

gentle ping @yejinio ๐Ÿ™‡

jrhee17 avatar Mar 28 '24 02:03 jrhee17

I've added a small commit which

  • Deprecates ServerBuilder#virtualHost methods that doesn't support VirtualHostBuilder reuse
  • Adds a ServerBuilder#withVirtualHost which supports VirtualHostBuilder reuse
  • Deprecates VirtualHostBuilder#hostnamePattern which makes VirtualHostBuilder reuse ambiguous

Let me know if the changes don't make sense ๐Ÿ™‡ https://github.com/line/armeria/pull/5418/commits/0d0edef32cefac38f31ae7d525bcfd57e7cc3311

jrhee17 avatar Apr 02 '24 07:04 jrhee17