Merge "Allow user to specify headers at the command line."
This commit is contained in:
commit
42fa4568f1
16
bin/swift
16
bin/swift
@ -701,6 +701,10 @@ def st_post(parser, args, print_queue, error_queue):
|
|||||||
parser.add_option('-m', '--meta', action='append', dest='meta', default=[],
|
parser.add_option('-m', '--meta', action='append', dest='meta', default=[],
|
||||||
help='Sets a meta data item with the syntax name:value. This option '
|
help='Sets a meta data item with the syntax name:value. This option '
|
||||||
'may be repeated. Example: -m Color:Blue -m Size:Large')
|
'may be repeated. Example: -m Color:Blue -m Size:Large')
|
||||||
|
parser.add_option('-H', '--header', action='append', dest='header',
|
||||||
|
default=[], help='Set request headers with the syntax header:value. '
|
||||||
|
' This option may be repeated. Example -H content-type:text/plain '
|
||||||
|
'-H "Content-Length: 4000"')
|
||||||
(options, args) = parse_args(parser, args)
|
(options, args) = parse_args(parser, args)
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
if (options.read_acl or options.write_acl or options.sync_to or
|
if (options.read_acl or options.write_acl or options.sync_to or
|
||||||
@ -737,6 +741,8 @@ def st_post(parser, args, print_queue, error_queue):
|
|||||||
conn.put_container(args[0], headers=headers)
|
conn.put_container(args[0], headers=headers)
|
||||||
elif len(args) == 2:
|
elif len(args) == 2:
|
||||||
headers = split_headers(options.meta, 'X-Object-Meta-', error_queue)
|
headers = split_headers(options.meta, 'X-Object-Meta-', error_queue)
|
||||||
|
# add header options to the headers object for the request.
|
||||||
|
headers.update(split_headers(options.header, '', error_queue))
|
||||||
try:
|
try:
|
||||||
conn.post_object(args[0], args[1], headers=headers)
|
conn.post_object(args[0], args[1], headers=headers)
|
||||||
except ClientException, err:
|
except ClientException, err:
|
||||||
@ -783,6 +789,11 @@ def st_upload(parser, args, print_queue, error_queue):
|
|||||||
parser.add_option('', '--segment-threads', type=int,
|
parser.add_option('', '--segment-threads', type=int,
|
||||||
default=10, help='Number of threads to use for '
|
default=10, help='Number of threads to use for '
|
||||||
'uploading object segments')
|
'uploading object segments')
|
||||||
|
parser.add_option('-H', '--header', action='append', dest='header',
|
||||||
|
default=[], help='Set request headers with the syntax header:value. '
|
||||||
|
' This option may be repeated. Example -H content-type:text/plain '
|
||||||
|
'-H "Content-Length: 4000"')
|
||||||
|
|
||||||
(options, args) = parse_args(parser, args)
|
(options, args) = parse_args(parser, args)
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
@ -857,6 +868,9 @@ def st_upload(parser, args, print_queue, error_queue):
|
|||||||
except ClientException, err:
|
except ClientException, err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
|
# Merge the command line header options to the put_headers
|
||||||
|
put_headers.update(split_headers(options.header, '',
|
||||||
|
error_queue))
|
||||||
# Don't do segment job if object is not big enough
|
# Don't do segment job if object is not big enough
|
||||||
if options.segment_size and \
|
if options.segment_size and \
|
||||||
getsize(path) > int(options.segment_size):
|
getsize(path) > int(options.segment_size):
|
||||||
@ -1011,7 +1025,7 @@ def split_headers(options, prefix='', error_queue=None):
|
|||||||
for item in options:
|
for item in options:
|
||||||
split_item = item.split(':', 1)
|
split_item = item.split(':', 1)
|
||||||
if len(split_item) == 2:
|
if len(split_item) == 2:
|
||||||
headers[prefix + split_item[0]] = split_item[1]
|
headers[(prefix + split_item[0]).title()] = split_item[1]
|
||||||
else:
|
else:
|
||||||
error_string = "Metadata parameter %s must contain a ':'.\n%s" \
|
error_string = "Metadata parameter %s must contain a ':'.\n%s" \
|
||||||
% (item, st_post_help)
|
% (item, st_post_help)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user