Module: ResponseDataFilter

Includes:
HttpStatusCode
Defined in:
lib/macaw_framework/data_filters/response_data_filter.rb

Overview

Module responsible to filter and mount HTTP responses

Constant Summary

Constants included from HttpStatusCode

HttpStatusCode::HTTP_STATUS_CODE_MAP

Class Method Summary collapse

Class Method Details

.mount_first_response_line(status, headers) ⇒ Object



14
15
16
17
18
19
# File 'lib/macaw_framework/data_filters/response_data_filter.rb', line 14

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

.mount_response(status, headers, body) ⇒ Object



10
11
12
# File 'lib/macaw_framework/data_filters/response_data_filter.rb', line 10

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

.mount_response_headers(headers) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/macaw_framework/data_filters/response_data_filter.rb', line 21

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