@Override
  public WebhookDelivery call(Webhook webhook, WebhookPayload payload) {
    WebhookDelivery.Builder builder = new WebhookDelivery.Builder();
    long startedAt = system.now();
    builder
      .setAt(startedAt)
      .setPayload(payload)
      .setWebhook(webhook);

    try {
      HttpUrl url = HttpUrl.parse(webhook.getUrl());
      if (url == null) {
        throw new IllegalArgumentException("Webhook URL is not valid: " + webhook.getUrl());
      }
      builder.setEffectiveUrl(HttpUrlHelper.obfuscateCredentials(webhook.getUrl(), url));
      Request request = buildHttpRequest(url, webhook, payload);
      try (Response response = execute(request)) {
        builder.setHttpStatus(response.code());
      }
    } catch (Exception e) {
      builder.setError(e);
    }

    return builder
      .setDurationInMs((int) (system.now() - startedAt))
      .build();
  }
@Test
  public void send_basic_authentication_header_if_url_contains_credentials() throws Exception {
    HttpUrl url = server.url("/ping").newBuilder().username("theLogin").password("thePassword").build();
    Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID,
      randomAlphanumeric(40), "my-webhook", url.toString(), null);
    server.enqueue(new MockResponse().setBody("pong"));

    WebhookDelivery delivery = newSender(false).call(webhook, PAYLOAD);

    assertThat(delivery.getWebhook().getUrl())
      .isEqualTo(url.toString())
      .contains("://theLogin:thePassword@");
    RecordedRequest recordedRequest = takeAndVerifyPostRequest("/ping");
    assertThat(recordedRequest.getHeader("Authorization")).isEqualTo(Credentials.basic(url.username(), url.password()));
  }