Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

HTTPClient Caching (maybe?) inside the WithHTTPServiceProvider #2

@eoincampbell

Description

@eoincampbell

Hey @spetz

Just wondering if you can point me in the right direction on an issue we're seeing, that I'm having trouble getting to the bottom of.

One of our web endpoints requires a bearertoken to be created. We're seeing that after a period of time, the bearertoken expires and so subsequent checks fail (as the watcher already exists with old bearertoken)

So we changed the code to the following using the WithHttpServiceProvider method which I assumed would create a new HttpClient with a new BearerToken for each watch iteration.

This doesn't seem to be working though (it seems like something is still being cached... possibly httpclient pooling maybe) but can't put my finger on it. Any ideas ?

var builder = WebWatcherConfiguration.Create(url);
builder = builder.EnsureThat(resp =>
{
	//check result code
});

builder.WithHttpServiceProvider(() =>
{
	tokenBearer = _authorizationManager
		.Authenticate(Settings.Current.ClientId, Settings.Current.Secret, Settings.Current.TenantId);

	var httpClient = new HttpClient();
	httpClient.DefaultRequestHeaders.Add("Authorization", $"bearer {tokenBearer}");
	return new HttpService(httpClient);
});

watcher = WebWatcher.Create(config.TestName, builder.Build(), config.Group);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions