http_spew RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH 0/5] random half-brained updates
@ 2016-10-28 20:14 Eric Wong
  2016-10-28 20:14 ` [PATCH 1/5] declare empty classes with constant assignment Eric Wong
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eric Wong @ 2016-10-28 20:14 UTC (permalink / raw)
  To: http_spew-public

This project is not to be taken seriously, obviously.

5 changes:
      declare empty classes with constant assignment
      test_upload: use object_id to check matches
      use frozen string literals for Ruby 2.1+
      merge into kcar project and mailing list
      dedicated mailing list

 .olddoc.yml                  |  7 +++++--
 GNUmakefile                  |  1 -
 README                       |  8 ++++----
 http_spew.gemspec            |  4 ++--
 lib/http_spew.rb             | 26 +++++++++++++-------------
 lib/http_spew/content_md5.rb |  4 +---
 lib/http_spew/headers.rb     | 23 +++++++----------------
 test/test_upload.rb          |  7 +++++--
 8 files changed, 37 insertions(+), 43 deletions(-)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] declare empty classes with constant assignment
  2016-10-28 20:14 [PATCH 0/5] random half-brained updates Eric Wong
@ 2016-10-28 20:14 ` Eric Wong
  2016-10-28 20:15 ` [PATCH 2/5] test_upload: use object_id to check matches Eric Wong
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2016-10-28 20:14 UTC (permalink / raw)
  To: http_spew-public; +Cc: Eric Wong

Normal constant assignments generate less bytecode than
defineclass instructions.  While we're in the area, use
require_relative to avoid unnecessary path traversals.
---
 lib/http_spew.rb | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/http_spew.rb b/lib/http_spew.rb
index 84359eb..e6bde3b 100644
--- a/lib/http_spew.rb
+++ b/lib/http_spew.rb
@@ -8,20 +8,20 @@ module HTTP_Spew
   autoload :HitNRun, "http_spew/hit_n_run"
   autoload :InputSpray, "http_spew/input_spray"
 
-  class Error < RuntimeError; end
-  class TimeoutError < Error; end
-  class ConnectionReset < Error; end
-  class RequestError < Error; end
-  class UnexpectedResponse < RequestError; end
-  class ChecksumError < HTTP_Spew::Error; end
-  class LengthError < HTTP_Spew::Error; end
-  class NoWritersError < HTTP_Spew::Error; end
-  class EOF < EOFError; end
+  Error = Class.new(RuntimeError)
+  TimeoutError = Class.new(Error)
+  ConnectionReset = Class.new(Error)
+  RequestError = Class.new(Error)
+  UnexpectedResponse = Class.new(RequestError)
+  ChecksumError = Class.new(Error)
+  LengthError = Class.new(Error)
+  NoWritersError = Class.new(Error)
+  EOF = Class.new(EOFError)
 
-  require "http_spew/version"
-  require "http_spew/headers"
-  require "http_spew/request"
-  require "http_spew/class_methods"
+  require_relative "http_spew/version"
+  require_relative "http_spew/headers"
+  require_relative "http_spew/request"
+  require_relative "http_spew/class_methods"
 
   extend HTTP_Spew::ClassMethods
 end
-- 
EW


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] test_upload: use object_id to check matches
  2016-10-28 20:14 [PATCH 0/5] random half-brained updates Eric Wong
  2016-10-28 20:14 ` [PATCH 1/5] declare empty classes with constant assignment Eric Wong
@ 2016-10-28 20:15 ` Eric Wong
  2016-10-28 20:15 ` [PATCH 3/5] use frozen string literals for Ruby 2.1+ Eric Wong
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2016-10-28 20:15 UTC (permalink / raw)
  To: http_spew-public; +Cc: Eric Wong

We do not define <=> for comparison, so object_id
is safer and more future-proof.
---
 test/test_upload.rb | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/test/test_upload.rb b/test/test_upload.rb
index 33c494a..df54765 100644
--- a/test/test_upload.rb
+++ b/test/test_upload.rb
@@ -117,13 +117,16 @@ class TestUpload < Test::Unit::TestCase
     req << HTTP_Spew::Request.new(@env, StringIO.new(str), @sockaddr)
     req << HTTP_Spew::Request.new(@env, StringIO.new(str), @sockaddr)
     req << HTTP_Spew::Request.new(@env, StringIO.new(str), @sockaddr)
-    before = req.dup
+    before = req.map(&:object_id)
     rv = HTTP_Spew.wait_nonblock!(3, req)
     while rv.nil? do
       rv = HTTP_Spew.wait_nonblock!(3, req)
     end
     assert_nil rv.uniq!
     assert rv.size > 0
-    rv.each { |r| assert before.include?(r) }
+    rv.map!(&:object_id)
+    rv.each do |r|
+      assert before.include?(r), "rv=#{rv.inspect} before=#{before.inspect}"
+    end
   end
 end if HAVE_UNICORN
-- 
EW


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] use frozen string literals for Ruby 2.1+
  2016-10-28 20:14 [PATCH 0/5] random half-brained updates Eric Wong
  2016-10-28 20:14 ` [PATCH 1/5] declare empty classes with constant assignment Eric Wong
  2016-10-28 20:15 ` [PATCH 2/5] test_upload: use object_id to check matches Eric Wong
@ 2016-10-28 20:15 ` Eric Wong
  2016-10-28 20:15 ` [PATCH 4/5] merge into kcar project and mailing list Eric Wong
  2016-10-28 20:15 ` [PATCH 5/5] dedicated " Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2016-10-28 20:15 UTC (permalink / raw)
  To: http_spew-public; +Cc: Eric Wong

Constant lookups (even with caching) have extra size and speed
costs compared to just using frozen string literals.  This slows
down performance on older Rubies (even if they become
unsupported upstream), but newest C Ruby takes priority
(currently 2.3).
---
 lib/http_spew/content_md5.rb |  4 +---
 lib/http_spew/headers.rb     | 23 +++++++----------------
 2 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/lib/http_spew/content_md5.rb b/lib/http_spew/content_md5.rb
index 1c5be88..a999111 100644
--- a/lib/http_spew/content_md5.rb
+++ b/lib/http_spew/content_md5.rb
@@ -7,8 +7,6 @@ class HTTP_Spew::ContentMD5
   attr_reader :content_md5
   attr_reader :bytes_digested
 
-  CRLF = "\r\n" # :nodoc:
-
   def initialize(env, input = env["rack.input"])
     if trailer = env["HTTP_TRAILER"]
       unless trailer.split(/\s*,\s*/).grep(/\AContent-MD5\z/i)[0]
@@ -41,7 +39,7 @@ class HTTP_Spew::ContentMD5
             @bytes_digested += n
             wr.write("#{n.to_s(16)}\r\n")
             digest.update(buf)
-            wr.write(buf << CRLF)
+            wr.write(buf << "\r\n".freeze)
           end while input.read(0x4000, buf)
         end
         if expect_len && expect_len.to_i != @bytes_digested
diff --git a/lib/http_spew/headers.rb b/lib/http_spew/headers.rb
index da34c03..6f6f4d0 100644
--- a/lib/http_spew/headers.rb
+++ b/lib/http_spew/headers.rb
@@ -1,18 +1,10 @@
 # -*- encoding: binary -*-
 module HTTP_Spew::Headers
-  # :stopdoc:
-  REQUEST_METHOD = "REQUEST_METHOD"
-  REQUEST_URI = "REQUEST_URI"
-  CRLF = "\r\n"
-  QUERY_STRING = "QUERY_STRING"
-  PATH_INFO = "PATH_INFO"
-  CONTENT_TYPE = "CONTENT_TYPE" # specified by Rack to be !/^HTTP_/
-  # :startdoc:
 
   # regenerates the request_uri from a Rack +env+
   def request_uri(env)
-    qs = env[QUERY_STRING]
-    qs.size == 0 ? env[PATH_INFO] : "#{env[PATH_INFO]}?#{qs}"
+    qs = env['QUERY_STRING']
+    qs.size == 0 ? env['PATH_INFO'] : "#{env['PATH_INFO']}?#{qs}"
   end
   module_function :request_uri
 
@@ -27,26 +19,25 @@ module HTTP_Spew::Headers
   #
   #   buf, input = env_to_headers(env, input)
   def env_to_headers(env, input)
-    req = "#{env[REQUEST_METHOD]} " \
-          "#{env[REQUEST_URI] || request_uri(env)} HTTP/1.1\r\n" \
+    req = "#{env['REQUEST_METHOD']} " \
+          "#{env['REQUEST_URI'] || request_uri(env)} HTTP/1.1\r\n" \
           "Connection: close\r\n"
-    uscore, dash = "_", "-"
     env.each do |key,value|
       %r{\AHTTP_(\w+)\z} =~ key or next
       key = $1
       %r{\A(?:VERSION|EXPECT|TRANSFER_ENCODING|CONNECTION|KEEP_ALIVE)\z}x =~
         key and next
 
-      key.tr!(uscore, dash)
+      key.tr!('_'.freeze, '-'.freeze)
       req << "#{key}: #{value}\r\n"
     end
     if input
       req << (input.respond_to?(:size) ?
              "Content-Length: #{input.size}\r\n" :
              "Transfer-Encoding: chunked\r\n")
-      ct = env[CONTENT_TYPE] and req << "Content-Type: #{ct}\r\n"
+      ct = env['CONTENT_TYPE'] and req << "Content-Type: #{ct}\r\n"
     end
-    req << CRLF
+    req << "\r\n".freeze
     String === input ? (req << input) : [ req, input ]
   end
   module_function :env_to_headers
-- 
EW


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] merge into kcar project and mailing list
  2016-10-28 20:14 [PATCH 0/5] random half-brained updates Eric Wong
                   ` (2 preceding siblings ...)
  2016-10-28 20:15 ` [PATCH 3/5] use frozen string literals for Ruby 2.1+ Eric Wong
@ 2016-10-28 20:15 ` Eric Wong
  2016-10-28 20:15 ` [PATCH 5/5] dedicated " Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2016-10-28 20:15 UTC (permalink / raw)
  To: http_spew-public; +Cc: Eric Wong

librelist is down, and segregating this from kcar probably
isn't worth it for email support.
---
 .olddoc.yml       | 6 ++++--
 GNUmakefile       | 1 -
 README            | 8 ++++----
 http_spew.gemspec | 4 ++--
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/.olddoc.yml b/.olddoc.yml
index b230ebb..51f1b61 100644
--- a/.olddoc.yml
+++ b/.olddoc.yml
@@ -1,4 +1,6 @@
 ---
-cgit_url: http://bogomips.org/http_spew.git
+cgit_url: https://bogomips.org/http_spew.git
 git_url: git://bogomips.org/http_spew.git
-rdoc_url: http://bogomips.org/http_spew/
+rdoc_url: https://bogomips.org/http_spew/
+private_email: kcar@bogomips.org
+public_email: kcar-public@bogomips.org
diff --git a/GNUmakefile b/GNUmakefile
index 229c3d1..0604222 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,6 +1,5 @@
 all::
 RSYNC_DEST := bogomips.org:/srv/bogomips/http_spew
-rfproject := rainbows
 rfpackage := http_spew
 
 RUBY_VERSION_FILE = lib/http_spew/version.rb
diff --git a/README b/README
index 35a4c24..8facb56 100644
--- a/README
+++ b/README
@@ -39,7 +39,7 @@ You can get the latest source via git from the following locations:
 You may browse the code from the web and download the latest snapshot
 tarballs here:
 
-* http://bogomips.org/http_spew.git (cgit)
+* https://bogomips.org/http_spew.git
 * http://repo.or.cz/w/http_spew.git (gitweb)
 
 Inline patches (from "git format-patch") to the mailing list are
@@ -54,8 +54,8 @@ don't email the git mailing list or maintainer with http_spew patches.
 == Contact
 
 All feedback (bug reports, user/development discussion, patches, pull
-requests) go to the mailing list: mailto:http.spew@librelist.org
+requests) go to the mailing list: mailto:kcar-public@bogomips.org
 
-Mailing list archives in mbox format may be downloaded here:
+Mailing list archives may be viewed and downloaded here:
 
-http://bogomips.org/http_spew/archives/
+https://bogomips.org/kcar-public/
diff --git a/http_spew.gemspec b/http_spew.gemspec
index 258641a..4aafc26 100644
--- a/http_spew.gemspec
+++ b/http_spew.gemspec
@@ -7,9 +7,9 @@ name, summary, title = readme_metadata
 Gem::Specification.new do |s|
   s.name = %q{http_spew}
   s.version = ENV["VERSION"].dup
-  s.authors = ["HTTP Spew hackers"]
+  s.authors = ["kcar hackers"]
   s.description = readme_description
-  s.email = %q{http.spew@librelist.org}
+  s.email = %q{kcar@bogomips.org}
   s.extra_rdoc_files = extra_rdoc_files(manifest)
   s.files = manifest
   s.homepage = Olddoc.config['rdoc_url']
-- 
EW


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] dedicated mailing list
  2016-10-28 20:14 [PATCH 0/5] random half-brained updates Eric Wong
                   ` (3 preceding siblings ...)
  2016-10-28 20:15 ` [PATCH 4/5] merge into kcar project and mailing list Eric Wong
@ 2016-10-28 20:15 ` Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2016-10-28 20:15 UTC (permalink / raw)
  To: http_spew-public; +Cc: Eric Wong

On second thought, it looks like I already created a mailing
list for this project last year.  Oops :x
---
 .olddoc.yml | 3 ++-
 README      | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/.olddoc.yml b/.olddoc.yml
index 51f1b61..532ab7e 100644
--- a/.olddoc.yml
+++ b/.olddoc.yml
@@ -2,5 +2,6 @@
 cgit_url: https://bogomips.org/http_spew.git
 git_url: git://bogomips.org/http_spew.git
 rdoc_url: https://bogomips.org/http_spew/
+ml_url: https://bogomips.org/http_spew-public/
 private_email: kcar@bogomips.org
-public_email: kcar-public@bogomips.org
+public_email: http_spew-public@bogomips.org
diff --git a/README b/README
index 8facb56..c8c2828 100644
--- a/README
+++ b/README
@@ -54,8 +54,8 @@ don't email the git mailing list or maintainer with http_spew patches.
 == Contact
 
 All feedback (bug reports, user/development discussion, patches, pull
-requests) go to the mailing list: mailto:kcar-public@bogomips.org
+requests) go to the mailing list: mailto:http_spew-public@bogomips.org
 
 Mailing list archives may be viewed and downloaded here:
 
-https://bogomips.org/kcar-public/
+https://bogomips.org/http_spew-public/
-- 
EW


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-10-28 20:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-28 20:14 [PATCH 0/5] random half-brained updates Eric Wong
2016-10-28 20:14 ` [PATCH 1/5] declare empty classes with constant assignment Eric Wong
2016-10-28 20:15 ` [PATCH 2/5] test_upload: use object_id to check matches Eric Wong
2016-10-28 20:15 ` [PATCH 3/5] use frozen string literals for Ruby 2.1+ Eric Wong
2016-10-28 20:15 ` [PATCH 4/5] merge into kcar project and mailing list Eric Wong
2016-10-28 20:15 ` [PATCH 5/5] dedicated " Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/http_spew.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox