lib/nice_http.rb
def head(argument)
        begin
          if argument.kind_of?(String) then
            argument={:path => argument}
          end
          path, data, headers_t=manage_request(argument)
          @start_time = Time.now if @start_time.nil?
          if argument.kind_of?(Hash) then
            arg=argument
            if @use_mocks and arg.kind_of?(Hash) and arg.keys.include?(:mock_response) then
              data=""
              if arg[:mock_response].keys.include?(:data) then
                data=arg[:mock_response][:data]
                if data.kind_of?(Hash) #to json
                  begin
                    require 'json'
                    data=data.to_json
                  rescue
                    @logger.fatal "There was a problem converting to json: #{data}"
                  end
                end
              end
              @logger.warn "Pay attention!!! This is a mock response:"
              @start_time_net = Time.now if @start_time_net.nil?
              manage_response(arg[:mock_response], data.to_s)
              return @response
            end
          end
  
          begin
            @start_time_net = Time.now if @start_time_net.nil?
            resp=@http.head(path, headers_t)
            data=resp.body
          rescue Exception => stack
            @logger.warn stack
            @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
            @http.finish()
            @http.start()
            @start_time_net = Time.now if @start_time_net.nil?
            resp, data=@http.head(path)
          end
          manage_response(resp, data)
          return @response
        rescue Exception => stack
          @logger.fatal stack
          return :error
        end
      end
######################################################
# Implementation of the http HEAD method.
# Asks for the response identical to the one that would correspond to a GET request, but without the response body. 
# This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
#  input:
#     1 argument
#       Hash containing at least key :path
#     1 argument
#       String giving the path
#  output:
#    response -> Hash including the symbol keys:
#       :message = plain text response
#       :code = code response (200=ok,500=wrong...)
#     *All keys in response are lowercase
######################################################
Implementation of the http HEAD method.
Asks for the response identical to the one that would correspond to a GET request, but without the response body.
This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
Implementation of the http HEAD method . Asks for the response identical to the one that would correspond to a GET request but without the response body . This is useful for retrieving meta - information written in response headers without having to transport the entire content .
def head(argument)
        begin
          if argument.kind_of?(String) then
            argument={:path => argument}
          end
          path, data, headers_t=manage_request(argument)
          @start_time = Time.now if @start_time.nil?
          if argument.kind_of?(Hash) then
            arg=argument
            if @use_mocks and arg.kind_of?(Hash) and arg.keys.include?(:mock_response) then
              data=""
              if arg[:mock_response].keys.include?(:data) then
                data=arg[:mock_response][:data]
                if data.kind_of?(Hash) 
                  begin
                    require 'json'
                    data=data.to_json
                  rescue
                    @logger.fatal "There was a problem converting to json: #{data}"
                  end
                end
              end
              @logger.warn "Pay attention!!! This is a mock response:"
              @start_time_net = Time.now if @start_time_net.nil?
              manage_response(arg[:mock_response], data.to_s)
              return @response
            end
          end
          begin
            @start_time_net = Time.now if @start_time_net.nil?
            resp=@http.head(path, headers_t)
            data=resp.body
          rescue Exception => stack
            @logger.warn stack
            @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
            @http.finish()
            @http.start()
            @start_time_net = Time.now if @start_time_net.nil?
            resp, data=@http.head(path)
          end
          manage_response(resp, data)
          return @response
        rescue Exception => stack
          @logger.fatal stack
          return :error
        end
      end
def head ( argument ) begin if argument . kind_of? ( String ) then argument = { :path => argument } end path , data , headers_t = manage_request ( argument ) @start_time = Time . now if @start_time . nil? if argument . kind_of? ( Hash ) then arg = argument if @use_mocks and arg . kind_of? ( Hash ) and arg . keys . include? ( :mock_response ) then data = "" if arg [ :mock_response ] . keys . include? ( :data ) then data = arg [ :mock_response ] [ :data ] if data . kind_of? ( Hash ) begin require 'json' data = data . to_json rescue @logger . fatal "There was a problem converting to json: #{data}" end end end @logger . warn "Pay attention!!! This is a mock response:" @start_time_net = Time . now if @start_time_net . nil? manage_response ( arg [ :mock_response ] , data . to_s ) return @response end end begin @start_time_net = Time . now if @start_time_net . nil? resp = @http . head ( path , headers_t ) data = resp . body rescue Exception => stack @logger . warn stack @logger . warn "The connection seems to be closed in the host machine. Trying to reconnect" @http . finish ( ) @http . start ( ) @start_time_net = Time . now if @start_time_net . nil? resp , data = @http . head ( path ) end manage_response ( resp , data ) return @response rescue Exception => stack @logger . fatal stack return :error end end
Implementation of the http HEAD method.
Implementation of the http HEAD method .
#to json
argument