Skip to content

feat: Add an option to specify headers#1096

Open
kayoch1n wants to merge 3 commits intohibiken:masterfrom
kayoch1n:feat/header-option
Open

feat: Add an option to specify headers#1096
kayoch1n wants to merge 3 commits intohibiken:masterfrom
kayoch1n:feat/header-option

Conversation

@kayoch1n
Copy link
Copy Markdown

This PR adds Header() option to the Client API, allowing users to associate key-value headers to tasks.

  • Add Header(key, value string) Option function to client.go.
  • Add parsing support in inspector.go.
  • Add tests.

The underlying value of Header is [2]string. Inspector parses Header option by unmarshaling the JSON array argument back to [2]string

usage:

client.Enqueue(NewTask("send_email", data), Header("channel", "email"))

Follow-up to #1070 which added headers support to Task messages

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 62.96296% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.33%. Comparing base (4f00f52) to head (5216f1c).
⚠️ Report is 36 commits behind head on master.

Files with missing lines Patch % Lines
client.go 61.90% 8 Missing ⚠️
inspector.go 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1096      +/-   ##
==========================================
- Coverage   67.13%   63.33%   -3.81%     
==========================================
  Files          29       29              
  Lines        4300     5010     +710     
==========================================
+ Hits         2887     3173     +286     
- Misses       1135     1558     +423     
- Partials      278      279       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

func (h headerOption) Type() OptionType { return HeaderOpt }
func (h headerOption) Value() interface{} { return [2]string{h[0], h[1]} }

func Headers(headers map[string]string) (ret []Option) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we rename this to something else like HeadersMap so that it is not confusing. #1070 also introduced a Headers method on Task.

@kamikazechaser
Copy link
Copy Markdown
Collaborator

Maybe another thing to document is when to use this vs what was introduced in #1070.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants