Skip to content

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

Merged
Brahm Lower (brahmlower) merged 1 commit into
mainfrom
brahmlower/add-request-id-header-support
Mar 28, 2024
Merged

feat: add support for setting x-request-id header#606
Brahm Lower (brahmlower) merged 1 commit into
mainfrom
brahmlower/add-request-id-header-support

Conversation

@brahmlower

Copy link
Copy Markdown
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.

Comment thread censys/common/base.py Outdated
@brahmlower
Brahm Lower (brahmlower) force-pushed the brahmlower/add-request-id-header-support branch from 9c90584 to 1d710be Compare March 28, 2024 18:49
@brahmlower
Brahm Lower (brahmlower) force-pushed the brahmlower/add-request-id-header-support branch from 1d710be to 0d48d04 Compare March 28, 2024 18:50

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@brahmlower
Brahm Lower (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