Skip to content

Commit c8de951

Browse files
committed
Fixes #1054 - Relax limitation on special chars for --add-header key names
We are too restrictive on the list of characters that are allowed to be used in "header name" for the --add-headers option. The http specification a larger set of characters for header names. Adding the following ones: !#$%&*+^_| Still, even if no issue is to be expected, I would not advice anyone to use any of these chars for a header name.
1 parent 92df370 commit c8de951

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

S3/Config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def read_config_file(self, configfile):
383383
if cp.get('add_headers'):
384384
for option in cp.get('add_headers').split(","):
385385
(key, value) = option.split(':')
386-
self.extra_headers[key.replace('_', '-').strip()] = value.strip()
386+
self.extra_headers[key.strip()] = value.strip()
387387

388388
self._parsed_files.append(configfile)
389389

s3cmd

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,13 +2835,16 @@ def main():
28352835
key, val = unicodise_s(hdr).split(":", 1)
28362836
except ValueError:
28372837
raise ParameterError("Invalid header format: %s" % unicodise_s(hdr))
2838-
key_inval = re.sub("[a-zA-Z0-9-.]", "", key)
2838+
# key char restrictions of the http headers name specification
2839+
key_inval = re.sub(r"[a-zA-Z0-9\-.!#$%&*+^_|]", "", key)
28392840
if key_inval:
28402841
key_inval = key_inval.replace(" ", "<space>")
28412842
key_inval = key_inval.replace("\t", "<tab>")
2842-
raise ParameterError("Invalid character(s) in header name '%s': \"%s\"" % (key, key_inval))
2843-
debug(u"Updating Config.Config extra_headers[%s] -> %s" % (key.replace('_', '-').strip().lower(), val.strip()))
2844-
cfg.extra_headers[key.replace('_', '-').strip().lower()] = val.strip()
2843+
raise ParameterError("Invalid character(s) in header name '%s'"
2844+
": \"%s\"" % (key, key_inval))
2845+
debug(u"Updating Config.Config extra_headers[%s] -> %s" %
2846+
(key.strip().lower(), val.strip()))
2847+
cfg.extra_headers[key.strip().lower()] = val.strip()
28452848

28462849
# Process --remove-header
28472850
if options.remove_headers:

0 commit comments

Comments
 (0)