diff --git a/docker-compose.yml b/docker-compose.yml index a6d2b76a..7b15fe89 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,7 @@ services: - BUNDLE_PATH=/usr/local/bundle - BUNDLE_SILENCE_ROOT_WARNING=1 - BUNDLE_APP_CONFIG=/usr/local/bundle + - HTTPBIN_ALTSVC_HOST=another2 image: ruby:alpine depends_on: - httpproxy @@ -27,6 +28,8 @@ services: - nghttp2 volumes: - ./:/home + links: + - "altsvc-nghttp2:another2" entrypoint: /home/test/support/ci/build.sh @@ -64,8 +67,22 @@ services: volumes: - ./test/support/ci:/home command: - --conf /home/nghttp.conf --no-ocsp - + --conf /home/nghttp.conf --no-ocsp --frontend 0.0.0.0,80;no-tls --frontend 0.0.0.0,443 + + altsvc-nghttp2: + image: registry.gitlab.com/honeyryderchuck/httpx/nghttp2:2 + ports: + - 81:80 + - 444:443 + depends_on: + - httpbin + entrypoint: + /usr/local/bin/nghttpx + volumes: + - ./test/support/ci:/home + command: + --conf /home/nghttp.conf --no-ocsp --frontend 0.0.0.0,80;no-tls --frontend 0.0.0.0,443 --altsvc "h2,443,nghttp2" + httpbin: environment: - DEBUG=True diff --git a/test/http_test.rb b/test/http_test.rb index 19fd1c17..0d1688fe 100644 --- a/test/http_test.rb +++ b/test/http_test.rb @@ -15,6 +15,7 @@ class HTTPTest < Minitest::Test include IO include Timeouts include Errors + include AltSvc if ENV.key?("HTTPBIN_ALTSVC_HOST") include Plugins::Proxy unless ENV.key?("HTTPX_NO_PROXY") include Plugins::Authentication diff --git a/test/https_test.rb b/test/https_test.rb index 92b38b64..16f93886 100644 --- a/test/https_test.rb +++ b/test/https_test.rb @@ -13,6 +13,8 @@ class HTTPSTest < Minitest::Test include IO include Timeouts include Errors + # TODO: uncomment as soon as nghttpx supports altsvc for HTTP/2 + # include AltSvc if ENV.key?("HTTPBIN_ALTSVC_HOST") include Plugins::Proxy unless ENV.key?("HTTPX_NO_PROXY") include Plugins::Authentication diff --git a/test/support/ci/nghttp.conf b/test/support/ci/nghttp.conf index 037883fb..dcdbf079 100644 --- a/test/support/ci/nghttp.conf +++ b/test/support/ci/nghttp.conf @@ -1,5 +1,3 @@ -frontend=0.0.0.0,80;no-tls -frontend=0.0.0.0,443 backend=httpbin,8000 private-key-file=/home/certs/server.key certificate-file=/home/certs/server.crt diff --git a/test/support/http_helpers.rb b/test/support/http_helpers.rb index 6127bd4f..d6589d0d 100644 --- a/test/support/http_helpers.rb +++ b/test/support/http_helpers.rb @@ -8,8 +8,8 @@ module HTTPHelpers private - def build_uri(suffix = "/") - "#{origin}#{suffix || "/"}" + def build_uri(suffix = "/", uri_origin = origin) + "#{uri_origin}#{suffix || "/"}" end def json_body(response) diff --git a/test/support/requests/altsvc.rb b/test/support/requests/altsvc.rb new file mode 100644 index 00000000..93595ef0 --- /dev/null +++ b/test/support/requests/altsvc.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Requests + module AltSvc + def test_altsvc_get + altsvc_origin = origin(ENV["HTTPBIN_ALTSVC_HOST"]) + + HTTPX.wrap do |http| + altsvc_uri = build_uri("/get", altsvc_origin) + response = http.get(altsvc_uri) + verify_status(response, 200) + # this is only needed for http/1.1 + response2 = http.get(altsvc_uri) + verify_status(response2, 200) + # introspection time + pool = http.__send__(:pool) + connections = pool.instance_variable_get(:@connections) + origins = connections.map { |conn| conn.instance_variable_get(:@origin) }.uniq + assert origins.size == 2, "connection didn't follow altsvc (expected a connection for both origins)" + end + end + end +end