Class: Unicorn::App::ExecCgi

Inherits:
Struct
  • Object
show all
Defined in:
lib/unicorn/app/exec_cgi.rb

Overview

This class is highly experimental (even more so than the rest of Unicorn) and has never run anything other than cgit.

Constant Summary collapse

CHUNK_SIZE =
16384
PASS_VARS =
%w(
  CONTENT_LENGTH
  CONTENT_TYPE
  GATEWAY_INTERFACE
  AUTH_TYPE
  PATH_INFO
  PATH_TRANSLATED
  QUERY_STRING
  REMOTE_ADDR
  REMOTE_HOST
  REMOTE_IDENT
  REMOTE_USER
  REQUEST_METHOD
  SERVER_NAME
  SERVER_PORT
  SERVER_PROTOCOL
  SERVER_SOFTWARE
).map { |x| x.freeze }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ExecCgi

Intializes the app, example of usage in a config.ru

map "/cgit" do
  run Unicorn::App::ExecCgi.new("/path/to/cgit.cgi")
end


35
36
37
38
39
40
41
42
# File 'lib/unicorn/app/exec_cgi.rb', line 35

def initialize(*args)
  self.args = args
  first = args[0] or
    raise ArgumentError, "need path to executable"
  first[0] == ?/ or args[0] = ::File.expand_path(first)
  File.executable?(args[0]) or
    raise ArgumentError, "#{args[0]} is not executable"
end

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



9
10
11
# File 'lib/unicorn/app/exec_cgi.rb', line 9

def args
  @args
end

Instance Method Details

#call(env) ⇒ Object

Calls the app



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/unicorn/app/exec_cgi.rb', line 45

def call(env)
  out, err = Unicorn::Util.tmpio, Unicorn::Util.tmpio
  inp = force_file_input(env)
  pid = fork { run_child(inp, out, err, env) }
  inp.close
  pid, status = Process.waitpid2(pid)
  write_errors(env, err, status) if err.stat.size > 0
  err.close

  return parse_output!(out) if status.success?
  out.close
  [ 500, { 'Content-Length' => '0', 'Content-Type' => 'text/plain' }, [] ]
end