diff --git a/src/com/facebook/buck/artifact_cache/ArtifactCaches.java b/src/com/facebook/buck/artifact_cache/ArtifactCaches.java index 05b351c3911..7292867640f 100644 --- a/src/com/facebook/buck/artifact_cache/ArtifactCaches.java +++ b/src/com/facebook/buck/artifact_cache/ArtifactCaches.java @@ -28,6 +28,7 @@ import com.facebook.buck.timing.DefaultClock; import com.facebook.buck.util.AsyncCloseable; import com.facebook.buck.util.HumanReadableException; +import com.google.common.base.CharMatcher; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -299,8 +300,9 @@ private static ArtifactCache createHttpArtifactCache( storeClientBuilder.networkInterceptors().add( chain -> chain.proceed( chain.request().newBuilder() - .addHeader("X-BuckCache-User", System.getProperty("user.name", "")) - .addHeader("X-BuckCache-Host", hostToReportToRemote) + .addHeader("X-BuckCache-User", + stripNonAscii(System.getProperty("user.name", ""))) + .addHeader("X-BuckCache-Host", stripNonAscii(hostToReportToRemote)) .build())); int timeoutSeconds = cacheDescription.getTimeoutSeconds(); setTimeouts(storeClientBuilder, timeoutSeconds); @@ -390,6 +392,17 @@ private static ArtifactCache createHttpArtifactCache( .build()); } + private static String stripNonAscii(String str) { + if (CharMatcher.ASCII.matchesAllOf(str)) { + return str; + } + StringBuilder builder = new StringBuilder(); + for (char c : str.toCharArray()) { + builder.append(CharMatcher.ASCII.matches(c) ? c : '?'); + } + return builder.toString(); + } + private static OkHttpClient.Builder setTimeouts( OkHttpClient.Builder builder, int timeoutSeconds) {