Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to add personal header #46

Closed
Puliyo opened this issue Dec 28, 2015 · 1 comment
Closed

Ability to add personal header #46

Puliyo opened this issue Dec 28, 2015 · 1 comment

Comments

@Puliyo
Copy link

Puliyo commented Dec 28, 2015

It will be great if there's an ability to add user defined header.

private String newResponseHeaders(GetRequest request) throws IOException, ProxyCacheException {
        String mime = source.getMime();
        boolean mimeKnown = !TextUtils.isEmpty(mime);
        int length = cache.isCompleted() ? cache.available() : source.length();
        boolean lengthKnown = length >= 0;
        long contentLength = request.partial ? length - request.rangeOffset : length;
        boolean addRange = lengthKnown && request.partial;
        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("\n") // headers end
                .toString();
    }

Something like this:

private String newResponseHeaders(GetRequest request, HashMap<String, String> headers) {
      StringBuilder _headers = new StringBuilder(newResponseHeaders(request));
      for (Map.Entry<String, String> entry : map.entrySet()) {
            _headers.append(String.format("%s: %s\n", entry.getKey(), entry.getValue()));
      }
      return _headers.toString();
}
@danikula
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants