Sha256: 1c0a52f9f43497345f64668178e1588c556760e7b9e1dac574a341b14ef539f7

Contents?: true

Size: 810 Bytes

Versions: 6

Compression:

Stored size: 810 Bytes

Contents

# frozen_string_literal: true

require_relative("request")
require_relative("response")

module Zapp
  module HTTPContext
    # Context containing request and response
    class Context
      attr_reader(:req, :res, :socket)

      def initialize(socket:, logger: Zapp::Logger)
        @socket = socket
        @req = Zapp::HTTPContext::Request.new(socket: socket)
        @res = Zapp::HTTPContext::Response.new(socket: socket)
      rescue Puma::HttpParserError => e
        res.write(data: "Invalid HTTP request", status: 400, headers: {})
        logger.warn("Puma parser error: #{e}")
        logger.debug("HTTP request raw: #{context.req.raw}")
      end

      def close
        @socket.close
      end

      def client_closed?
        req.data["HTTP_CONNECTION"] == "close"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
zapp-0.2.6 lib/zapp/http_context/context.rb
zapp-0.2.5 lib/zapp/http_context/context.rb
zapp-0.2.4 lib/zapp/http_context/context.rb
zapp-0.2.3 lib/zapp/http_context/context.rb
zapp-0.2.2 lib/zapp/http_context/context.rb
zapp-0.2.1 lib/zapp/http_context/context.rb