{"record":{"id":"975be00c6abff05d","repo":"apple/pkl","slug":"httpredirectnolocation","errorCode":"httpRedirectNoLocation","errorMessage":"httpRedirectNoLocation: ${uri}","messagePattern":"httpRedirectNoLocation: (.+?)","errorType":"exception","errorClass":"HttpClientException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/http/RequestRewritingClient.java","lineNumber":131,"sourceCode":"    var redirectCount = 0;\n    var currentRequestUri = rewriteUri(request.uri());\n    var currentRequest = rewriteRequest(request, currentRequestUri);\n    while (true) {\n      httpRequestChecker.check(currentRequestUri);\n      var response = delegate.send(currentRequest, responseBodyHandler, httpRequestChecker);\n      if (!HttpUtils.isRedirectStatusCode(response.statusCode())) {\n        return response;\n      }\n      if (response.body() instanceof Closeable closeable) {\n        closeable.close();\n      }\n      if (redirectCount >= MAX_HTTP_REDIRECTS) {\n        throw new HttpClientException(\n            ErrorMessages.create(\"httpTooManyRedirects\", MAX_HTTP_REDIRECTS));\n      }\n      var location = response.headers().firstValue(\"Location\");\n      if (location.isEmpty()) {\n        throw new HttpClientException(\n            ErrorMessages.create(\"httpRedirectNoLocation\", currentRequestUri));\n      }\n      URI redirectUri;\n      try {\n        redirectUri = currentRequestUri.resolve(location.get());\n      } catch (IllegalArgumentException e) {\n        throw new HttpClientException(\n            ErrorMessages.create(\"httpRedirectInvalidUri\", currentRequestUri, location.get()));\n      }\n      if (currentRequestUri.getScheme().equalsIgnoreCase(\"https\")\n          && redirectUri.getScheme().equalsIgnoreCase(\"http\")) {\n        throw new HttpClientException(\n            ErrorMessages.create(\"httpRedirectCannotDowngrade\", currentRequestUri, redirectUri));\n      }\n      currentRequestUri = rewriteUri(redirectUri);\n      currentRequest = rewriteRequest(request, currentRequestUri);\n      redirectCount++;\n    }","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/http/RequestRewritingClient.java#L113-L149","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the response with `curl -I <url>` to confirm the missing Location header and which server produced it.","Fix the server/proxy to include a Location header on redirect responses.","Update the import/dependency URL to point directly at the final resource, bypassing the broken redirect.","If a proxy/CDN is stripping headers, correct its configuration or bypass it for this host.","Add the host to no_proxy if a corporate proxy is mangling the redirect."],"exampleFix":"// before (proxy config)\nadd_header Location \"\";  # emits empty Location\n// after (proxy config)\nreturn 302 https://mirror.example.com$request_uri;","handlingStrategy":"try-catch","validationCode":"HttpURLConnection c = (HttpURLConnection) URI.create(targetUrl).toURL().openConnection();\nc.setInstanceFollowRedirects(false);\nif (c.getResponseCode() >= 300 && c.getResponseCode() < 400\n    && c.getHeaderField(\"Location\") == null) {\n  throw new IllegalStateException(\"Redirect without Location header from \" + targetUrl);\n}","typeGuard":null,"tryCatchPattern":"try {\n  // fetch module\n} catch (HttpClientException e) {\n  if (e.getMessage().startsWith(\"httpRedirectNoLocation\")) {\n    // bypass or fix the misbehaving proxy/server, retry\n  }\n}","preventionTips":["Verify dependency URLs return proper 3xx responses with curl -I before adding them.","Audit reverse proxy/CDN configurations for redirect responses lacking Location.","Point imports directly at final URLs to avoid fragile redirect chains.","Check whether a corporate proxy is stripping headers and add the host to no_proxy if so."],"tags":["http","redirects","network","missing-header"],"backgroundTag":"http-error-response","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}