Пример #1
0
 @Get
 @At("/:port/limit")
 public Reply<?> getLimits(@Named("port") int port, Request<String> request) {
   LegacyProxyServer proxy = proxyManager.get(port);
   if (proxy == null) {
     return Reply.saying().notFound();
   }
   return Reply.with(new BandwidthLimitDescriptor(proxy.getStreamManager())).as(Json.class);
 }
Пример #2
0
  @Put
  @At("/:port/limit")
  public Reply<?> limit(@Named("port") int port, Request<String> request) {
    LegacyProxyServer proxy = proxyManager.get(port);
    if (proxy == null) {
      return Reply.saying().notFound();
    }

    StreamManager streamManager = proxy.getStreamManager();
    String upstreamKbps = request.param("upstreamKbps");
    if (upstreamKbps != null) {
      try {
        streamManager.setUpstreamKbps(Integer.parseInt(upstreamKbps));
        streamManager.enable();
      } catch (NumberFormatException e) {
      }
    }

    String upstreamBps = request.param("upstreamBps");
    if (upstreamBps != null) {
      try {
        ((BrowserMobProxy) proxy).setWriteBandwidthLimit(Integer.parseInt(upstreamBps));
      } catch (NumberFormatException e) {
      }
    }

    String downstreamKbps = request.param("downstreamKbps");
    if (downstreamKbps != null) {
      try {
        streamManager.setDownstreamKbps(Integer.parseInt(downstreamKbps));
        streamManager.enable();
      } catch (NumberFormatException e) {
      }
    }

    String downstreamBps = request.param("downstreamBps");
    if (downstreamBps != null) {
      try {
        ((BrowserMobProxy) proxy).setReadBandwidthLimit(Integer.parseInt(downstreamBps));
      } catch (NumberFormatException e) {
      }
    }

    String upstreamMaxKB = request.param("upstreamMaxKB");
    if (upstreamMaxKB != null) {
      try {
        streamManager.setUpstreamMaxKB(Integer.parseInt(upstreamMaxKB));
        streamManager.enable();
      } catch (NumberFormatException e) {
      }
    }
    String downstreamMaxKB = request.param("downstreamMaxKB");
    if (downstreamMaxKB != null) {
      try {
        streamManager.setDownstreamMaxKB(Integer.parseInt(downstreamMaxKB));
        streamManager.enable();
      } catch (NumberFormatException e) {
      }
    }
    String latency = request.param("latency");
    if (latency != null) {
      try {
        streamManager.setLatency(Integer.parseInt(latency));
        streamManager.enable();
      } catch (NumberFormatException e) {
      }
    }
    String payloadPercentage = request.param("payloadPercentage");
    if (payloadPercentage != null) {
      try {
        streamManager.setPayloadPercentage(Integer.parseInt(payloadPercentage));
      } catch (NumberFormatException e) {
      }
    }
    String maxBitsPerSecond = request.param("maxBitsPerSecond");
    if (maxBitsPerSecond != null) {
      try {
        streamManager.setMaxBitsPerSecondThreshold(Integer.parseInt(maxBitsPerSecond));
      } catch (NumberFormatException e) {
      }
    }
    String enable = request.param("enable");
    if (enable != null) {
      if (Boolean.parseBoolean(enable)) {
        streamManager.enable();
      } else {
        streamManager.disable();
      }
    }
    return Reply.saying().ok();
  }