Skip to content

Conversation

@welteki
Copy link
Member

@welteki welteki commented Jun 18, 2025

Description

Change the header flag to accept key value pairs separated by a colon. e.g. "key: value".

The previous format is marked as deprecated but still supported. A warning is printed when it is used.

Fix an issues where the 'Content-Type' header was being overridden by the default value of the --content-type flag when the flag is not set explicitly.

e.g. when running faas-cli invoke -H "Content-Type=application/tar" the content type would be overridden with the default value text/plain.

Motivation and Context

  • I have raised an issue to propose this change (required)

Align the format more closely with curl to make the invoke command as intuitive and familiar as possible.

How Has This Been Tested?

Changes are covered by unit test.

Verify headers can be set using the new format:

faas-cli invoke -H "foo: bar" <<< hello

Verify the deprecated format is still accepted and prints a warning:

faas-cli invoke -H "foo=bar" <<< hello
Warning: Using deprecated 'key=value' format for headers. Please use 'Key: Value' format instead.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Change the header flag to accept key value pairs separated by a colon.
e.g. "key: value".

The previous format is marked as deprecated but still supported. A
warning is printed when it is used.

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
if value == "" {
return httpHeader, fmt.Errorf("the --header or -H flag must take the form of key=value (empty value given)")
// Fallback to deprecated key=value format
parts = strings.SplitN(header, "=", 2)
Copy link
Contributor

@rgee0 rgee0 Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we pre-process header to replace = with : when a colon isn't present? Then we'd only need a header processing once.

We could also show the warning from the pre-processing step if a replace took place, and wrap a test around the pre-processor.

Alternatively, the header processing could be extracted as a function:

func processHeader(header, separator)(k, v){
...
}

@alexellis alexellis merged commit ee4db09 into openfaas:master Jul 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants