test_12_reuse.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.skipif(condition=Env.httpd_is_at_least('2.5.0'),
  56. reason=f"httpd 2.5+ handles KeepAlives different")
  57. @pytest.mark.parametrize("proto", ['http/1.1'])
  58. def test_12_02_h1_conn_timeout(self, env: Env,
  59. httpd, nghttpx, repeat, proto):
  60. httpd.clear_extra_configs()
  61. httpd.set_extra_config('base', [
  62. f'KeepAliveTimeout 1',
  63. ])
  64. httpd.reload()
  65. count = 5
  66. curl = CurlClient(env=env)
  67. urln = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{count-1}]'
  68. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  69. '--rate', '30/m',
  70. ])
  71. r.check_response(count=count, http_status=200)
  72. # Connections time out on server before we send another request,
  73. assert r.total_connects == count