Move timeouts from request to clientoptions, update migration/changelog

This commit is contained in:
Steve Bazyl 2017-04-03 11:10:54 -07:00
parent 97ff7f4d9a
commit 4682267161
7 changed files with 74 additions and 30 deletions

View File

@ -1,9 +1,10 @@
# 0.11.0
* *Breaking Change* - Fix handling of large numbers during code generation. Previously the
* *Breaking change* - Fix handling of large numbers during code generation. Previously the
uint64/int64 formats were passed through as strings. They are now coerced to/from Fixnum/Bignum types
* *Breaking Change* - No longer normalize unicode strings in URI templates. Mostly affects
* *Breaking change* - No longer normalize unicode strings in URI templates. Mostly affects
Cloud Storage, but other APIs with unicode strings in paths may be affected. Old behavior
can be restored using the `normalize_unicode` request option.
* *Breaking change* -- Moved timeout options from `RequestOptions` to `ClientOptions`
* Remove Hurley as dependency. May cause minor breaking changes if directly accessing the underlying
client connection.
* Drop compatibility with Rails 3.x since that is no longer supported by the Rails community.
@ -17,7 +18,7 @@
# 0.10.3
* Regenerate APIs
* Enable additional API:
* `acceleratedmobilepageurl:v1``
* `acceleratedmobilepageurl:v1`
* `appengine:v1`
* `clouderrorreporting:v1beta1`
* `cloudfunctions:v1`

View File

@ -1,3 +1,36 @@
# Migrating from version`0.10` to `0.11`
## Unicode normalization
The client no longer normalizes unicode strings in path parameters. This may affect
some applications using multibyte strings that were previously normalized.:
To restore the previous behavior, set the following option prior to creating a service.
```ruby
ClientOptions.default.normalize_unicode = true
```
## Type change for large numbers
Previously, types declared as 64 bit numbers were mapped to strings. These are now mapped to
`Fixednum`/`Bignum`.
## Timeouts
Timeout options have been moved from `RequestOptions` to `ClientOptions`.
Old | New
----------------------------------|-----------------
`RequestOptions.open_timeout_sec` | `ClentOptions.open_timeout_sec`
`RequestOptions.timeout_sec` | `ClentOptions.read_timeout_sec`
`RequestOptions.timeout_sec` | `ClentOptions.send_timeout_sec`
## Batch requests across services no longer supported
It is no longer possible to combine multiple services (e.g. Gail & Drive)
in a batch request. If batching requests that span services, group
requests for each service in their own batch request.
# Migrating from version `0.9.x` to `0.10`
Only one minor breaking change was introduced in the `to_json` method due to a version bump for the `representable` gem from `2.3` to `3.0`. If you used the `skip_undefined` in `to_json`, you should replace that with `user_options: { skip_undefined: true }`.

0
dl.rb Normal file
View File

View File

@ -380,23 +380,24 @@ module Google
client = ::HTTPClient.new
client.transparent_gzip_decompression = true
client.proxy = client_options.proxy_url if client_options.proxy_url
if request_options.timeout_sec
client.connect_timeout = request_options.timeout_sec
client.receive_timeout = request_options.timeout_sec
client.send_timeout = request_options.timeout_sec
if client_options.open_timeout_sec
client.connect_timeout = client_options.open_timeout_sec
end
if request_options.open_timeout_sec
client.connect_timeout = request_options.open_timeout_sec
client.send_timeout = request_options.open_timeout_sec
if client_options.read_timeout_sec
client.receive_timeout = client_options.read_timeout_sec
end
if client_options.send_timeout_sec
client.send_timeout = client_options.send_timeout_sec
end
client.follow_redirect_count = 5
client.default_header = { 'User-Agent' => user_agent }
client.debug_dev = logger if logger.level == Logger::DEBUG
client.debug_dev = logger if client_options.log_http_requests
client
end

View File

@ -87,13 +87,14 @@ module Google
@download_io.rewind
check_if_rewind_needed = false
end
logger.debug { sprintf('Writing chunk (%d bytes)', chunk.length) }
@offset += chunk.length
# logger.debug { sprintf('Writing chunk (%d bytes, %d total)', chunk.length, bytes_read) }
@download_io.write(chunk)
@download_io.flush
@offset += chunk.length
end
end
@download_io.flush
if @close_io_on_finish
result = nil
else
@ -102,6 +103,7 @@ module Google
check_status(http_res.status.to_i, http_res.header, http_res.body)
success(result, &block)
rescue => e
@download_io.flush
error(e, rethrow: true, &block)
end
end

View File

@ -29,6 +29,7 @@ module Google
UPLOAD_PROTOCOL_HEADER = 'X-Goog-Upload-Protocol'
UPLOAD_CONTENT_TYPE_HEADER = 'X-Goog-Upload-Header-Content-Type'
UPLOAD_CONTENT_LENGTH = 'X-Goog-Upload-Header-Content-Length'
CONTENT_TYPE_HEADER = 'Content-Type'
# File name or IO containing the content to upload
# @return [String, File, #read]
@ -51,16 +52,20 @@ module Google
if streamable?(upload_source)
self.upload_io = upload_source
@close_io_on_finish = false
elsif upload_source.is_a?(String)
elsif self.upload_source.is_a?(String)
self.upload_io = File.new(upload_source, 'r')
if upload_content_type.nil?
if self.upload_content_type.nil?
type = MIME::Types.of(upload_source)
upload_content_type = type.first.content_type unless type.nil? || type.empty?
self.upload_content_type = type.first.content_type unless type.nil? || type.empty?
end
@close_io_on_finish = true
else
fail Google::Apis::ClientError, 'Invalid upload source'
end
if self.upload_content_type.nil? || self.upload_content_type.empty?
self.upload_content_type = 'application/octet-stream'
end
puts self.upload_content_type.inspect
end
# Close IO stream when command done. Only closes the stream if it was opened by the command.
@ -198,7 +203,7 @@ module Google
apply_request_options(request_header)
request_header[UPLOAD_COMMAND_HEADER] = QUERY_COMMAND
client.post(@upload_url, header: request_header, follow_redirect: true)
client.post(@upload_url, body: '', header: request_header, follow_redirect: true)
end
@ -219,6 +224,7 @@ module Google
request_header[UPLOAD_COMMAND_HEADER] = QUERY_COMMAND
request_header[UPLOAD_COMMAND_HEADER] = UPLOAD_COMMAND
request_header[UPLOAD_OFFSET_HEADER] = @offset.to_s
request_header[CONTENT_TYPE_HEADER] = upload_content_type
client.post(@upload_url, body: content, header: request_header, follow_redirect: true)
end

View File

@ -15,18 +15,19 @@
module Google
module Apis
# General options for API requests
ClientOptions = Struct.new(
ClientOptions = Struct.new(
:application_name,
:application_version,
:proxy_url,
:use_net_http)
:open_timeout_sec,
:read_timeout_sec,
:send_timeout_sec,
:log_http_requests)
RequestOptions = Struct.new(
:authorization,
:retries,
:header,
:timeout_sec,
:open_timeout_sec,
:normalize_unicode,
:skip_serialization,
:skip_deserialization)
@ -39,7 +40,12 @@ module Google
# @return [String] Version of the application, for identification in the User-Agent header
# @!attribute [rw] proxy_url
# @return [String] URL of a proxy server
# @!attribute [rw] log_http_requests
# @return [Boolean] True if raw HTTP requests should be logged
# @!attribute [rw] open_timeout_sec
# @return [Fixnum] How long, in seconds, before failed connections time out
# @!attribute [rw] read_timeout_sec
# @return [Fixnum] How long, in seconds, before requests time out
# Get the default options
# @return [Google::Apis::ClientOptions]
def self.default
@ -53,10 +59,6 @@ module Google
# @return [Signet::OAuth2::Client, #apply(Hash)] OAuth2 credentials
# @!attribute [rw] retries
# @return [Fixnum] Number of times to retry requests on server error
# @!attribute [rw] timeout_sec
# @return [Fixnum] How long, in seconds, before requests time out
# @!attribute [rw] open_timeout_sec
# @return [Fixnum] How long, in seconds, before failed connections time out
# @!attribute [rw] header
# @return [Hash<String,String] Additional HTTP headers to include in requests
# @!attribute [rw] normalize_unicode
@ -84,11 +86,10 @@ module Google
end
end
ClientOptions.default.use_net_http = false
ClientOptions.default.log_http_requests = false
ClientOptions.default.application_name = 'unknown'
ClientOptions.default.application_version = '0.0.0'
RequestOptions.default.retries = 0
RequestOptions.default.open_timeout_sec = 20
RequestOptions.default.normalize_unicode = false
RequestOptions.default.skip_serialization = false
RequestOptions.default.skip_deserialization = false