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

Removing headers that were automatically added #1785

Open
mmcdermo2 opened this issue Apr 25, 2024 · 0 comments
Open

Removing headers that were automatically added #1785

mmcdermo2 opened this issue Apr 25, 2024 · 0 comments

Comments

@mmcdermo2
Copy link

I’m trying to write a test at the moment to perform a multipart POST operation. However, the request is generating some headers that I didn’t add, and that I don’t want (resulting in the request getting filtered by our WAF). The headers in question are:

Transfer-Encoding
Accept-Encoding
Content-Transfer-Encoding

I’ve tried casting the Request to a FilterableRequest and removing the headers, but they don’t get removed. I suspect they’re getting added by the Apache HttpClient ? Is there any way to remove such headers using REST Assured ? Below is what I have so far

        byte[] fileContent;
        try {
            fileContent = Files.readAllBytes(Path.of(file.getPath()));
        }
        catch (IOException ioException) {
            throw new TestException(ioException.getMessage());
        }

        FilterableRequestSpecification given = (FilterableRequestSpecification)
        given()
                .config(RestAssuredConfig.config()
                        .sslConfig(SSLConfig.sslConfig()
                                .relaxedHTTPSValidation()
                                .allowAllHostnames()
                                )
                )
                .contentType(MULTIPART_FORM_DATA)
                .accept("application/json")
                .auth().oauth2(token.getAccessToken())
                .multiPart(new MultiPartSpecBuilder(fileContent)
                        .controlName("file")
                        .fileName(file.getName())
                        .mimeType("text/xml")
                        .build());

        final String response =
        given
                .removeHeader("Transfer-Encoding")
                .removeHeader("Accept-Encoding")
                .removeHeader("Content-Transfer-Encoding")
        .when()
                .log().all()
                .post(REPORTS_IMPORT_URL_ENDPOINT)
        .then()
                .log().all()
                .statusCode(HttpStatus.SC_CREATED)
                .extract()
                .body()
                .asString();

And this is the request that gets generated

POST /api/v1/reports HTTP/1.1
User-Agent: Apache-HttpClient/4.4.1 (Java/11.0.22)
Authorization: Bearer  <token removed>
Accept: application/json
Connection: close
Transfer-Encoding: chunked
Content-Type: multipart/form-data; boundary=iho-Fb5-DiGJsfc5qR03lUI0sQ_XVoxMGP7gjkt
Host: x.x.x.x

Accept-Encoding: gzip,deflate

--iho-Fb5-DiGJsfc5qR03lUI0sQ_XVoxMGP7gjkt
Content-Disposition: form-data; name="file"; filename="Report.xml"
Content-Type: text/xml
Content-Transfer-Encoding: binary

<?xml version="1.0" encoding="utf-8" ?>
<reportexport>
    <name>Report</name>
     <field1>sample value</field>
</reportexport>
--iho-Fb5-DiGJsfc5qR03lUI0sQ_XVoxMGP7gjkt--

I know there’s a PR up to remove the deprecated Content-Transfer-Encoding header, but even still I would need to remove the other two. Does anybody have any idea what I’m doing wrong ? Any help would be really greatly appreciated.

Thanks in advance

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

1 participant