fcgiwrap 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +7 -0
- data/README +41 -0
- data/lib/fcgiwrap.rb +87 -0
- metadata +56 -0
data/ChangeLog
ADDED
data/README
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
FastCGI Wrapper for ruby
|
3
|
+
- a trick to wrap CGI in FastCGI easily
|
4
|
+
|
5
|
+
Author: Tatsuki Sugiura <sugi@nemui.org>
|
6
|
+
|
7
|
+
Licence: Ruby's
|
8
|
+
|
9
|
+
Install:
|
10
|
+
|
11
|
+
Just copy fcgiwrap.rb to ruby's libdir or cgi's current directory.
|
12
|
+
|
13
|
+
Description:
|
14
|
+
|
15
|
+
This library was written for wrapping CGI to FastCGI without
|
16
|
+
modification.
|
17
|
+
|
18
|
+
FCGIWrap provides just FCGIWrap.each method. The method receives
|
19
|
+
a block and call it for each fcgi request. In this loop, CGI::new()
|
20
|
+
was overrided, then it will return instance of fcgi.
|
21
|
+
|
22
|
+
Usage:
|
23
|
+
|
24
|
+
Write a wrapper script.
|
25
|
+
If you want to wrap foo.cgi, write foo.fcgi like following;
|
26
|
+
|
27
|
+
------
|
28
|
+
#!/usr/bin/ruby
|
29
|
+
require 'fcgiwrap'
|
30
|
+
FCGIWrap.each {
|
31
|
+
load '/path/to/foo.cgi'
|
32
|
+
}
|
33
|
+
------
|
34
|
+
|
35
|
+
Limitation:
|
36
|
+
|
37
|
+
Currently, FCGIWrap can not support some CGIs;
|
38
|
+
- using global variable without initialization
|
39
|
+
- substitution of constant in main routine of cgi
|
40
|
+
(ruby will output warning).
|
41
|
+
|
data/lib/fcgiwrap.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#
|
2
|
+
# FastCGI Wrapper
|
3
|
+
# trick to wrap a cgi in fastcgi easily
|
4
|
+
#
|
5
|
+
# Author: Tatsuki Sugiura <sugi@nemui.org>
|
6
|
+
# Licence: Ruby's
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# Usage:
|
10
|
+
# write wrapper script like following;
|
11
|
+
# require 'fcgiwrap'
|
12
|
+
# FCGIWrap.each {
|
13
|
+
# load '/path/to/original.cgi'
|
14
|
+
# }
|
15
|
+
|
16
|
+
require 'cgi'
|
17
|
+
require 'fcgi'
|
18
|
+
|
19
|
+
# for ruby 1.8 blow
|
20
|
+
if RUBY_VERSION.tr(".", "0").to_i < 10801
|
21
|
+
alias $stdout $defout
|
22
|
+
def ENV.clear
|
23
|
+
ENV.each_key {|k| ENV.delete(k) }
|
24
|
+
end
|
25
|
+
def ENV.update(from)
|
26
|
+
from.each {|k,v| ENV[k] = v}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class FCGIWrap
|
31
|
+
VERSION = "0.1.5"
|
32
|
+
@@cgi = nil
|
33
|
+
@@shutdown = false
|
34
|
+
class << self
|
35
|
+
def cgi
|
36
|
+
@@cgi
|
37
|
+
end
|
38
|
+
|
39
|
+
def each_request
|
40
|
+
trap(:PIPE){ exit }
|
41
|
+
trap(:TERM){ @@cgi ? (@@shutdown = true) : exit }
|
42
|
+
trap(:INT){ @@cgi ? (@@shutdown = true) : exit }
|
43
|
+
FCGI.each_cgi { |@@cgi|
|
44
|
+
ENV.clear
|
45
|
+
ENV.update(@@cgi.env_table)
|
46
|
+
begin
|
47
|
+
yield
|
48
|
+
rescue SystemExit
|
49
|
+
@@shutdown && raise
|
50
|
+
ensure
|
51
|
+
@@cgi = nil
|
52
|
+
#Thread.list.each { |t|
|
53
|
+
# Thread.current == t and next
|
54
|
+
# t.kill
|
55
|
+
#}
|
56
|
+
end
|
57
|
+
@@shutdown && exit
|
58
|
+
}
|
59
|
+
end
|
60
|
+
alias each each_request
|
61
|
+
alias each_cgi each_request
|
62
|
+
alias loop each_request
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Kernel
|
67
|
+
def print(*args)
|
68
|
+
if FCGIWrap.cgi
|
69
|
+
FCGIWrap.cgi.print(*args)
|
70
|
+
else
|
71
|
+
# IGNORE:
|
72
|
+
# STDERR.puts "WARN: Useless print"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
def puts(*args)
|
76
|
+
Kernel.print(*args.map{|s| t = s.dup.to_s; t !~ /\n$/ and t += "\n"; t })
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class CGI
|
81
|
+
class << self
|
82
|
+
def new(*args)
|
83
|
+
FCGIWrap.cgi ? FCGIWrap.cgi : super(*args)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: fcgiwrap
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.5
|
7
|
+
date: 2006-10-16 00:00:00 +09:00
|
8
|
+
summary: A trick to wrap CGI in FastCGI easily
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: sugi@nemui.org
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Tatsuki Sugiura
|
31
|
+
files:
|
32
|
+
- lib/fcgiwrap.rb
|
33
|
+
- README
|
34
|
+
- ChangeLog
|
35
|
+
test_files: []
|
36
|
+
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
extra_rdoc_files:
|
40
|
+
- README
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
requirements: []
|
46
|
+
|
47
|
+
dependencies:
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: fcgi
|
50
|
+
version_requirement:
|
51
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.0.0
|
56
|
+
version:
|