Sha256: 16ca07b13b16fa79b449a6bbe3c09c5451461c1f57781ed76c5f3cf5259349da

Contents?: true

Size: 760 Bytes

Versions: 19

Compression:

Stored size: 760 Bytes

Contents

# frozen_string_literal: true

require_relative "../utils/http_status_code"

##
# Module responsible to filter and mount HTTP responses
module ResponseDataFilter
  include HttpStatusCode

  def self.mount_response(status, headers, body)
    "#{mount_first_response_line(status, headers)}#{mount_response_headers(headers)}#{body}"
  end

  def self.mount_first_response_line(status, headers)
    separator = " \r\n\r\n"
    separator = " \r\n" unless headers.nil?

    "HTTP/1.1 #{status} #{HTTP_STATUS_CODE_MAP[status]}#{separator}"
  end

  def self.mount_response_headers(headers)
    return "" if headers.nil?

    response = ""
    headers.each do |key, value|
      response += "#{key}: #{value}\r\n"
    end
    response += "\r\n"
    response
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
macaw_framework-1.3.0 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.2.6 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.2.5 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.2.4 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.2.3 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.2.2 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.2.1 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.2.0 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.1.8 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.1.7 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.1.6 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.1.5 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.1.4 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.1.3 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.1.2 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.1.1 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.1.0 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.0.5 lib/macaw_framework/data_filters/response_data_filter.rb
macaw_framework-1.0.4 lib/macaw_framework/data_filters/response_data_filter.rb