Working with HTML responses is a recurring need in web debugging: you might want to inject a probe script, force a no cache policy, or simply tag pages so they stand out from the asset noise. The htmlResponseFilter is the fastest way to scope a rule to that subset, relying on the Content-Type header so it runs as soon as the response is identified.
Use htmlResponseFilter when a rule should only run on responses returning HTML. The filter inspects the Content-Type header for a text/html hint, so it triggers as soon as the response headers arrive, before the body is fully streamed.
Typical uses:
Add a script tag right before on every HTML response so you can profile pages without rebuilding the app.
rules:
- filter:
typeKind: HtmlResponseFilter
actions:
- typeKind: InjectHtmlTagAction
tag: '<script src="https://debug.example.com/probe.js"></script>'
location: BeforeHeadEnd
Force the browser to refetch HTML on every load while leaving CSS and images cached normally.
rules:
- filter:
typeKind: HtmlResponseFilter
actions:
- typeKind: RemoveCacheAction
Single out HTML pages from one origin so you can quickly find them in a busy capture.
rules:
- filter:
typeKind: FilterCollection
operation: And
children:
- typeKind: HtmlResponseFilter
- typeKind: HostFilter
pattern: www.example.com
operation: Exact
actions:
- typeKind: ApplyTagAction
tag:
value: html-page
Select exchanges having HTML body. The content-type header is checked to determine if the content body is has text/html hint.
Evaluation scope defines the timing where this filter will be applied.
responseHeaderReceivedFromRemote This scope occurs the moment fluxzy has done parsing the response header.
htmlResponseFilter
This filter has no specific characteristic
The following table describes the customizable properties available for this filter:
| Property | Type | Description | DefaultValue |
|---|---|---|---|
| inverted | boolean | Negate the filter result | false |
The following examples apply a comment to the filtered exchange
Select exchanges having HTML body. The content-type header is checked to determine if the content body is has text/html hint.
rules:
- filter:
typeKind: HtmlResponseFilter
actions:
- typeKind: ApplyCommentAction
comment: filter was applied
View definition of HtmlResponseFilter for .NET integration.
The following filters are related to this filter:
Only the Content-Type header is inspected. If a server lies about the content type, the filter will trust the header. Pair it with body inspection if you need real sniffing.
No. It triggers only on text/html. Use contentTypeXmlFilter for XML responses and pair filters together if you want both.
Yes. Wrap it inside a FilterCollection along with statusCodeSuccessFilter to act only on successful HTML responses.