Introduction

edit

The Meziantou.Framework.Http.* packages add features to HttpClient that it does not have on its own. Most of them are a DelegatingHandler: you put it in the pipeline of a client, and every request that goes through the client gets the feature. The others parse HTTP formats.

What you can do with them

  • Cache responses on the client, following the HTTP caching rules: freshness, validation with ETag and Last-Modified, Vary, No-Vary-Search, immutable and stale-if-error. Keep the cache in memory, in a file, in SQLite or in Redis. See Caching.
  • Enforce HSTS: send the requests to the hosts that require HTTPS over HTTPS, even when the URL says http://, with the HSTS preload list built in. See HSTS.
  • Block server-side request forgery when your application fetches URLs it does not control: reject the schemes, the IP addresses and the networks it must not reach, checked on every connection. See Server-side request forgery.
  • Record and replay the traffic of an HttpClient in tests, to a JSON or a HAR file, with the secrets removed. See Recording.
  • Parse Link headers (RFC 8288), for instance to follow pagination links. See Link headers.
  • Verify credentials against an Apache htpasswd file. See Htpasswd files.

Packages

PackageMain typesPages
Meziantou.Framework.HttpLinkHeaderValueLink headers
Meziantou.Framework.Http.CachingHttpCachingDelegateHandler, IHttpCacheStoreCaching
Meziantou.Framework.Http.Caching.InMemoryInMemoryHttpCacheStoreCaching
Meziantou.Framework.Http.Caching.SqliteSqliteHttpCacheStoreCaching
Meziantou.Framework.Http.Caching.RedisRedisHttpCacheStoreCaching
Meziantou.Framework.Http.HstsHstsClientHandler, HstsDomainPolicyCollectionHSTS
Meziantou.Framework.Http.HtpasswdHtpasswdFileHtpasswd files
Meziantou.Framework.Http.RecordingHttpRecordingHandlerRecording
Meziantou.Framework.Http.ServerSideRequestForgeryServerSideRequestForgeryClientHandlerServer-side request forgery

Each package is independent: install only the ones you need. The HAR files that the recording package reads and writes are described by the HttpArchive package.

Next steps