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.



129
130
131
132
133
134
135
136
137
138
# File 'lib/fdk/context.rb', line 129

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.



126
127
128
# File 'lib/fdk/context.rb', line 126

def headers
  @headers
end

#response_headersObject (readonly)

Returns the value of attribute response_headers.



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

def response_headers
  @response_headers
end

Instance Method Details

#methodObject



144
145
146
# File 'lib/fdk/context.rb', line 144

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

#request_urlObject



140
141
142
# File 'lib/fdk/context.rb', line 140

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

#status_code=(val) ⇒ Object



148
149
150
# File 'lib/fdk/context.rb', line 148

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