mirror of
				https://github.com/HoneyryderChuck/httpx.git
				synced 2025-11-04 00:01:41 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
# frozen_string_literal: true
 | 
						|
 | 
						|
require_relative "test"
 | 
						|
 | 
						|
class KeepAliveServer < TestServer
 | 
						|
  class KeepAliveApp < WEBrick::HTTPServlet::AbstractServlet
 | 
						|
    def do_GET(_req, res) # rubocop:disable Naming/MethodName
 | 
						|
      res.status = 200
 | 
						|
      res["Connection"] = "Keep-Alive"
 | 
						|
      res["Content-Type"] = "application/json"
 | 
						|
      res.body = "{\"counter\": infinity}"
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  class KeepAliveMax2App < WEBrick::HTTPServlet::AbstractServlet
 | 
						|
    def do_GET(_req, res) # rubocop:disable Naming/MethodName
 | 
						|
      res.status = 200
 | 
						|
      res["Connection"] = "Keep-Alive"
 | 
						|
      res["Keep-Alive"] = "max=2"
 | 
						|
      res["Content-Type"] = "application/json"
 | 
						|
      res.body = "{\"counter\": 2}"
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  def initialize(options = {})
 | 
						|
    super
 | 
						|
    mount("/", KeepAliveApp)
 | 
						|
    mount("/2", KeepAliveMax2App)
 | 
						|
  end
 | 
						|
end
 | 
						|
 | 
						|
class KeepAlivePongServer < TestHTTP2Server
 | 
						|
  attr_reader :pings, :pongs
 | 
						|
 | 
						|
  def initialize
 | 
						|
    @sent = false
 | 
						|
    super
 | 
						|
  end
 | 
						|
 | 
						|
  private
 | 
						|
 | 
						|
  def handle_stream(conn, stream)
 | 
						|
    # responds once, then closes the connection
 | 
						|
    if @sent
 | 
						|
      conn.goaway
 | 
						|
      @sent = false
 | 
						|
    else
 | 
						|
      super
 | 
						|
      @sent = true
 | 
						|
    end
 | 
						|
  end
 | 
						|
end
 |