Skip to content

Commit

Permalink
danikula#132: format response headers in US locale to make sure libra…
Browse files Browse the repository at this point in the history
…ry supports any language
  • Loading branch information
danikula committed Apr 21, 2017
1 parent 01bba67 commit 6cd1855
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Locale;

import static com.danikula.videocache.ProxyCacheUtils.DEFAULT_BUFFER_SIZE;

Expand Down Expand Up @@ -65,9 +66,9 @@ private String newResponseHeaders(GetRequest request) throws IOException, ProxyC
return new StringBuilder()
.append(request.partial ? "HTTP/1.1 206 PARTIAL CONTENT\n" : "HTTP/1.1 200 OK\n")
.append("Accept-Ranges: bytes\n")
.append(lengthKnown ? String.format("Content-Length: %d\n", contentLength) : "")
.append(addRange ? String.format("Content-Range: bytes %d-%d/%d\n", request.rangeOffset, length - 1, length) : "")
.append(mimeKnown ? String.format("Content-Type: %s\n", mime) : "")
.append(lengthKnown ? format("Content-Length: %d\n", contentLength) : "")
.append(addRange ? format("Content-Range: bytes %d-%d/%d\n", request.rangeOffset, length - 1, length) : "")
.append(mimeKnown ? format("Content-Type: %s\n", mime) : "")
.append("\n") // headers end
.toString();
}
Expand Down Expand Up @@ -98,6 +99,10 @@ private void responseWithoutCache(OutputStream out, long offset) throws ProxyCac
}
}

private String format(String pattern, Object... args) {
return String.format(Locale.US, pattern, args);
}

@Override
protected void onCachePercentsAvailableChanged(int percents) {
if (listener != null) {
Expand Down

0 comments on commit 6cd1855

Please sign in to comment.