Skip to content
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

Add exit-on-unmatched-rule option for http server #63

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

marc-gr
Copy link
Contributor

@marc-gr marc-gr commented Nov 7, 2023

Closes #61

@marc-gr marc-gr force-pushed the exit-on-unmatched-rule branch from b59d414 to 20e61d1 Compare November 7, 2023 13:17
@marc-gr marc-gr requested a review from andrewkroh November 7, 2023 13:17
@elasticmachine
Copy link

elasticmachine commented Nov 7, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-11-07T13:18:03.831+0000

  • Duration: 6 min 52 sec

Test stats 🧪

Test Results
Failed 0
Passed 22
Skipped 0
Total 22

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@marc-gr marc-gr merged commit 33314ff into elastic:main Nov 7, 2023
@marc-gr marc-gr deleted the exit-on-unmatched-rule branch November 7, 2023 15:39
handler, err := newHandlerFromConfig(config, logger)
notFoundHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logger.Debugf("request did not match with any rule: %s", strRequest(r))
w.WriteHeader(404)
Copy link
Member

Choose a reason for hiding this comment

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

I think there is an http.NotFound constant.

logger.Debugf("request did not match with any rule: %s", strRequest(r))
w.WriteHeader(404)
if opts.ExitOnUnmatchedRule {
logger.Fatalf("--exit-on-unmatched-rule is set, exiting")
Copy link
Member

@andrewkroh andrewkroh Nov 7, 2023

Choose a reason for hiding this comment

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

I think it would be more graceful to asynchronously stop the server. With os.Exit being called from the handler there is no guarantee that the response has been flushed to the client before the program stops.

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.

Add option to http mock to fail if it gets a request that does not match
4 participants