Sha256: 89c8364b0021f34a623ef211d83231f6743ac28adfd8abe63ccc45f0dcae9799

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

module NginxTail
  module HttpVersion
    
    def self.included(base) # :nodoc:
      base.class_eval do

        @@http_version_expression = Regexp.compile('HTTP/([0-9])\.([0-9])')

        def self.minor_version(http_version)
          return $1 if http_version =~ @@http_version_expression
        end

        def self.major_version(http_version)
          return $1 if http_version =~ @@http_version_expression
        end

        def self.to_http_version_s(http_version, which = :full)
          # http_version will be nil if $request == "-" (ie. "dodgy" HTTP requests)
          http_version.nil? ? "" : case which
            when :full then http_version
            when :major then self.major_version(http_version)
            when :minor then self.minor_version(http_version)
          end
        end

        # this ensures the below module methods actually make sense...
        raise "Class #{base.name} should implement instance method 'http_version'" unless base.instance_methods.map(&:to_s).include? 'http_version'
        
      end
    end

    def to_http_version_s(which = :full)
      self.class.to_http_version_s(self.http_version, which)
    end
    
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ntail-1.3.1 lib/ntail/http_version.rb
ntail-1.3.0 lib/ntail/http_version.rb
ntail-1.2.0 lib/ntail/http_version.rb
ntail-1.1.4 lib/ntail/http_version.rb
ntail-1.1.3 lib/ntail/http_version.rb
ntail-1.1.2 lib/ntail/http_version.rb
ntail-1.1.1 lib/ntail/http_version.rb
ntail-1.1.0 lib/ntail/http_version.rb
ntail-1.0.2 lib/ntail/http_version.rb
ntail-1.0.0 lib/ntail/http_version.rb
ntail-0.2.0 lib/ntail/http_version.rb
ntail-0.1.0 lib/ntail/http_version.rb
ntail-0.0.12 lib/ntail/http_version.rb