Class HttpHeaders

  • All Implemented Interfaces:
    DslConfig, DslTestElement, DslTestPlan.TestPlanChild, BaseSampler.SamplerChild, MultiLevelTestElement, BaseThreadGroup.ThreadGroupChild

    public class HttpHeaders
    extends BaseConfigElement
    Allows specifying HTTP headers (through an underlying JMeter HttpHeaderManager) to be used by HTTP samplers.

    This test element can be added at different levels (in the same way as HTTPHeaderManager) of a test plan affecting all samplers in the scope were is added. For example if httpHeaders is specified at test plan, then all headers will apply to http samplers; if it is specified on thread group, then only samplers on that thread group would be affected; if specified as a child of a sampler, only the particular sampler will include such headers. Also take into consideration that headers specified at lower scope will overwrite ones specified at higher scope (eg: sampler child headers will overwrite test plan headers).

    Since:
    0.1
    • Constructor Detail

      • HttpHeaders

        public HttpHeaders()
    • Method Detail

      • header

        public HttpHeaders header​(String name,
                                  String value)
        Allows to set an HTTP header to be used by HTTP samplers.

        To specify multiple headers just invoke this method several times with the different header names and values.

        Parameters:
        name - of the HTTP header.
        value - of the HTTP header.
        Returns:
        the config element for further configuration or usage.
      • header

        public HttpHeaders header​(String name,
                                  PropertyScriptBuilder.PropertyScript<String> valueSupplier)
        Same as header(String, String) but allows using dynamically calculated HTTP header value.

        This method is just an abstraction that uses jexl2 function as HTTP header value.

        WARNING: This only works when using embedded jmeter engine. Check the user guide for details on some alternative.

        Parameters:
        name - of the HTTP header.
        valueSupplier - builds the header value.
        Returns:
        the config element for further configuration or usage.
        Since:
        1.14
      • contentType

        public HttpHeaders contentType​(org.apache.http.entity.ContentType contentType)
        Allows to easily specify the Content-Type HTTP header.
        Parameters:
        contentType - value to use as Content-Type header.
        Returns:
        the config element for further configuration or usage.
        Since:
        0.42
      • isEmpty

        public boolean isEmpty()