Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to extract certain headers to the header manager #1

Open
nigelsim opened this issue Jul 26, 2024 · 1 comment
Open

Ability to extract certain headers to the header manager #1

nigelsim opened this issue Jul 26, 2024 · 1 comment

Comments

@nigelsim
Copy link

It'd be really great to be able to extract the Authorization header out to the Header Manager, so that can can keep the script valid by simply updating the Bearer token.

@vdaburon
Copy link
Owner

vdaburon commented Jul 26, 2024

With the parameter remove_cookie the program will remove all cookies may be also the Authorization, set to false to keep all cookie values.

With the parameter remove_cache_request the program will remove cache informations.
Extract :

if (harRequest.getHeaders() != null && harRequest.getHeaders().size() > 0) {
for (HarHeader header : harRequest.getHeaders()) {
String headerName = header.getName();
String headerValue = header.getValue();
boolean addThisHearder = true;

            if ("Cookie".equalsIgnoreCase(headerName)) {
                if (isRemoveCookie) {
                    // no cookie because add a Cookie Manager
                    addThisHearder = false;
                }
            }

            if ("If-Modified-Since".equalsIgnoreCase(headerName) || "If-None-Match".equalsIgnoreCase(headerName) || "If-Last-Modified".equalsIgnoreCase(headerName)) {
                if (isRemoveCacheRequest) {
                    // no cache If-Modified-Since or If-None-Match because add a Cache Manager
                    addThisHearder = false;
                }
            }

            if ("Content-Length".equalsIgnoreCase(headerName)) {
                // the Content-length is computed by JMeter when the request is created, so remove it
                addThisHearder = false;
            }

            if(addThisHearder) {
                Element elementProp = createElementProp(document, headerName, "Header", null, null, null);

                Element stringProp1 = createProperty(document, "stringProp", "Header.name", headerName);
                elementProp.appendChild(stringProp1);

                Element stringProp2 = createProperty(document, "stringProp", "Header.value", headerValue);
                elementProp.appendChild(stringProp2);
                collectionProp.appendChild(elementProp);
            }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants