All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hyperfoil.core.handlers.CountHeadersHandler Maven / Gradle / Ivy

There is a newer version: 0.27.1
Show newest version
package io.hyperfoil.core.handlers;

import org.kohsuke.MetaInfServices;

import io.hyperfoil.api.config.Locator;
import io.hyperfoil.api.config.Step;
import io.hyperfoil.api.connection.HttpRequest;
import io.hyperfoil.api.http.HeaderHandler;
import io.hyperfoil.api.statistics.IntValue;
import io.hyperfoil.function.SerializableSupplier;

public class CountHeadersHandler implements HeaderHandler {
   @Override
   public void handleHeader(HttpRequest request, CharSequence header, CharSequence value) {
      IntValue custom = request.statistics().getCustom(request.startTimestampMillis(), header, IntValue::new);
      custom.add(1);
   }

   /**
    * Stores number of occurences of each header in custom statistics (these can be displayed in CLI using the stats -c command).
    */
   public static class Builder implements HeaderHandler.Builder {
      @Override
      public CountHeadersHandler build(SerializableSupplier step) {
         return new CountHeadersHandler();
      }
   }

   @MetaInfServices(HeaderHandler.BuilderFactory.class)
   public static class BuilderFactory implements HeaderHandler.BuilderFactory {
      @Override
      public String name() {
         return "countHeaders";
      }

      @Override
      public boolean acceptsParam() {
         return false;
      }

      @Override
      public Builder newBuilder(Locator locator, String param) {
         return new Builder();
      }
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy