about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-09-01 19:04:52 -0700
committerEric Wong <normalperson@yhbt.net>2009-09-01 19:04:52 -0700
commit144e9909ea0f875b3dd58c6c850e25ed9f70c3cb (patch)
tree522e0bd781829e42f2aaf0390f15e75f8a05711d
parent98d72e530ae0e7899aee88bcb0a607e046b32965 (diff)
Back in HTTP/0.9 days (before it was called HTTP/0.9),
"GET /uri/goes/here\r\n" was a valid HTTP request.

See rfc 1945, section 4.1 for details on this ancient
"Simple-Request" scheme used by HTTP/0.9 clients.
-rw-r--r--ext/clogger_ext/clogger.c6
-rw-r--r--lib/clogger/pure.rb4
-rw-r--r--test/test_clogger.rb10
3 files changed, 15 insertions, 5 deletions
diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c
index 19386e5..2dc1ddc 100644
--- a/ext/clogger_ext/clogger.c
+++ b/ext/clogger_ext/clogger.c
@@ -461,12 +461,12 @@ static void append_request(struct clogger *c)
 
         append_request_uri(c);
 
-        rb_str_buf_append(c->log_buf, g_space);
-
         /* HTTP_VERSION can be injected by malicious clients */
         tmp = rb_hash_aref(c->env, g_HTTP_VERSION);
-        if (!NIL_P(tmp))
+        if (!NIL_P(tmp)) {
+                rb_str_buf_append(c->log_buf, g_space);
                 rb_str_buf_append(c->log_buf, byte_xs(tmp));
+        }
 }
 
 static void append_request_length(struct clogger *c)
diff --git a/lib/clogger/pure.rb b/lib/clogger/pure.rb
index ebbb1d6..d8752b3 100644
--- a/lib/clogger/pure.rb
+++ b/lib/clogger/pure.rb
@@ -83,11 +83,11 @@ private
       status = status.to_i
       status >= 100 && status <= 999 ? ('%03d' % status) : '-'
     when :request
+      version = env['HTTP_VERSION'] and version = " #{byte_xs(version)}"
       qs = env['QUERY_STRING']
       qs.empty? or qs = "?#{byte_xs(qs)}"
       "#{env['REQUEST_METHOD']} " \
-        "#{request_uri(env)} " \
-        "#{byte_xs(env['HTTP_VERSION'])}"
+        "#{request_uri(env)}#{version}"
     when :request_uri
       request_uri(env)
     when :request_length
diff --git a/test/test_clogger.rb b/test/test_clogger.rb
index 5e85e15..9fd6d05 100644
--- a/test/test_clogger.rb
+++ b/test/test_clogger.rb
@@ -392,4 +392,14 @@ class TestClogger < Test::Unit::TestCase
     assert_raise(TypeError) { cl.call(@req) }
   end
 
+  def test_http_09_request
+    str = StringIO.new
+    app = lambda { |env| [302, [ %w(a) ], []] }
+    cl = Clogger.new(app, :logger => str, :format => '$request')
+    req = @req.dup
+    req.delete 'HTTP_VERSION'
+    cl.call(req)
+    assert_equal "GET /hello?goodbye=true\n", str.string
+  end
+
 end