diff options
author | Matthieu Huin <mhu@enovance.com> | 2013-08-13 17:58:55 +0200 |
---|---|---|
committer | Matthieu Huin <mhu@enovance.com> | 2013-11-04 17:41:55 +0100 |
commit | 3cabda8c48dfe559e3f707c2750036247988d9d3 (patch) | |
tree | a49032319e1ded9cb6a21553a809cb1e4a9a777f /bin | |
parent | ff6ba367faa71a7dd22e210382c8afc41d79d779 (diff) | |
download | python-swiftclient-3cabda8c48dfe559e3f707c2750036247988d9d3.tar.gz |
Allow custom headers when using swift download (CLI)
This fixes bug #1051046
A repeatable option, --header or -H, is added so a user can specify
custom headers such as Range or If-Modified-Since when downloading
an object with the swift CLI.
Change-Id: I1f7dcf64cf625f2e5a4488c210894cfe6e0d5974
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/swift | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -265,6 +265,11 @@ Optional arguments: Number of threads to use for deleting containers --no-download Perform download(s), but don't actually write anything to disk + --header <header_name:header_value> + Adds a customized request header to the query, like + "Range" or "If-Match". This argument is repeatable. + Example --header "content-type:text/plain" + '''.strip("\n") @@ -293,6 +298,13 @@ def st_download(parser, args, thread_manager): '', '--no-download', action='store_true', default=False, help="Perform download(s), but don't actually write anything to disk") + parser.add_option( + '-H', '--header', action='append', dest='header', + default=[], + help='Specify a request header, as --header NAME:VALUE. ' + 'Adds a customized request header to the query, like "Range" or ' + '"If-Match". This argument is repeatable. Example' + ' --header "content-type:text/plain"') (options, args) = parse_args(parser, args) args = args[1:] if options.out_file == '-': @@ -303,6 +315,7 @@ def st_download(parser, args, thread_manager): thread_manager.error('Usage: %s download %s\n%s', basename(argv[0]), st_download_options, st_download_help) return + req_headers = split_headers(options.header, '', thread_manager) def _download_object(queue_arg, conn): if len(queue_arg) == 2: @@ -315,7 +328,8 @@ def st_download(parser, args, thread_manager): try: start_time = time() headers, body = \ - conn.get_object(container, obj, resp_chunk_size=65536) + conn.get_object(container, obj, resp_chunk_size=65536, + headers=req_headers) header_receipt = time() content_type = headers.get('content-type') if 'content-length' in headers: |