/** * Appends the path to the URL, without escaping any meta characters, unless it is empty or {@code null}. * <p> * Has the same result as {@link #encodedPath(String)}, except that empty or {@code null} values are ignored. * * @param path the path to append * @return {@code this} * @since 1.2 */ default HttpUrlBuilder maybeEncodedPath(String path) { if (path != null && !path.isEmpty()) { encodedPath(path); } return this; } /**
@Override public ReceivedResponse request(String path, Action<? super RequestSpec> requestAction) { try (ExecController execController = new DefaultExecController(2)) { URI uri = builder(path).params(params).build(); try (HttpClient httpClient = httpClient()) { response = client.request(httpClient, uri, execController, Duration.ofMinutes(60), requestSpec -> { final RequestSpec decorated = new CookieHandlingRequestSpec(requestSpec); decorated.get(); defaultRequestConfig.execute(decorated); request.execute(decorated); requestAction.execute(decorated); }); } } catch (Throwable throwable) { throw uncheck(throwable); } extractCookies(response); return response; }
/** * Creates a URL by building a URL based on the public address. * * @param action the additions to the public address * @return the built url * @throws Exception any thrown by {@code action} * @since 1.2 */ default URI get(Action<? super HttpUrlBuilder> action) throws Exception { return action.with(builder()).build(); }
/** * Creates a URL builder using the public address as the base. * * @return a URL builder * @since 1.2 */ default HttpUrlBuilder builder() { return HttpUrlBuilder.base(get()); }
/** * Add some query params to the URL. * <p> * The given action will be supplied with a multi map builder, to which it can contribute query params. * <p> * This method is additive with regard to the query params of this builder. * * @param params an action that contributes query params * @return {@code this} * @throws Exception any thrown by {@code params} */ default HttpUrlBuilder params(Action<? super ImmutableMultimap.Builder<String, Object>> params) throws Exception { return params(Action.with(ImmutableMultimap.builder(), params).build()); }
/** * Appends the path to the URL, unless it is empty or {@code null}. * <p> * Has the same result as {@link #path(String)}, except that empty or {@code null} values are ignored. * * @param path the path to append * @return {@code this} * @since 1.2 */ default HttpUrlBuilder maybePath(String path) { if (path != null && !path.isEmpty()) { path(path); } return this; }
private Promise<Clients> createClients(Context ctx, PathBinding pathBinding) throws Exception { String boundTo = pathBinding.getBoundTo(); PublicAddress publicAddress = ctx.get(PublicAddress.class); String absoluteCallbackUrl = publicAddress.get(b -> b.maybeEncodedPath(boundTo).maybeEncodedPath(path)).toASCIIString(); Iterable<? extends Client<?, ?>> result = clientsProvider.get(ctx); @SuppressWarnings("rawtypes") List<Client> clients; if (result instanceof List) { clients = Types.cast(result); } else { clients = ImmutableList.copyOf(result); } return Promise.value(new Clients(absoluteCallbackUrl, clients)); }
/** * Creates a URL by building a URL based on the public address. * * @param ctx the handling context at the time the public address is needed * @param action the additions to the public address * @return the built url * @throws Exception any thrown by {@code action} * @deprecated since 1.2, use {@link #get(Action)} */ @Deprecated default URI get(@SuppressWarnings("UnusedParameters") Context ctx, Action<? super HttpUrlBuilder> action) throws Exception { return action.with(builder()).build(); }
private HttpUrlBuilder builder(String path) { try { URI basePath = new URI(path); if (basePath.isAbsolute()) { return HttpUrlBuilder.base(basePath); } else { path = path.startsWith("/") ? path.substring(1) : path; return HttpUrlBuilder.base(new URI(applicationUnderTest.getAddress().toString() + path)); } } catch (URISyntaxException e) { throw uncheck(e); } }
/** * Creates a URL by appending the given <i>path</i> to the public address * * @param ctx the handling context at the time the public address is needed * @param path the path to append to the public address * @return the public address with the given path appended * @deprecated since 1.2, use {@link #get(String)} */ @Deprecated default URI get(@SuppressWarnings("UnusedParameters") Context ctx, String path) { return builder().path(path).build(); }