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

feat: add support for setting x-request-id header #606

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

brahmlower
Copy link
Contributor

This PR adds mediocre support for setting request ids to support request debugging.

Methods on censys.search.{CensysHosts|CensysCerts} don't support configuring the underlying request object on each call. Given that **kwargs is used to glob additional search params on most methods, I didn't see a clean and consistent way to support setting one-off request options through the query methods themselves.

Support for setting the x-request-id header is implemented by adding a property to the CensysAPIBase class, where updates will mutate the request objects headers, so that the next request will include the assigned request-id value.

This leads to an awkward, though functional, usage pattern:

from censys.search import CensysHosts

h = CensysHosts(request_id="test-id-0")
host = h.view("8.8.8.8")                    # request with  x-request-id: test-id-0

h.request_id = "test-id-1"
host = h.view("8.8.8.8")                    # request with  x-request-id: test-id-1

host = h.view("8.8.8.8")                    # request with  x-request-id: test-id-1

h.request_id = "test-id-2"
host = h.view("8.8.8.8")                    # request with  x-request-id: test-id-2

h.request_id = None
host = h.view("8.8.8.8")                    # request without x-request-id

h.request_id = "test-id-3"
host = h.view("8.8.8.8")                    # request with  x-request-id: test-id-3

This ux is definitely not ideal, but it makes the feature available quickly with minimal changes to the package interfaces. I figure this is tolerable for now since it's only meant for debugging.

@brahmlower brahmlower force-pushed the brahmlower/add-request-id-header-support branch from 6355f02 to e801c34 Compare March 28, 2024 18:28
@brahmlower brahmlower force-pushed the brahmlower/add-request-id-header-support branch 2 times, most recently from 6df5ba2 to 9c90584 Compare March 28, 2024 18:37
@brahmlower brahmlower force-pushed the brahmlower/add-request-id-header-support branch from 9c90584 to 1d710be Compare March 28, 2024 18:49
@brahmlower brahmlower force-pushed the brahmlower/add-request-id-header-support branch from 1d710be to 0d48d04 Compare March 28, 2024 18:50
Copy link
Member

@thehappydinoa thehappydinoa left a comment

Choose a reason for hiding this comment

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

LGTM!

@brahmlower brahmlower merged commit d5533d1 into main Mar 28, 2024
5 checks passed
@brahmlower brahmlower deleted the brahmlower/add-request-id-header-support branch March 28, 2024 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants