lib/ezid/requests/request.rb in ezid-client-1.8.0 vs lib/ezid/requests/request.rb in ezid-client-1.9.0.rc1

- old
+ new

@@ -1,11 +1,12 @@ -require "delegate" -require "uri" -require "net/http" -require "forwardable" +require 'delegate' +require 'uri' +require 'net/http' +require 'forwardable' +require 'date' -require_relative "../responses/response" +require_relative '../responses/response' module Ezid # # A request to the EZID service. # @@ -29,28 +30,39 @@ yield request if block_given? request.execute end def short_name - name.split("::").last.sub("Request", "") + name.split('::').last.sub('Request', '') end end attr_reader :client def_delegators :client, :connection, :user, :password, :session # @param client [Ezid::Client] the client def initialize(client, *args) @client = client super build_request - set_content_type("text/plain", charset: "UTF-8") + set_content_type('text/plain', charset: 'UTF-8') end # Executes the request and returns the response # @return [Ezid::Response] the response def execute - response_class.new(get_response_for_request) + retries = 0 + begin + response_class.new(get_response_for_request) + rescue Net::HTTPServerException, UnexpectedResponseError => e + if retries < 2 + sleep 15 + retries += 1 + retry + else + raise + end + end end # The request URI # @return [URI] the URI def uri @@ -89,10 +101,11 @@ private def get_response_for_request connection.start do |conn| + self['Accept'] = 'text/plain' add_authentication if authentication_required? add_metadata if has_metadata? conn.request(__getobj__) end end @@ -111,10 +124,10 @@ end # Adds authentication data to the request def add_authentication if session.open? - self["Cookie"] = session.cookie + self['Cookie'] = session.cookie else basic_auth(user, password) end end