protected void write(ByteBuffer content, boolean complete, Callback callback) { if (_firstByteTimeStamp == -1) { long minDataRate = getHttpChannel().getHttpConfiguration().getMinResponseDataRate(); if (minDataRate > 0) _firstByteTimeStamp = System.nanoTime(); else _firstByteTimeStamp = Long.MAX_VALUE; } _interceptor.write(content, complete, callback); }
private Socket socket() { HttpChannel httpChannel = response.getHttpOutput().getHttpChannel(); ChannelEndPoint ep = (ChannelEndPoint) httpChannel.getEndPoint(); return ((SocketChannel) ep.getChannel()).socket(); }
public static Socket getTlsSocket(Response response) { HttpChannel httpChannel = response.getHttpOutput().getHttpChannel(); SslConnection.DecryptedEndPoint sslEndpoint = (SslConnection.DecryptedEndPoint) httpChannel.getEndPoint(); Object endpoint = sslEndpoint.getSslConnection().getEndPoint(); try { return (Socket) endpoint.getClass().getMethod("getSocket").invoke(endpoint); } catch (Exception e) { return throwUnchecked(e, Socket.class); } }
@Override protected long getIdleTimeout() { long bto = getHttpChannel().getHttpConfiguration().getBlockingTimeout(); if (bto>0) return bto; if (bto<0) return -1; return _channel.getIdleTimeout(); } };
/** * <p>Invoked when bytes have been flushed to the network.</p> * <p>The number of flushed bytes may be different from the bytes written * by the application if an {@link Interceptor} changed them, for example * by compressing them.</p> * * @param bytes the number of bytes flushed * @throws IOException if the minimum data rate, when set, is not respected * @see org.eclipse.jetty.io.WriteFlusher.Listener */ public void onFlushed(long bytes) throws IOException { if (_firstByteTimeStamp == -1 || _firstByteTimeStamp == Long.MAX_VALUE) return; long minDataRate = getHttpChannel().getHttpConfiguration().getMinResponseDataRate(); _flushed += bytes; long elapsed = System.nanoTime() - _firstByteTimeStamp; long minFlushed = minDataRate * TimeUnit.NANOSECONDS.toMillis(elapsed) / TimeUnit.SECONDS.toMillis(1); if (LOG.isDebugEnabled()) LOG.debug("Flushed bytes min/actual {}/{}", minFlushed, _flushed); if (_flushed < minFlushed) throw new IOException(String.format("Response content data rate < %d B/s", minDataRate)); }
private void writeGarbageThenCloseSocket() { response.getHttpOutput().getHttpChannel().getEndPoint().write(new Callback() { @Override public void succeeded() { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } @Override public void failed(Throwable x) { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } }, BufferUtil.toBuffer(GARBAGE)); }