Sha256: d68c1f2d6642a966c642aa8ed9ef3d919c469454143525422db3156ee21c6311

Contents?: true

Size: 840 Bytes

Versions: 3

Compression:

Stored size: 840 Bytes

Contents

# frozen_string_literal: true

require("webrick")

module Zapp
  module HTTPContext
    # Represents an HTTP Request to be processed by a worker
    class Request
      attr_reader(:raw, :data, :body)

      # Request parsing is done threaded, but not in separate Ractors.
      # So we allocate an HTTP parser per thread and assign it to this hash key in Thread.current
      PARSER_THREAD_HASH_KEY = "PUMA_PARSER_INSTANCE"

      def initialize(socket:)
        # Max Request size of 8KB TODO: Make a config value for this setting
        @raw = socket.readpartial(8192)
        @data = {}

        parser.execute(data, raw, 0)

        @body = Zapp::InputStream.new(string: parser.body)

        parser.reset
      end

      def parser
        Thread.current[PARSER_THREAD_HASH_KEY] ||= Puma::HttpParser.new
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zapp-0.2.4 lib/zapp/http_context/request.rb
zapp-0.2.3 lib/zapp/http_context/request.rb
zapp-0.2.2 lib/zapp/http_context/request.rb