clogger 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/GNUmakefile +1 -0
- data/History.txt +16 -0
- data/README.txt +4 -4
- data/ext/clogger_ext/clogger.c +14 -5
- data/lib/clogger.rb +1 -1
- data/lib/clogger/pure.rb +9 -4
- data/test/test_clogger.rb +29 -0
- metadata +2 -2
data/GNUmakefile
CHANGED
@@ -72,6 +72,7 @@ release: package Manifest.txt $(release_notes) $(release_changes)
|
|
72
72
|
clogger clogger $(VERSION) pkg/clogger-$(VERSION).tgz
|
73
73
|
rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
|
74
74
|
clogger clogger_ext $(VERSION) pkg/clogger_ext-$(VERSION).gem
|
75
|
+
rake post_news
|
75
76
|
endif
|
76
77
|
|
77
78
|
.PHONY: test doc Manifest.txt release
|
data/History.txt
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
=== 0.0.4 / 2009-09-02
|
2
|
+
|
3
|
+
The pure Ruby version now escapes with uppercase A-F
|
4
|
+
characters to match nginx log output. There are now extra
|
5
|
+
checks against badly behaving Rack applications and 500
|
6
|
+
errors will be logged before TypeError is raised if the
|
7
|
+
application response does not conform (minimally) to Rack
|
8
|
+
expectations. Finally, handling of $request (requests
|
9
|
+
without "HTTP_VERSION" set in the Rack env) should now be
|
10
|
+
logged correctly without unnecessary trailing characters.
|
11
|
+
|
12
|
+
Hackers: the primary git repository has been moved to
|
13
|
+
git://git.bogomips.org/clogger.git for now since I'm having
|
14
|
+
issues with pushing to Rubyforge (seems related to Support
|
15
|
+
Requests item #26185).
|
16
|
+
|
1
17
|
=== 0.0.3 / 2009-08-29
|
2
18
|
|
3
19
|
The MRI extension clogger_ext gets GC bug fix and
|
data/README.txt
CHANGED
@@ -78,13 +78,13 @@ somewhere inside the "Rails::Initializer.run do |config|" block:
|
|
78
78
|
|
79
79
|
The latest development happens in git and is published to the following:
|
80
80
|
|
81
|
-
git://
|
82
|
-
git://
|
81
|
+
git://git.bogomips.org/clogger.git
|
82
|
+
git://repo.or.cz/clogger.git
|
83
83
|
|
84
84
|
You may also browse and download snapshot tarballs:
|
85
85
|
|
86
|
-
* http://
|
87
|
-
* http://
|
86
|
+
* http://git.bogomips.org/cgit/clogger.git (cgit)
|
87
|
+
* http://repo.or.cz/w/clogger.git (gitweb)
|
88
88
|
|
89
89
|
The mailing list (see below) is central for coordination and
|
90
90
|
development. Patches should always be sent inline
|
data/ext/clogger_ext/clogger.c
CHANGED
@@ -55,7 +55,7 @@ enum clogger_special {
|
|
55
55
|
CL_SP_response_length,
|
56
56
|
CL_SP_ip,
|
57
57
|
CL_SP_pid,
|
58
|
-
CL_SP_request_uri
|
58
|
+
CL_SP_request_uri
|
59
59
|
};
|
60
60
|
|
61
61
|
struct clogger {
|
@@ -185,7 +185,7 @@ static int str_case_eq(VALUE a, VALUE b)
|
|
185
185
|
struct response_ops { long nr; VALUE ops; };
|
186
186
|
|
187
187
|
/* this can be worse than O(M*N) :<... but C loops are fast ... */
|
188
|
-
static VALUE
|
188
|
+
static VALUE swap_sent_headers_unsafe(VALUE kv, VALUE memo)
|
189
189
|
{
|
190
190
|
struct response_ops *tmp = (struct response_ops *)memo;
|
191
191
|
VALUE key = rb_obj_as_string(RARRAY_PTR(kv)[0]);
|
@@ -214,6 +214,15 @@ static VALUE swap_sent_headers(VALUE kv, VALUE memo)
|
|
214
214
|
return Qnil;
|
215
215
|
}
|
216
216
|
|
217
|
+
static VALUE swap_sent_headers(VALUE kv, VALUE memo)
|
218
|
+
{
|
219
|
+
if (TYPE(kv) != T_ARRAY)
|
220
|
+
rb_raise(rb_eTypeError, "headers not returning pairs");
|
221
|
+
if (RARRAY_LEN(kv) < 2)
|
222
|
+
rb_raise(rb_eTypeError, "headers not returning pairs");
|
223
|
+
return swap_sent_headers_unsafe(kv, memo);
|
224
|
+
}
|
225
|
+
|
217
226
|
static VALUE sent_headers_ops(struct clogger *c)
|
218
227
|
{
|
219
228
|
struct response_ops tmp;
|
@@ -452,12 +461,12 @@ static void append_request(struct clogger *c)
|
|
452
461
|
|
453
462
|
append_request_uri(c);
|
454
463
|
|
455
|
-
rb_str_buf_append(c->log_buf, g_space);
|
456
|
-
|
457
464
|
/* HTTP_VERSION can be injected by malicious clients */
|
458
465
|
tmp = rb_hash_aref(c->env, g_HTTP_VERSION);
|
459
|
-
if (!NIL_P(tmp))
|
466
|
+
if (!NIL_P(tmp)) {
|
467
|
+
rb_str_buf_append(c->log_buf, g_space);
|
460
468
|
rb_str_buf_append(c->log_buf, byte_xs(tmp));
|
469
|
+
}
|
461
470
|
}
|
462
471
|
|
463
472
|
static void append_request_length(struct clogger *c)
|
data/lib/clogger.rb
CHANGED
data/lib/clogger/pure.rb
CHANGED
@@ -62,7 +62,7 @@ private
|
|
62
62
|
def byte_xs(s)
|
63
63
|
s = s.dup
|
64
64
|
s.force_encoding(Encoding::BINARY) if defined?(Encoding::BINARY)
|
65
|
-
s.gsub!(/(['"\x00-\x1f])/) { |x| "\\x#{$1.unpack('H2').first}" }
|
65
|
+
s.gsub!(/(['"\x00-\x1f])/) { |x| "\\x#{$1.unpack('H2').first.upcase}" }
|
66
66
|
s
|
67
67
|
end
|
68
68
|
|
@@ -83,11 +83,11 @@ private
|
|
83
83
|
status = status.to_i
|
84
84
|
status >= 100 && status <= 999 ? ('%03d' % status) : '-'
|
85
85
|
when :request
|
86
|
+
version = env['HTTP_VERSION'] and version = " #{byte_xs(version)}"
|
86
87
|
qs = env['QUERY_STRING']
|
87
88
|
qs.empty? or qs = "?#{byte_xs(qs)}"
|
88
89
|
"#{env['REQUEST_METHOD']} " \
|
89
|
-
"#{request_uri(env)}
|
90
|
-
"#{byte_xs(env['HTTP_VERSION'])}"
|
90
|
+
"#{request_uri(env)}#{version}"
|
91
91
|
when :request_uri
|
92
92
|
request_uri(env)
|
93
93
|
when :request_length
|
@@ -133,7 +133,12 @@ private
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def get_sent_header(headers, match)
|
136
|
-
headers.each
|
136
|
+
headers.each do |pair|
|
137
|
+
Array === pair && pair.size >= 2 or
|
138
|
+
raise TypeError, "headers not returning pairs"
|
139
|
+
key, value = pair
|
140
|
+
match == key.downcase and return value
|
141
|
+
end
|
137
142
|
"-"
|
138
143
|
end
|
139
144
|
|
data/test/test_clogger.rb
CHANGED
@@ -333,6 +333,18 @@ class TestClogger < Test::Unit::TestCase
|
|
333
333
|
assert_equal expect, str.string
|
334
334
|
end
|
335
335
|
|
336
|
+
# rack allows repeated headers with "\n":
|
337
|
+
# { 'Set-Cookie' => "a\nb" } =>
|
338
|
+
# Set-Cookie: a
|
339
|
+
# Set-Cookie: b
|
340
|
+
def test_escape_header_newlines
|
341
|
+
str = StringIO.new
|
342
|
+
app = lambda { |env| [302, { 'Set-Cookie' => "a\nb" }, [] ] }
|
343
|
+
cl = Clogger.new(app, :logger => str, :format => '$sent_http_set_cookie')
|
344
|
+
cl.call(@req)
|
345
|
+
assert_equal "a\\x0Ab\n", str.string
|
346
|
+
end
|
347
|
+
|
336
348
|
def test_request_uri_fallback
|
337
349
|
str = StringIO.new
|
338
350
|
app = lambda { |env| [ 200, {}, [] ] }
|
@@ -373,4 +385,21 @@ class TestClogger < Test::Unit::TestCase
|
|
373
385
|
assert_match %r{#{e}$}m, str
|
374
386
|
end
|
375
387
|
|
388
|
+
def test_broken_header_response
|
389
|
+
str = StringIO.new
|
390
|
+
app = lambda { |env| [302, [ %w(a) ], []] }
|
391
|
+
cl = Clogger.new(app, :logger => str, :format => '$sent_http_set_cookie')
|
392
|
+
assert_raise(TypeError) { cl.call(@req) }
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_http_09_request
|
396
|
+
str = StringIO.new
|
397
|
+
app = lambda { |env| [302, [ %w(a) ], []] }
|
398
|
+
cl = Clogger.new(app, :logger => str, :format => '$request')
|
399
|
+
req = @req.dup
|
400
|
+
req.delete 'HTTP_VERSION'
|
401
|
+
cl.call(req)
|
402
|
+
assert_equal "GET /hello?goodbye=true\n", str.string
|
403
|
+
end
|
404
|
+
|
376
405
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Wong
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-02 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|