test_12_reuse.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #***************************************************************************
  4. # _ _ ____ _
  5. # Project ___| | | | _ \| |
  6. # / __| | | | |_) | |
  7. # | (__| |_| | _ <| |___
  8. # \___|\___/|_| \_\_____|
  9. #
  10. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  11. #
  12. # This software is licensed as described in the file COPYING, which
  13. # you should have received as part of this distribution. The terms
  14. # are also available at https://curl.se/docs/copyright.html.
  15. #
  16. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. # copies of the Software, and permit persons to whom the Software is
  18. # furnished to do so, under the terms of the COPYING file.
  19. #
  20. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. # KIND, either express or implied.
  22. #
  23. # SPDX-License-Identifier: curl
  24. #
  25. ###########################################################################
  26. #
  27. import difflib
  28. import filecmp
  29. import logging
  30. import os
  31. import pytest
  32. from testenv import Env, CurlClient
  33. log = logging.getLogger(__name__)
  34. @pytest.mark.skipif(condition=Env.curl_uses_lib('bearssl'), reason='BearSSL too slow')
  35. @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason=f"curl without SSL")
  36. class TestReuse:
  37. # check if HTTP/1.1 handles 'Connection: close' correctly
  38. @pytest.mark.parametrize("proto", ['http/1.1'])
  39. def test_12_01_h1_conn_close(self, env: Env,
  40. httpd, nghttpx, repeat, proto):
  41. httpd.clear_extra_configs()
  42. httpd.set_extra_config('base', [
  43. f'MaxKeepAliveRequests 1',
  44. ])
  45. httpd.reload()
  46. count = 100
  47. curl = CurlClient(env=env)
  48. urln = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{count-1}]'
  49. r = curl.http_download(urls=[urln], alpn_proto=proto)
  50. r.check_response(count=count, http_status=200)
  51. # Server sends `Connection: close` on every 2nd request, requiring
  52. # a new connection
  53. delta = 5
  54. assert (count/2 - delta) < r.total_connects < (count/2 + delta)
  55. @pytest.mark.parametrize("proto", ['http/1.1'])
  56. def test_12_02_h1_conn_timeout(self, env: Env,
  57. httpd, nghttpx, repeat, proto):
  58. httpd.clear_extra_configs()
  59. httpd.set_extra_config('base', [
  60. f'KeepAliveTimeout 1',
  61. ])
  62. httpd.reload()
  63. count = 5
  64. curl = CurlClient(env=env)
  65. urln = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{count-1}]'
  66. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  67. '--rate', '30/m',
  68. ])
  69. r.check_response(count=count, http_status=200)
  70. # Connections time out on server before we send another request,
  71. assert r.total_connects == count