{"record":{"id":"42cb31ea03a86e90","repo":"bumptech/glide","slug":"bad-redirect-url-redirecturlstring","errorCode":null,"errorMessage":"Bad redirect url: {redirectUrlString}","messagePattern":"Bad redirect url: (.+?)","errorType":"http","errorClass":"HttpException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/load/data/HttpUrlFetcher.java","lineNumber":118,"sourceCode":"    }\n\n    if (isCancelled) {\n      return null;\n    }\n\n    final int statusCode = getHttpStatusCodeOrInvalid(urlConnection);\n    if (isHttpOk(statusCode)) {\n      return getStreamForSuccessfulRequest(urlConnection);\n    } else if (isHttpRedirect(statusCode)) {\n      String redirectUrlString = urlConnection.getHeaderField(REDIRECT_HEADER_FIELD);\n      if (TextUtils.isEmpty(redirectUrlString)) {\n        throw new HttpException(\"Received empty or null redirect url\", statusCode);\n      }\n      URL redirectUrl;\n      try {\n        redirectUrl = new URL(url, redirectUrlString);\n      } catch (MalformedURLException e) {\n        throw new HttpException(\"Bad redirect url: \" + redirectUrlString, statusCode, e);\n      }\n      // Closing the stream specifically is required to avoid leaking ResponseBodys in addition\n      // to disconnecting the url connection below. See #2352.\n      cleanup();\n      return loadDataWithRedirects(redirectUrl, redirects + 1, url, headers);\n    } else if (statusCode == INVALID_STATUS_CODE) {\n      throw new HttpException(statusCode);\n    } else {\n      try {\n        throw new HttpException(urlConnection.getResponseMessage(), statusCode);\n      } catch (IOException e) {\n        throw new HttpException(\"Failed to get a response message\", statusCode, e);\n      }\n    }\n  }\n\n  private static int getHttpStatusCodeOrInvalid(HttpURLConnection urlConnection) {\n    try {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/data/HttpUrlFetcher.java#L100-L136","documentation":"After extracting a non-empty Location header from a redirect response, HttpUrlFetcher attempts to construct a java.net.URL from it (resolved relative to the current URL). If the Location header contains a syntactically invalid URL, the MalformedURLException is caught and re-thrown as an HttpException with the bad URL string and the redirect status code.","triggerScenarios":"Server returns a Location header with illegal characters, spaces, or malformed scheme. Relative redirect path that cannot be resolved against the base URL. Server sends a Location value with unescaped Unicode characters.","commonSituations":"Servers that generate redirect URLs dynamically without proper encoding. Internationalized domain names or paths with special characters. Proxy servers that mangle the Location header.","solutions":["Fix the server to emit properly encoded, valid URLs in the Location header","Provide the final canonical image URL directly to Glide","Handle the HttpException in a RequestListener and use a fallback image"],"exampleFix":"// before\nGlide.with(context).load(problematicRedirectUrl).into(imageView);\n// after — use the known-good final URL\nGlide.with(context)\n  .load(canonicalImageUrl)\n  .error(R.drawable.placeholder)\n  .into(imageView);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"Glide.with(context)\n  .load(url)\n  .error(R.drawable.placeholder)\n  .listener(new RequestListener<Drawable>() {\n    @Override public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {\n      for (Throwable cause : e.getRootCauses()) {\n        if (cause instanceof HttpException && cause.getMessage().contains(\"Bad redirect url\")) {\n          Log.w(TAG, \"Malformed redirect URL from server for \" + model);\n        }\n      }\n      return false;\n    }\n    @Override public boolean onResourceReady(Drawable r, Object m, Target<Drawable> t, DataSource d, boolean i) { return false; }\n  })\n  .into(imageView);","preventionTips":["Use canonical, properly-encoded image URLs","Fix server-side URL generation to produce valid redirect targets","Handle redirect-related HttpExceptions gracefully with placeholder images"],"tags":["glide","http","redirect","network"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}