Sha256: fd4b65c1ebbbc936641118e8a70994d02f3a7c4cad53363243b2f0c63de8294d

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# encoding: utf-8
require 'ting_yun/http/abstract_request'

    module TingYun
      module Http


    class CurbRequest
      CURB = 'Curb'.freeze
      LHOST = 'host'.freeze
      UHOST = 'Host'.freeze

      def initialize( curlobj )
        @curlobj = curlobj
      end

      def type
        CURB
      end

      def from
        "curb%2Fhttp"
      end

      def host_from_header
        self[LHOST] || self[UHOST]
      end

      def host
        host_from_header || self.uri.host
      end

      def method
        @curlobj._ty_http_verb
      end

      def []( key )
        @curlobj.headers[ key ]
      end

      def []=( key, value )
        @curlobj.headers[ key ] = value
      end

      def uri
        @uri ||= TingYun::Agent::HTTPClients::URIUtil.parse_and_normalize_url(@curlobj.url)
      end
    end


    class CurbResponse < AbstractRequest
      def initialize(curlobj)
        @headers = {}
        @curlobj = curlobj
      end

      def [](key)
        @headers[ key.downcase ]
      end

      def to_hash
        @headers.dup
      end

      def append_header_data( data )
        key, value = data.split( /:\s*/, 2 )
        @headers[ key.downcase ] = value
        @curlobj._ty_header_str ||= ''
        @curlobj._ty_header_str << data
      end

    end


  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tingyun_rpm-1.6.1 lib/ting_yun/http/curb_wrappers.rb
tingyun_rpm-1.5.0 lib/ting_yun/http/curb_wrappers.rb