apple/pkl · error · HttpClientException

httpRedirectNoLocation

httpRedirectNoLocation

Error message

httpRedirectNoLocation: ${uri}

What it means

Pkl received an HTTP redirect response that lacks the required Location header, so it cannot know where to redirect. doSend throws httpRedirectNoLocation when a 3xx response arrives with no Location header during module fetching.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/http/RequestRewritingClient.java:131

    var redirectCount = 0;
    var currentRequestUri = rewriteUri(request.uri());
    var currentRequest = rewriteRequest(request, currentRequestUri);
    while (true) {
      httpRequestChecker.check(currentRequestUri);
      var response = delegate.send(currentRequest, responseBodyHandler, httpRequestChecker);
      if (!HttpUtils.isRedirectStatusCode(response.statusCode())) {
        return response;
      }
      if (response.body() instanceof Closeable closeable) {
        closeable.close();
      }
      if (redirectCount >= MAX_HTTP_REDIRECTS) {
        throw new HttpClientException(
            ErrorMessages.create("httpTooManyRedirects", MAX_HTTP_REDIRECTS));
      }
      var location = response.headers().firstValue("Location");
      if (location.isEmpty()) {
        throw new HttpClientException(
            ErrorMessages.create("httpRedirectNoLocation", currentRequestUri));
      }
      URI redirectUri;
      try {
        redirectUri = currentRequestUri.resolve(location.get());
      } catch (IllegalArgumentException e) {
        throw new HttpClientException(
            ErrorMessages.create("httpRedirectInvalidUri", currentRequestUri, location.get()));
      }
      if (currentRequestUri.getScheme().equalsIgnoreCase("https")
          && redirectUri.getScheme().equalsIgnoreCase("http")) {
        throw new HttpClientException(
            ErrorMessages.create("httpRedirectCannotDowngrade", currentRequestUri, redirectUri));
      }
      currentRequestUri = rewriteUri(redirectUri);
      currentRequest = rewriteRequest(request, currentRequestUri);
      redirectCount++;
    }

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Inspect the response with `curl -I <url>` to confirm the missing Location header and which server produced it.
  2. Fix the server/proxy to include a Location header on redirect responses.
  3. Update the import/dependency URL to point directly at the final resource, bypassing the broken redirect.
  4. If a proxy/CDN is stripping headers, correct its configuration or bypass it for this host.
  5. Add the host to no_proxy if a corporate proxy is mangling the redirect.

Example fix

// before (proxy config)
add_header Location "";  # emits empty Location
// after (proxy config)
return 302 https://mirror.example.com$request_uri;
Defensive patterns

Strategy: try-catch

Validate before calling

HttpURLConnection c = (HttpURLConnection) URI.create(targetUrl).toURL().openConnection();
c.setInstanceFollowRedirects(false);
if (c.getResponseCode() >= 300 && c.getResponseCode() < 400
    && c.getHeaderField("Location") == null) {
  throw new IllegalStateException("Redirect without Location header from " + targetUrl);
}

Try / catch

try {
  // fetch module
} catch (HttpClientException e) {
  if (e.getMessage().startsWith("httpRedirectNoLocation")) {
    // bypass or fix the misbehaving proxy/server, retry
  }
}

Prevention

When it happens

Trigger: A URL fetched by Pkl (project dependency, import) returns a 3xx status with no Location header; the code checks response.headers().firstValue("Location") and throws when empty.

Common situations: A broken/misconfigured reverse proxy or CDN emitting bare 301/302 responses, a custom auth gateway issuing redirects without Location, or an API endpoint returning 304/3xx unexpectedly to a non-browser client.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/975be00c6abff05d. Report an issue: GitHub.