0
我有2个服务器,其中一个是公开的,另一个是我的用户隐藏的。首先可以看到本地网络中的第二个,但用户无法访问公共网络上的第二台计算机。重定向到Java中隐藏的URL
我想将一些URL(具有特定模式)从公共计算机重定向到隐藏。隐藏的URL可能会返回响应中的任何标题。
目前我通过重定向流实现此功能,但问题是(最终用户/客户端)的响应没有全部头文件。
隐藏回应:重定向数据流后
Accept-Ranges: bytes
Connection: keep-alive
Content-Disposition: filename="0.jpg"
Content-Length: 38903
Content-Range: bytes 0-38902/38903
Content-Type: image/jpeg;charset=UTF-8
Date: Thu, 28 Apr 2016 05:11:48 GMT
Last-Modified: Mon, 25 Apr 2016 06:28:17 GMT
Server: Apache-Coyote/1.1
响应:
Connection: keep-alive
Content-Length: 38903
Date: Thu, 28 Apr 2016 05:14:06 GMT
Server: Apache-Coyote/1.1
我的代码是什么链接这样的:
private void redirectGalleyStream(long diskId, String code, HttpServletResponse response)
throws IOException {
final InputStream is = new URL(Settings.i().getVodServer() + "/downloadGalleryImage" +
"?diskId=" + diskId + "&code=" + code).openStream();
fastCopy(is, response.getOutputStream());
}
public static void fastCopy(final InputStream src, final OutputStream dest) throws IOException {
try {
final ReadableByteChannel inputChannel = Channels.newChannel(src);
final WritableByteChannel outputChannel = Channels.newChannel(dest);
fastCopy(inputChannel, outputChannel);
} finally {
try {
src.close();
} catch (Exception ignored) {
}
try {
dest.close();
} catch (Exception ignored) {
}
}
}
public static void fastCopy(final ReadableByteChannel src, final WritableByteChannel dest) throws IOException {
try {
final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
while (src.read(buffer) != -1) {
buffer.flip();
dest.write(buffer);
buffer.compact();
}
buffer.flip();
while (buffer.hasRemaining()) {
dest.write(buffer);
}
} finally {
try {
src.close();
} catch (Exception ignored) {
}
try {
dest.close();
} catch (Exception ignored) {
}
}
}
我怎么可以在客户端的所有头?