Method: CloudEvents::HttpBinding#decode_rack_env

Defined in:
lib/cloud_events/http_binding.rb

#decode_rack_env(env, **format_args) ⇒ CloudEvents::Event, ...

Deprecated.

Will be removed in version 1.0. Use #decode_event instead.

Decode an event from the given Rack environment hash. Following the CloudEvents spec, this chooses a handler based on the Content-Type of the request.

Parameters:

  • env (Hash)

    The Rack environment.

  • format_args (keywords)

    Extra args to pass to the formatter.

Returns:

  • (CloudEvents::Event)

    if the request includes a single structured or binary event.

  • (Array<CloudEvents::Event>)

    if the request includes a batch of structured events.

  • (nil)

    if the request does not appear to be a CloudEvent.

Raises:



246
247
248
249
250
251
252
253
# File 'lib/cloud_events/http_binding.rb', line 246

def decode_rack_env(env, **format_args)
  content_type_string = env["CONTENT_TYPE"]
  content_type = ContentType.new(content_type_string) if content_type_string
  content = read_with_charset(env["rack.input"], content_type&.charset)
  env["rack.input"].rewind rescue nil
  decode_binary_content(content, content_type, env, true, **format_args) ||
    decode_structured_content(content, content_type, false, **format_args)
end