+
Skip to content

Add case-instensitive GetHeader for HookRequest & HookResponse #3556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2025

Conversation

sparshev
Copy link
Contributor

Simple implementation for case-insensitive GetHeader. I thought about caching the keys, but it seems too complicated for now with additional not predictable memory consumption. Tests are included.

Fixes #3555

@gmlewis gmlewis changed the title Added case-instensitive GetHeader for HookRequest & HookResponse Add case-instensitive GetHeader for HookRequest & HookResponse Apr 18, 2025
Copy link

codecov bot commented Apr 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.24%. Comparing base (6a7684f) to head (2d0b5cc).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3556   +/-   ##
=======================================
  Coverage   91.23%   91.24%           
=======================================
  Files         183      183           
  Lines       16053    16063   +10     
=======================================
+ Hits        14646    14656   +10     
  Misses       1231     1231           
  Partials      176      176           

☔ 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.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

If you add one more test case to each of your tests that covers lines 57 and 78, respectively, then the linter will be happy. 😄

@sparshev
Copy link
Contributor Author

Oh you right! Completely forgot about negative cases)

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @sparshev!
LGTM.

Awaiting second LGTM+Approval from any other contributor to this repo before merging.

@stevehipwell - might you have time for a code review? Thank you!

@atilsensalduz
Copy link
Contributor

LGTM! Tiny nit: wdyt to abstract the common functionality into a shared helper function aims to reduce code duplication like below?

func getHeader(headers map[string]string, key string) string {
	for k, v := range headers {
		if strings.EqualFold(k, key) {
			return v
		}
	}
	return ""
}

func (r *HookRequest) GetHeader(key string) string {
	return getHeader(r.Headers, key)
}

func (r *HookResponse) GetHeader(key string) string {
	return getHeader(r.Headers, key)
}

@gmlewis
Copy link
Collaborator

gmlewis commented Apr 18, 2025

Thank you, @atilsensalduz and @sparshev!
Merging after the tests all pass.

@gmlewis gmlewis merged commit 5b75aa8 into google:master Apr 18, 2025
7 checks passed
@sparshev sparshev deleted the hookrequest_hookresponse_getheader branch April 18, 2025 21:06
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.

HookRequest.Headers and HookResponse.Headers maps need to be canonicalized
3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载