Sha256: 5980d7f223b92980912bc0b0e3b20cfb4f9d1a1bba9a4bcd74999e5f5093f7e8

Contents?: true

Size: 594 Bytes

Versions: 2

Compression:

Stored size: 594 Bytes

Contents

# frozen_string_literal: true

module Zapp
  module HTTPContext
    # Represents an HTTP response being sent back to a client
    class Response
      def initialize(socket:)
        @socket = socket
      end

      # TODO: Add headers argument
      def write(data:, status:, headers:)
        response = "HTTP/1.1 #{status}\n"

        response += "Content-Length: #{data.size}\n" unless headers["Content-Length"]

        headers.each do |k, v|
          response += "#{k}: #{v}\n"
        end

        response += "\n#{data}\n"

        @socket.write(response)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zapp-0.1.1 lib/zapp/http_context/response.rb
zapp-0.1.0 lib/zapp/http_context/response.rb