Class: Midori::CleanRoom

Inherits:
Object
  • Object
show all
Defined in:
lib/em-midori/clean_room.rb

Overview

This class is used to be sandbox of requests processing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, middleware = [], body_accept = [String]) ⇒ CleanRoom

Returns a new instance of CleanRoom.

Parameters:

  • request (Midori::Request)

    HTTP request

  • middleware (Array<Midori::Middleware>) (defaults to: [])

    middlewares to run

  • body_accept (Array<Class>) (defaults to: [String])

    what class for body could last middleware accept by default


12
13
14
15
16
17
18
19
# File 'lib/em-midori/clean_room.rb', line 12

def initialize(request, middleware = [], body_accept = [String])
  @status = 200
  @header = Midori::Const::DEFAULT_HEADER.clone
  @body = ''
  @request = request
  @middleware = middleware
  @body_accept = body_accept
end

Instance Attribute Details

#bodyObject

HTTP response body. String could is accepted by default, but could leave for further process with Midori::Midlleware

Returns:

  • (Object)

    the current value of body


7
8
9
# File 'lib/em-midori/clean_room.rb', line 7

def body
  @body
end

#codeFixnum

HTTP response code

Returns:

  • (Fixnum)

    the current value of code


7
8
9
# File 'lib/em-midori/clean_room.rb', line 7

def code
  @code
end

#headerHash

HTTP response header

Returns:

  • (Hash)

    the current value of header


7
8
9
# File 'lib/em-midori/clean_room.rb', line 7

def header
  @header
end

#requestMidori::Request

HTTP request

Returns:


7
8
9
# File 'lib/em-midori/clean_room.rb', line 7

def request
  @request
end

Instance Method Details

#raw_responseMidori::Response

Genenrate response from variables inside Midori::CleanRoom

Returns:


23
24
25
# File 'lib/em-midori/clean_room.rb', line 23

def raw_response
  Midori::Response.new(@status, @header, @body)
end

#use(middleware, *args) ⇒ nil

Add a middleware to a specific route

Parameters:

  • middleware (Class)

    inherited form Midori::Middleware class

  • args (Array<Object>)

    for middleware initialize

Returns:

  • (nil)

    nil


31
32
33
34
35
36
37
38
39
# File 'lib/em-midori/clean_room.rb', line 31

def use(middleware, *args)
  middleware = middleware.new(*args)
  middleware.helper
  @middleware = [] if @middleware.nil?
  @middleware << middleware
  @body_accept.replace middleware.body_accept
  @request = middleware.before(request)
  nil
end