Module: Xenon::Routing::HeaderDirectives

Includes:
RouteDirectives
Included in:
Directives
Defined in:
lib/xenon/routing/header_directives.rb

Instance Method Summary collapse

Methods included from RouteDirectives

#complete, #extract, #extract_request, #fail, #map_request, #map_response, #reject

Instance Method Details

#header(name) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/xenon/routing/header_directives.rb', line 14

def header(name)
  optional_header(name) do |value|
    if value
      yield value
    else
      reject Rejection.new(:header, { required: name })
    end
  end
end

#optional_header(name) ⇒ Object



8
9
10
11
12
# File 'lib/xenon/routing/header_directives.rb', line 8

def optional_header(name)
  extract_request do |request|
    yield request.header(name)
  end
end

#respond_with_header(header) ⇒ Object



24
25
26
27
28
# File 'lib/xenon/routing/header_directives.rb', line 24

def respond_with_header(header)
  map_response -> r { r.copy(headers: r.headers.add(header)) } do
    yield
  end
end