java httphandler - sendResponseHeaders:正在使用 HEAD 请求的内容长度调用

java httphandler - sendResponseHeaders: being invoked with a content length for a HEAD request

我目前正在开发一个简单的 HttpHandler 来显示 mp4 视频的内​​容(在 https url 中)。在我的浏览器中它工作正常,一切都按应有的方式显示,但是当我将这个 http url 传递给 javafx mediaplayer 时它给我错误:

Nov 09, 2015 10:02:13 PM sun.net.httpserver.ExchangeImpl sendResponseHeaders
WARNING: sendResponseHeaders: being invoked with a content length for a HEAD request

为什么会出现这个错误? 处理程序代码:

@Override
public void handle(HttpExchange exchange)
        throws IOException
{
    Headers h = exchange.getResponseHeaders();
    h.add("viewport", "width=device-width");
    String res = "<html><body><video controls autoplay name=\"media\"><br><source src=\"https://longurl.mp4\" type=\"video/mp4\"></video></body></html>";
    exchange.sendResponseHeaders(200, res.length());
    System.out.println("ResponseHeaders sent with " + res.length());
    exchange.getResponseBody().write(res.getBytes());
    exchange.getResponseBody().flush();
    exchange.getResponseBody().close();
    System.out.println("Sent data");
}

MediaPlayer 线程:

private void init(String source) //new URL("http://localhost:8000/stream").toURI().toASCIIString()
{
    System.out.println("ttttt T_T");
    Platform.runLater(new Runnable()
    {
        @Override
        public void run()
        {
            media = new Media(source);
            mediaPlayer = new MediaPlayer(media);
            mediaView = new MediaView(mediaPlayer);

            mediaPlayer.setOnReady(new Runnable()
    {
        @Override
        public void run()
        {
            mediaPlayer.play();
        }
    });

            root.getChildren().add(mediaView);
        }
    });
}

控制台输出:

ttttt T_T
Nov 09, 2015 10:02:13 PM sun.net.httpserver.ExchangeImpl sendResponseHeaders
WARNUNG: sendResponseHeaders: being invoked with a content length for a HEAD request
ResponseHeaders sent with 961
ResponseHeaders sent with 961
Sent data
ResponseHeaders sent with 961
Sent data

在早期版本中 Java 不能很好地处理 https url。自 JDK 1.8.0_76 以来已修复此问题。但目前没有 public 版本,只有早期访问版本。