Class: FDK::HTTPContext

Inherits:
Object
  • Object
show all
Defined in:
lib/fdk/context.rb

Overview

Represents the context data (inbound && outbound) for the execution passed as HTTP headers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx) ⇒ HTTPContext

Returns a new instance of HTTPContext.



109
110
111
112
113
114
115
116
117
118
# File 'lib/fdk/context.rb', line 109

def initialize(ctx)
  fn_http_h_ = "fn-http-h-"
  @ctx = ctx
  http_headers = {}
  ctx.headers.each do |k, v|
    http_headers[k.sub(fn_http_h_, "")] = v if k.downcase.start_with?(fn_http_h_)
  end
  @headers = InHeaders.new(http_headers, nil)
  @response_headers = OutHeaders.new(ctx.response_headers, ->(s) { fn_http_h_ + s })
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



106
107
108
# File 'lib/fdk/context.rb', line 106

def headers
  @headers
end

#response_headersObject (readonly)

Returns the value of attribute response_headers.



107
108
109
# File 'lib/fdk/context.rb', line 107

def response_headers
  @response_headers
end

Instance Method Details

#methodObject



124
125
126
# File 'lib/fdk/context.rb', line 124

def method
  @ctx.headers["fn-http-method"]
end

#request_urlObject



120
121
122
# File 'lib/fdk/context.rb', line 120

def request_url
  @ctx.headers["fn-http-request-url"]
end

#status_code=(val) ⇒ Object



128
129
130
# File 'lib/fdk/context.rb', line 128

def status_code=(val)
  @ctx.response_headers["fn-http-status"] = val.to_i
end