Repository: puma/puma
File: test/test_puma_server.rb (Ruby)

Code before:
    response = send_http_read_response req

    # No "Connection: close" header.
    assert_equal ["Content-Type: plain/text", "Content-Length: 6"], response.headers
    assert_equal "hello\n", response.body
  end


  def test_http_11_enable_keep_alives_true
    server_run(enable_keep_alives: true) { [200, {"Content-Type" => "plain/text"}, ["hello\n"]] }

    req  = "GET / HTTP/1.1\r\n\r\n"
    response = send_http_read_response req

    # No "Connection: close" header.
    assert_equal ["Content-Type: plain/text", "Content-Length: 6"], response.headers
    assert_equal "hello\n", response.body
  end

  def test_http_11_enable_keep_alives_false
    server_run(enable_keep_alives: false) { [200, {"Content-Type" => "plain/text"}, ["hello\n"]] }

    req  = "GET / HTTP/1.1\r\n\r\n"
    response = send_http_read_response req

    # No "Connection: close" header.
    assert_equal ["Content-Type: plain/text", "Connection: close", "Content-Length: 6"], response.headers
    assert_equal "hello\n", response.body
  end

  def test_http_10_keep_alive_with_body
    server_run { [200, {"Content-Type" => "plain/text"}, ["hello\n"]] }

    req = "GET / HTTP/1.0\r\nConnection: Keep-Alive\r\n\r\n"

    response = send_http_read_response req

    assert_equal "HTTP/1.0 200 OK", response.status
    assert_equal ["Content-Type: plain/text", "Connection: Keep-Alive", "Content-Length: 6"],
      response.headers
    assert_equal "hello\n", response.body
  end

  def test_http_10_close_with_body
    server_run { [200, {"Content-Type" => "plain/text"}, ["hello"]] }

    response = send_http_read_response "GET / HTTP/1.0\r\nConnection: close\r\n\r\n"

    assert_equal "HTTP/1.0 200 OK\r\nContent-Type: plain/text\r\nContent-Length: 5\r\n\r\nhello", response
  end


Review comment (suggestion):
```suggestion
    # Assert the "Connection: close" header is present with keep-alives disabled.
```

Code after:
    response = send_http_read_response req

    # No "Connection: close" header.
    assert_equal ["Content-Type: plain/text", "Content-Length: 6"], response.headers
    assert_equal "hello\n", response.body
  end
  def test_http_11_enable_keep_alives_true
    server_run(enable_keep_alives: true) { [200, {"Content-Type" => "plain/text"}, ["hello\n"]] }

    req  = "GET / HTTP/1.1\r\n\r\n"
    response = send_http_read_response req

    # No "Connection: close" header.
    assert_equal ["Content-Type: plain/text", "Content-Length: 6"], response.headers
    assert_equal "hello\n", response.body
  end

  def test_http_11_enable_keep_alives_false
    server_run(enable_keep_alives: false) { [200, {"Content-Type" => "plain/text"}, ["hello\n"]] }

    req  = "GET / HTTP/1.1\r\n\r\n"
    response = send_http_read_response req

    # Assert the "Connection: close" header is present with keep-alives disabled.
    assert_equal ["Content-Type: plain/text", "Connection: close", "Content-Length: 6"], response.headers
    assert_equal "hello\n", response.body
  end

  def test_http_10_keep_alive_with_body
    server_run { [200, {"Content-Type" => "plain/text"}, ["hello\n"]] }

    req = "GET / HTTP/1.0\r\nConnection: Keep-Alive\r\n\r\n"

    response = send_http_read_response req

    assert_equal "HTTP/1.0 200 OK", response.status
    assert_equal ["Content-Type: plain/text", "Connection: Keep-Alive", "Content-Length: 6"],
      response.headers
    assert_equal "hello\n", response.body
  end

  def test_http_10_close_with_body
    server_run { [200, {"Content-Type" => "plain/text"}, ["hello"]] }

    response = send_http_read_response "GET / HTTP/1.0\r\nConnection: close\r\n\r\n"

    assert_equal "HTTP/1.0 200 OK\r\nContent-Type: plain/text\r\nContent-Length: 5\r\n\r\nhello", response
  end

  def test_http_10_keep_alive_without_body
    server_run { [204, {}, []] }