It's possible to add custom header on part

Hi,
I want to add custom header on bodyPart, how I can do

–NJHlCFfMK14PDQdfesESkr5_BTXNCL
Content-Disposition:
Content-Type: application/xop+xml; type="application/soap+xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <contentid>
MyHeader: MyValue

soap:Envelope/
–NJHlCFfMK14PDQdfesESkr5_BTXNCL

http(“request_0”)
.post("/MyURL")
.headers(headers_0)
.bodyPart(RawFileBodyPart(MyFile)
.contentType(""“application/xop+xml; type=“application/soap+xml””"")
.charset(“UTF-8”)
.transferEncoding(“8bit”)
.contentId(“contentId”)
.dispositionType("")
.addPartHeader(“MyHeader”, “MyValue”)
)
)

Thanks

http://gatling.io/docs/2.1.6/http/http_request.html#headers

@Abhinav: @Yva is talking about custom multipart header, not request header.

@Yva Custom multipart headers are not currently supported. It would have to be supported in AsyncHttpClient first so Gatling can use it. Technically feasible, I opened some feature requests for this: https://github.com/gatling/gatling/issues/2723

It would help if you could provide a sample of a full multipart body.

As a workaround, you could probably write a single template for the whole body, instead of using multipart. You’d just have to generate the multipart boundary yourself, store it in the session, and pass it to the template with some EL expression.

Thank you for your answer, but the problem is that some parts are in binary format and the ELFileBody corrupts binaries parts.
The workaround for this problem is to have a body method which takes as parameters List of sources
exec (http (“Request).post(” URI).Body (ELFilePartialBody (“part1.txt”) RawFilePartialBody (“part2.bin”), …) but I do not know if really relevant

I find a workaround that works, but that is not clean, by overriding the method visitEndOfHeader in class ByteArrayPart, FilePart and StringPart.

Exempe :

public class StringPartWithCustomHeader extends StringPart {
private final HeadersPart headersPart;
public StringPartWithCustomHeader(final String name, final String value, final HeadersPart headersPart) {
super(name, value);
this.headersPart = headersPart;
}
public StringPartWithCustomHeader(final String name, final String value, final String contentType, final HeadersPart headersPart) {
super(name, value, contentType);
this.headersPart = headersPart;
}
public StringPartWithCustomHeader(final String name, final String value, final String contentType, final Charset charset, final HeadersPart headersPart) {
super(name, value, contentType, charset);
this.headersPart = headersPart;
}
public StringPartWithCustomHeader(final String name, final String value, final String contentType, final Charset charset, final String contentId, final HeadersPart headersPart) {
super(name, value, contentType, charset, contentId);
this.headersPart = headersPart;
}
public StringPartWithCustomHeader(final String name, final String value, final String contentType, final Charset charset, final String contentId, final String transferEncoding, final HeadersPart headersPart) {
super(name, value, contentType, charset, contentId, transferEncoding);
this.headersPart = headersPart;
}

@Override
protected void visitEndOfHeader(PartVisitor visitor) throws IOException {
//Adding my headers before
headersPart.visitCustomdHeaders(visitor);
super.visitEndOfHeader(visitor)
}
}

My MultipartBody
–w6TmHRk-z1J3VAu3BiN8qnbuclBQFqI
Content-Disposition:
Content-Type: application/xop+xml; type="application/soap+xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <rootpart@soapui.org>
MyHeader: Myvalue

<soap:Envelope xmlns:soap=“http://www.w3.org/2003/05/soap-envelope”>
soap:Body
leav:xml
leav:param1${PARAM_1}</leav:param1>
leav:param2${PARAM_2}</leav:param2>
leav:param3${PARAM_3}</leav:param3>
</leav:xml>
</soap:Body>
</soap:Envelope>
–w6TmHRk-z1J3VAu3BiN8qnbuclBQFqI
Content-Disposition: attachment; name=“file.zip”; filename=“file”
Content-Type: application/zip; name=file.zip
Content-Transfer-Encoding: binary
Content-ID: <file.zip>
MyHeader1: Myvalue1

--w6TmHRk-z1J3VAu3BiN8qnbuclBQFqI--

I just push support for multipart custom headers: https://github.com/gatling/gatling/issues/2723

Cheers,

Thank you for your quick support