Class: Landline::Server

Inherits:
Path show all
Defined in:
lib/landline/server.rb

Overview

A specialized path that can be used directly as a Rack application.

Constant Summary collapse

Context =
ServerContext

Constants inherited from Path

Path::ProcContext

Instance Attribute Summary

Attributes inherited from Path

#bounce, #children, #pipeline, #properties, #request

Attributes inherited from Node

#remap, #root

Instance Method Summary collapse

Methods inherited from Path

#filter, #postprocess, #preprocess, #process

Methods inherited from Node

#go, #process, #reject

Constructor Details

#initialize(parent: nil, **args, &setup) ⇒ Server

Returns a new instance of Server.

Parameters:

  • parent (Landline::Node, nil) (defaults to: nil)

    Parent object to inherit properties to

  • setup (#call)

    Setup block



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/landline/server.rb', line 17

def initialize(parent: nil, **args, &setup)
  super("", parent: nil, **args, &setup)
  return if parent

  {
    "index" => [],
    "handle.default" => proc do |code, backtrace: nil|
      page = Landline::Util.default_error_page(code, backtrace)
      headers = {
        "content-length": page.bytesize,
        "content-type": "text/html"
      }
      [headers, page]
    end,
    "path" => "/"
  }.each { |k, v| @properties[k] = v unless @properties[k] }
end

Instance Method Details

#call(env) ⇒ Array(Integer,Hash,Array)

Rack ingress point. This should not be called under any circumstances twice in the same application, although server nesting for the purpose of creating virtual hosts is allowed.

Parameters:

  • env (Hash)

Returns:

  • (Array(Integer,Hash,Array))


40
41
42
43
44
45
46
47
# File 'lib/landline/server.rb', line 40

def call(env)
  request = Landline::Request.new(env)
  response = catch(:finish) do
    go(request)
  end
  request.run_postprocessors(response)
  Response.convert(response).finalize
end