Add support for HTTP rewrites (#1062)

This adds a new configuration option for the HTTP client to replace URI prefixes when making outbound calls.

Follows the design of https://github.com/apple/pkl-evolution/pull/17
This commit is contained in:
Daniel Chao
2025-07-16 15:53:31 -07:00
committed by GitHub
parent fea031a138
commit 99020bb79d
27 changed files with 607 additions and 47 deletions

View File

@@ -473,6 +473,7 @@ public class PklPlugin implements Plugin<Project> {
task.getTestPort().set(spec.getTestPort());
task.getHttpProxy().set(spec.getHttpProxy());
task.getHttpNoProxy().set(spec.getHttpNoProxy());
task.getHttpRewrites().set(spec.getHttpRewrites());
}
private List<File> getTransitiveModules(AnalyzeImportsTask analyzeTask) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,4 +57,6 @@ public interface BasePklSpec {
Property<URI> getHttpProxy();
ListProperty<String> getHttpNoProxy();
MapProperty<URI, URI> getHttpRewrites();
}

View File

@@ -142,6 +142,10 @@ public abstract class BasePklTask extends DefaultTask {
@Optional
public abstract ListProperty<String> getHttpNoProxy();
@Input
@Optional
public abstract MapProperty<URI, URI> getHttpRewrites();
/**
* There are issues with using native libraries in Gradle plugins. As a workaround for now, make
* Truffle use an un-optimized runtime.
@@ -195,6 +199,7 @@ public abstract class BasePklTask extends DefaultTask {
Collections.emptyList(),
getHttpProxy().getOrNull(),
getHttpNoProxy().getOrElse(List.of()),
getHttpRewrites().getOrNull(),
Map.of(),
Map.of());
}

View File

@@ -163,6 +163,7 @@ public abstract class ModulesTask extends BasePklTask {
Collections.emptyList(),
null,
List.of(),
getHttpRewrites().getOrNull(),
Map.of(),
Map.of());
}