https://github.com/tilln/jmeter-cors-plugin
JMeter Plugin for making CORS preflight requests
https://github.com/tilln/jmeter-cors-plugin
cors jmeter jmeter-plugin preflight
Last synced: 5 months ago
JSON representation
JMeter Plugin for making CORS preflight requests
- Host: GitHub
- URL: https://github.com/tilln/jmeter-cors-plugin
- Owner: tilln
- License: mit
- Created: 2024-08-26T01:47:52.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-28T00:39:33.000Z (over 1 year ago)
- Last Synced: 2025-02-28T09:03:23.789Z (over 1 year ago)
- Topics: cors, jmeter, jmeter-plugin, preflight
- Language: Java
- Homepage:
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: docs/README.md
- License: LICENSE
Awesome Lists containing this project
README
# jmeter-cors-plugin [](https://github.com/tilln/jmeter-cors-plugin/actions/workflows/release.yml)
Overview
--------
[Apache JMeter](https://jmeter.apache.org/) plugin for making [CORS-preflight requests](https://fetch.spec.whatwg.org/#cors-preflight-request)
before HTTP requests to resources on other origins.
Similar to how a browser preflights cross-origin requests, e.g. REST API requests from
[single-page applications](https://en.wikipedia.org/wiki/Single-page_application),
this plugin creates a preflight request if necessary, without the need to explicitly
add a Sampler for it to the JMeter Test Plan.
It also simulates a [CORS-preflight cache](https://fetch.spec.whatwg.org/#cors-preflight-cache) to avoid
unnecessary preflight requests, just as a browser would.
#### Example

Usage
-----
### CORS Pre-Processor
Simply add a *CORS Pre-Processor* to the [scope](https://jmeter.apache.org/usermanual/test_plan.html#scoping_rules)
of any samplers that should make preflight requests.

#### Preflight Requests
- *Sample Suffix*: String to append to the preflight request's sample label (default: "-preflight").
#### Preflight Cache
- *Clear cache each iteration?*: When set to "True" or "False" the preflight cache can be explicitly cleared or kept
between Thread iterations. When left blank, it is only cleared when Thread Group property
"Same user on each iteration" is *not* set.
- *Default expiry (seconds)*: Cache expiry duration to apply when no "Access-Control-Max-Age" header is returned.
This allows overriding the 5 seconds the [specification](https://fetch.spec.whatwg.org/#http-access-control-max-age) defines.
Installation
------------
### Via [PluginsManager](https://jmeter-plugins.org/wiki/PluginsManager/)
Under tab "Available Plugins", select "CORS Pre-Processor", then click "Apply Changes and Restart JMeter".
### Via Package from [JMeter-Plugins.org](https://jmeter-plugins.org/)
Extract the [zip package](https://jmeter-plugins.org/files/packages/tilln-cors-plugin-1.1.zip) into JMeter's home directory, then restart JMeter.
### Via Manual Download
1. Copy the [jmeter-cors-plugin jar file](https://github.com/tilln/jmeter-cors-plugin/releases/download/1.1/jmeter-cors-plugin-1.1.jar) into JMeter's lib/ext directory.
2. Restart JMeter.
Limitations
-----------
- Minimum JMeter version 5.2.1
- Timers, Pre-Processors, Post-Processors, and Assertions are **not** executed for the preflight request, but only once for the actual HTTP sampler.
The preflight request will be made by a clone of the actual sampler after the preceding Pre-Processors have run.
Pre-processors appearing **after** the CORS Pre-Processor will be effective for the actual sampler only.
- CORS Pre-Processors are not "aware" of one another, so if a sampler's scope contains more than one,
multiple preflight requests will be made.