@Override protected SelectChannelEndPoint newEndPoint( SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException { // We're connected, cancel the connect timeout Timeout.Task connectTimeout = _connectingChannels.remove(channel); if (connectTimeout != null) connectTimeout.cancel(); if (LOG.isDebugEnabled()) LOG.debug("Channels with connection pending: {}", _connectingChannels.size()); // key should have destination at this point (will be replaced by endpoint after this call) HttpDestination dest = (HttpDestination) key.attachment(); SelectChannelEndPoint scep = new SelectChannelEndPoint(channel, selectSet, key, (int) _httpClient.getIdleTimeout()); AsyncEndPoint ep = scep; if (dest.isSecure()) { LOG.debug("secure to {}, proxied={}", channel, dest.isProxied()); ep = new UpgradableEndPoint(ep, newSslEngine(channel)); } AsyncConnection connection = selectSet.getManager().newConnection(channel, ep, key.attachment()); ep.setConnection(connection); AbstractHttpConnection httpConnection = (AbstractHttpConnection) connection; httpConnection.setDestination(dest); if (dest.isSecure() && !dest.isProxied()) ((UpgradableEndPoint) ep).upgrade(); dest.onNewConnection(httpConnection); return scep; }
public void upgrade() { AsyncHttpConnection connection = (AsyncHttpConnection) _endp.getConnection(); SslConnection sslConnection = new SslConnection(_engine, _endp); _endp.setConnection(sslConnection); _endp = sslConnection.getSslEndPoint(); sslConnection.getSslEndPoint().setConnection(connection); LOG.debug("upgrade {} to {} for {}", this, sslConnection, connection); }
/* * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#content(int, org.eclipse.io.Buffer) */ @Override public void content(Buffer ref) throws IOException { if (_endp instanceof AsyncEndPoint) ((AsyncEndPoint) _endp).scheduleIdle(); if (_delayedHandling) { _delayedHandling = false; handleRequest(); } }
/* * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#headerComplete() */ @Override public void headerComplete() throws IOException { if (_endp instanceof AsyncEndPoint) ((AsyncEndPoint) _endp).scheduleIdle(); _requests++; _generator.setVersion(_version); switch (_version) { case HttpVersions.HTTP_0_9_ORDINAL: break; case HttpVersions.HTTP_1_0_ORDINAL: _generator.setHead(_head); if (_server.getSendDateHeader()) _generator.setDate(_request.getTimeStampBuffer()); break; case HttpVersions.HTTP_1_1_ORDINAL: _generator.setHead(_head); if (_server.getSendDateHeader()) _generator.setDate(_request.getTimeStampBuffer()); if (!_host) { _generator.setResponse(HttpStatus.BAD_REQUEST_400, null); _responseFields.put(HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.CLOSE_BUFFER); _generator.completeHeader(_responseFields, true); _generator.complete(); return; } if (_expect) { _generator.setResponse(HttpStatus.EXPECTATION_FAILED_417, null); _responseFields.put(HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.CLOSE_BUFFER); _generator.completeHeader(_responseFields, true); _generator.complete(); return; } break; default: } if (_charset != null) _request.setCharacterEncodingUnchecked(_charset); // Either handle now or wait for first content if ((((HttpParser) _parser).getContentLength() <= 0 && !((HttpParser) _parser).isChunking()) || _expect100Continue) handleRequest(); else _delayedHandling = true; }
public boolean isCheckForIdle() { return _endp.isCheckForIdle(); }
public void onIdleExpired(long idleForMs) { _endp.onIdleExpired(idleForMs); }
public int getMaxIdleTime() { return _endp.getMaxIdleTime(); }
public Object getTransport() { return _endp.getTransport(); }
public boolean blockWritable(long millisecs) throws IOException { return _endp.blockWritable(millisecs); }
public int getRemotePort() { return _endp.getRemotePort(); }
public boolean hasProgressed() { return _endp.hasProgressed(); }
public boolean isWritable() { return _endp.isWritable(); }
public int fill(Buffer buffer) throws IOException { return _endp.fill(buffer); }
public void close() throws IOException { _endp.close(); }
public boolean isInputShutdown() { return _endp.isInputShutdown(); }
public String getRemoteAddr() { return _endp.getRemoteAddr(); }
public String getRemoteHost() { return _endp.getRemoteHost(); }
public int flush(Buffer buffer) throws IOException { return _endp.flush(buffer); }
public boolean isBlocking() { return _endp.isBlocking(); }
public void scheduleTimeout(Task task, long timeoutMs) { _endp.scheduleTimeout(task, timeoutMs); }
public boolean isOpen() { return _endp.isOpen(); }
public void cancelTimeout(Task task) { _endp.cancelTimeout(task); }
public void flush() throws IOException { _endp.flush(); }
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException { return _endp.flush(header, buffer, trailer); }
public void setMaxIdleTime(int timeMs) throws IOException { _endp.setMaxIdleTime(timeMs); }
public String getLocalAddr() { return _endp.getLocalAddr(); }
public void setCheckForIdle(boolean check) { _endp.setCheckForIdle(check); }
public String getLocalHost() { return _endp.getLocalHost(); }
public String toString() { return "Upgradable:" + _endp.toString(); }
public int getLocalPort() { return _endp.getLocalPort(); }