Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/aliyun/oss/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
require 'resolv'
require 'fiber'

module RestClientRefinements
# Refine rest-client to exclude the 'Content-Length' header when
# 'Transfer-Encoding' is set to 'chuncked' exclusively in Aliyun::OSS:HTTP. This may be a problem for
# some http servers like tengine.
refine RestClient::Payload::Base do
def headers
({'content-length' => size.to_s} if size) || {}
end
end
end


module Aliyun
module OSS

Expand Down Expand Up @@ -31,6 +43,7 @@ module OSS
# stream << "hello world"
# end
class HTTP
using RestClientRefinements

DEFAULT_CONTENT_TYPE = 'application/octet-stream'
DEFAULT_ACCEPT_ENCODING = 'identity'
Expand Down Expand Up @@ -307,16 +320,3 @@ def get_user_agent
end # HTTP
end # OSS
end # Aliyun

# Monkey patch rest-client to exclude the 'Content-Length' header when
# 'Transfer-Encoding' is set to 'chuncked'. This may be a problem for
# some http servers like tengine.
module RestClient
module Payload
class Base
def headers
({'content-length' => size.to_s} if size) || {}
end
end
end
end
10 changes: 5 additions & 5 deletions lib/aliyun/oss/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def list_buckets(opts = {})
update_if_exists(
more, {
:limit => ->(x) { x.to_i },
:truncated => ->(x) { x.to_bool }
:truncated => ->(x) { Util.to_bool(x) }
}
)

Expand Down Expand Up @@ -413,7 +413,7 @@ def get_bucket_referer(name)
doc = parse_xml(r.body)
opts = {
:allow_empty =>
get_node_text(doc.root, 'AllowEmptyReferer', &:to_bool),
get_node_text(doc.root, 'AllowEmptyReferer') { |x| Util.to_bool(x) },
:whitelist => doc.css("RefererList Referer").map(&:text)
}

Expand Down Expand Up @@ -790,7 +790,7 @@ def list_objects(bucket_name, opts = {})
update_if_exists(
more, {
:limit => ->(x) { x.to_i },
:truncated => ->(x) { x.to_bool },
:truncated => ->(x) { Util.to_bool(x) },
:delimiter => ->(x) { decode_key(x, encoding) },
:marker => ->(x) { decode_key(x, encoding) },
:next_marker => ->(x) { decode_key(x, encoding) }
Expand Down Expand Up @@ -1412,7 +1412,7 @@ def list_multipart_uploads(bucket_name, opts = {})
update_if_exists(
more, {
:limit => ->(x) { x.to_i },
:truncated => ->(x) { x.to_bool },
:truncated => ->(x) { Util.to_bool(x) },
:key_marker => ->(x) { decode_key(x, encoding) },
:next_key_marker => ->(x) { decode_key(x, encoding) }
}
Expand Down Expand Up @@ -1476,7 +1476,7 @@ def list_parts(bucket_name, object_name, txn_id, opts = {})
update_if_exists(
more, {
:limit => ->(x) { x.to_i },
:truncated => ->(x) { x.to_bool }
:truncated => ->(x) { Util.to_bool(x) }
}
)

Expand Down
17 changes: 7 additions & 10 deletions lib/aliyun/oss/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,14 @@ def ensure_bucket_name_valid(name)
unless (name =~ %r|^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$|)
fail ClientError, "The bucket name is invalid."
end
end
end

def to_bool(string)
return true if string =~ /^true$/i
false
end

end # self
end # Util
end # OSS
end # Aliyun

# Monkey patch to support #to_bool
class String
def to_bool
return true if self =~ /^true$/i
false
end
end
end # Aliyun