oaf 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDY5ZmIzZmNiOTk3MDVjMjRhYWI1ZTc2Y2E4NjJkZWExM2MxMjg2NQ==
4
+ YWEwNzM1MGU4YmJkNGRmYmZiZmQ5N2I3YWQyNjEyYzkyYjM0ZWRiOQ==
5
5
  data.tar.gz: !binary |-
6
- OTBlZmIwYTYxMTNiOTkyYjIwZjc4ZjBkMDIxNDA2NjZhZGMxOGFiMQ==
6
+ ZDVhMjQ1ZWJkMWNlNmY1ZjYxOGI3Y2ZkOTZjOWNiYmFhNWI2MmJlMg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDk1ZWExZjdiZjUzYjY2ZjI1OGFkN2MzZGJiZDM4ODAxMDgzYmIyYmU1MDkw
10
- M2EzMTcwZGEzZGQ5ZDVlODc5YWI3MTU3MmM5ODY5MjhiMDQ2YTQwNGZlZDAw
11
- Nzg5MTRmZDZiMzk3NGZjYzg1M2I1NmE1MmJhZDAzZmJhOTgzYTA=
9
+ ZWM5ODdmYTQzNDE4Y2YxMWEwZTViMmQwOTQ2YzRjYWNiNTA4Yjk5N2EyZDdi
10
+ YjI0ZTMwZTlhODMzMGRiZTFiNmRjYzVkMjVjOWQ0NmEyODRiYTg5YjA0ZGUy
11
+ MGRiNGQzODExYzcxMzdiYzJlMTI1MjhhYzEzMjBkY2ViZGUwM2E=
12
12
  data.tar.gz: !binary |-
13
- NGEyMjMxOWU0NGEwZmIxZjEyOTJhMjgwOGNhYmNlMWJhZTE4ZWFhMzhiNjI3
14
- MDAzMzc4MGZiZDdiODQyZTQzZDc3NTRmY2M4NjMzMmVhZGNjNGUyMzY4ZDFl
15
- NmI1NTMwOGViN2VkZjUyYjFlMzk5MGZlNjQ2ODhlMmY2ZWQ3ODY=
13
+ OTAzMjI5OTcxMTk1ZGY5MzY0MjVjMTE1NTE4ZDVlMWNmZWRjM2M5NTdmY2Qw
14
+ ZTE0ZmRkZTNhNTRkYjExMjA5MjJjOTIwOTlkYjM4NDAyMDg5MWRmM2ZkY2Q5
15
+ ZTEzMDdlOGNhNTUxN2YyMmUxZjI1ODRiNzA1YThiNWM3MmIwY2Q=
data/lib/oaf/http.rb CHANGED
@@ -62,7 +62,7 @@ module Oaf
62
62
  server = WEBrick::HTTPServer.new :Port => port
63
63
  server.mount_proc '/' do |req, res|
64
64
  req_body = ''
65
- req_headers = Oaf::Util.format_request_headers req.header
65
+ req_headers = Oaf::Util.format_hash req.header
66
66
  if ['POST', 'PUT'].member? req.request_method
67
67
  begin
68
68
  req_body = req.body
@@ -73,7 +73,7 @@ module Oaf
73
73
  req_body = req.query
74
74
  end
75
75
  file = Oaf::Util.get_request_file path, req.path, req.request_method
76
- out = Oaf::Util.get_output file, req.header, req_body
76
+ out = Oaf::Util.get_output file, req_headers, req_body
77
77
  headers, status, body = Oaf::HTTP.parse_response out
78
78
  headers.each do |name, value|
79
79
  res.header[name] = value
data/lib/oaf/util.rb CHANGED
@@ -20,6 +20,8 @@
20
20
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
 
23
+ require 'open3'
24
+
23
25
  module Oaf
24
26
 
25
27
  module Util
@@ -83,8 +85,8 @@ module Oaf
83
85
  .concat((500..505).to_a).include? code.to_i
84
86
  end
85
87
 
86
- # Format a hash of request headers in preparation for passing it to an
87
- # executable program as an argument.
88
+ # Format a hash in preparation for passing it to an executable program as
89
+ # an argument on the command line.
88
90
  #
89
91
  # == Parameters:
90
92
  # headers::
@@ -94,9 +96,9 @@ module Oaf
94
96
  # A comma-delimited, colon-separated list of header names and values. The
95
97
  # return value of this function should be parsed according to RFC2616.
96
98
  #
97
- def format_request_headers headers
99
+ def format_hash hash
98
100
  result = ''
99
- headers.each do |name, value|
101
+ hash.each do |name, value|
100
102
  result += "#{name}:#{value},"
101
103
  end
102
104
  result.sub!(/,$/, '')
@@ -174,6 +176,22 @@ module Oaf
174
176
  File.exist?(file) ? file : nil
175
177
  end
176
178
 
179
+ # Run a command with stdout and stderr buffered. This suppresses error
180
+ # messages from the server process and enables us to return them in the
181
+ # HTTP response instead.
182
+ #
183
+ # == Parameters:
184
+ # command::
185
+ # The command to execute against the server
186
+ #
187
+ # == Returns:
188
+ # A string of stderr concatenated to stdout.
189
+ #
190
+ def run_buffered command
191
+ stdin, stdout, stderr = Open3.popen3 command
192
+ stdout.read + stderr.read
193
+ end
194
+
177
195
  # Executes a file, or reads its contents if it is not executable, passing
178
196
  # it the request headers and body as arguments, and returns the result.
179
197
  #
@@ -192,7 +210,7 @@ module Oaf
192
210
  if file.nil?
193
211
  out = Oaf::Util.get_default_response
194
212
  elsif File.executable? file
195
- out = %x(#{file} "#{headers}" "#{body}")
213
+ out = Oaf::Util.run_buffered "#{file} '#{headers}' '#{body}'"
196
214
  else
197
215
  out = File.open(file).read
198
216
  end
data/lib/oaf/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
 
23
23
  module Oaf
24
- VERSION = '0.1.15'
24
+ VERSION = '0.1.16'
25
25
  end
@@ -83,19 +83,19 @@ module Oaf
83
83
  describe "Format Request Headers" do
84
84
  it "should return a single key/value for just one header" do
85
85
  headers = [['x-powered-by', 'oaf']]
86
- result = Oaf::Util.format_request_headers headers
86
+ result = Oaf::Util.format_hash headers
87
87
  result.should eq('x-powered-by:oaf')
88
88
  end
89
89
 
90
90
  it "should return a comma-delimited list for multiple headers" do
91
91
  headers = [['x-powered-by', 'oaf'], ['content-type', 'text/plain']]
92
- result = Oaf::Util.format_request_headers headers
92
+ result = Oaf::Util.format_hash headers
93
93
  result.should eq('x-powered-by:oaf,content-type:text/plain')
94
94
  end
95
95
 
96
96
  it "should return nil if no headers present" do
97
97
  headers = []
98
- result = Oaf::Util.format_request_headers headers
98
+ result = Oaf::Util.format_hash headers
99
99
  result.should be_nil
100
100
  end
101
101
  end
@@ -189,11 +189,17 @@ module Oaf
189
189
  @f2.chmod 0644
190
190
  @f2.write "This is a test\n"
191
191
  @f2.close
192
+
193
+ @f3 = Tempfile.new 'oaf'
194
+ @f3.chmod 0755
195
+ @f3.write "#!/bin/bash\necho 'This is a test' 1>&2\n"
196
+ @f3.close
192
197
  end
193
198
 
194
199
  after(:all) do
195
200
  @f1.delete
196
201
  @f2.delete
202
+ @f3.delete
197
203
  end
198
204
 
199
205
  it "should execute a file if it is executable" do
@@ -210,5 +216,10 @@ module Oaf
210
216
  result = Oaf::Util.get_output nil, nil, nil
211
217
  result.should eq(Oaf::Util.get_default_response)
212
218
  end
219
+
220
+ it "should catch stderr output instead of dumping it" do
221
+ result = Oaf::Util.get_output @f3.path, nil, nil
222
+ result.should eq("This is a test\n")
223
+ end
213
224
  end
214
225
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Uber