Module: Hyde::DSL::ProbeMethods

Included in:
ProbeBinding
Defined in:
lib/hyde/dsl/probe_methods.rb

Overview

Common methods for Probe objects

Instance Method Summary collapse

Instance Method Details

#bounceObject

Bounce request to the next handler

Raises:

  • (UncaughtThrowError)

    throws :break to get out of the callback



31
32
33
# File 'lib/hyde/dsl/probe_methods.rb', line 31

def bounce
  throw :break
end

#die(errorcode, backtrace: nil) ⇒ Object

Stop execution and generate a boilerplate response with the given code

Parameters:

  • errorcode (Integer)
  • backtrace (Array(String), nil) (defaults to: nil)

Raises:

  • (UncaughtThrowError)

    throws :finish to return back to Server



19
20
21
22
23
24
25
26
27
# File 'lib/hyde/dsl/probe_methods.rb', line 19

def die(errorcode, backtrace: nil)
  throw :finish, [errorcode].append(
    *(@origin.properties["handle.#{errorcode}"] or
      @origin.properties["handle.default"]).call(
        errorcode,
        backtrace: backtrace
      )
  )
end

#header(key, value) ⇒ Object

Set response header (generate response if one doesn’t exist yet)

Parameters:

  • key (String)

    header name

  • value (String)

    header value



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/hyde/dsl/probe_methods.rb', line 47

def header(key, value)
  return status(value) if key.downcase == "status"

  if key.match(/(?:[(),\/:;<=>?@\[\]{}"]|[^ -~])/)
    raise StandardError, "header key has invalid characters"
  end

  if value.match(/[^ -~]/)
    raise StandardError, "value key has invalid characters"
  end

  @origin.response = (@origin.response or Hyde::Response.new)
  key = key.downcase
  @origin.response.add_header(key, value)
end

#remove_header(key, value = nil) ⇒ Object

Delete a header value from the headers hash If no value is provided, deletes all key entries

Parameters:

  • key (String)

    header name

  • value (String, nil) (defaults to: nil)

    header value



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hyde/dsl/probe_methods.rb', line 67

def remove_header(key, value = nil)
  return unless @origin.response

  return if key.downcase == "status"

  if key.match(/(?:[(),\/:;<=>?@\[\]{}"]|[^ -~])/)
    raise StandardError, "header key has invalid characters"
  end

  if value&.match(/[^ -~]/)
    raise StandardError, "value key has invalid characters"
  end

  @origin.response.delete_header(key, value)
end

#requestHyde::Request

Get the current request

Returns:



11
12
13
# File 'lib/hyde/dsl/probe_methods.rb', line 11

def request
  @origin.request
end

#status(status) ⇒ Object Also known as: code

Set response status (generate response if one doesn’t exist yet)

Parameters:

  • status (Integer)

    http status code



37
38
39
40
# File 'lib/hyde/dsl/probe_methods.rb', line 37

def status(status)
  @response = (@response or Hyde::Response.new)
  @response.status = status
end