public long getRequestBytesSent() { return req.getResponse().getBytesWritten(); }
public long getRequestBytesSent() { return req.getResponse().getBytesWritten(); }
public long getRequestBytesSent() { return req.getResponse().getBytesWritten(); }
@Override protected void sendCache(Request request, FileCacheEntry entry) throws IOException { boolean flushBody = checkIfHeaders(request, entry); request.getResponse().sendHeaders(); if (flushBody) { SSLOutputWriter.flushChannel(request.getResponse().getChannel(), entry.bb.slice()); } } }
public HandShake handshake(WebSocketApplication app, Request request) { final HandShake handshake = createHandShake(request); handshake.respond(app, request.getResponse()); return handshake; }
/** * Send the cached resource. */ protected void sendCache(Request request, FileCacheEntry entry) throws IOException{ boolean flushBody = checkIfHeaders(request, entry); request.getResponse().setContentType(entry.contentType); request.getResponse().setContentLength(Integer.valueOf(entry.contentLength)); if (flushBody) { ByteBuffer sliced = entry.bb.slice(); ByteBuffer ob = ((SocketChannelOutputBuffer)request.getResponse() .getOutputBuffer()).getOutputByteBuffer(); int left = ob.remaining(); // It's better to execute a byte copy than two network operation. if (left > sliced.limit()){ request.getResponse().action(ActionCode.ACTION_COMMIT, null); ob.put(sliced); ((SocketChannelOutputBuffer)request.getResponse() .getOutputBuffer()).flushBuffer(); } else { request.getResponse().flush(); OutputWriter.flushChannel(request.getResponse().getChannel(),sliced); } } else { request.getResponse().flush(); } }
/** * Check if the if-unmodified-since condition is satisfied. * * @return boolean true if the resource meets the specified condition, * and false if the condition is not satisfied, in which case request * processing is stopped */ protected boolean checkIfUnmodifiedSince(Request request, FileCacheEntry entry) throws IOException { try { Response response = request.getResponse(); long lastModified = Long.parseLong(entry.lastModified); String h = request.getHeader("If-Unmodified-Since"); long headerValue = (h == null? -1: Long.parseLong(h)); if (headerValue != -1) { if ( lastModified >= (headerValue + 1000)) { // The entity has not been modified since the date // specified by the client. This is not an error case. response.setStatus(SC_PRECONDITION_FAILED); return false; } } } catch(IllegalArgumentException illegalArgument) { return true; } return true; }
throws IOException { Response response = request.getResponse(); String eTag = getETag(entry); String headerValue = request.getHeader("If-Match");
/** * Read some bytes. */ public int doRead(ByteChunk chunk, Request req) throws IOException { if (request.getResponse().isSuspended()){ request.action(ActionCode.RESET_SUSPEND_TIMEOUT, null); } if (lastActiveFilter == -1) return inputStreamInputBuffer.doRead(chunk, req); else return activeFilters[lastActiveFilter].doRead(chunk,req); }
/** * Read some bytes. */ public int doRead(ByteChunk chunk, Request req) throws IOException { if (request.getResponse().isSuspended()){ request.action(ActionCode.RESET_SUSPEND_TIMEOUT, null); } if (lastActiveFilter == -1) return inputStreamInputBuffer.doRead(chunk, req); else return activeFilters[lastActiveFilter].doRead(chunk,req); }
throws IOException { Response response = request.getResponse(); String eTag = getETag(entry); String headerValue = request.getHeader("If-None-Match");
throws IOException { try { Response response = request.getResponse(); String h = request.getHeader("If-Modified-Since"); long headerValue = (h == null ? -1: Long.parseLong(h));
/** * Intercept the request and decide if we cache the static resource. If the * static resource is already cached, return it. */ public int handle(Request req, int handlerCode) throws IOException{ if (fileCache == null) { return Interceptor.CONTINUE; } if (handlerCode == Interceptor.RESPONSE_PROCEEDED && fileCache.isEnabled()){ String docroot = SelectorThread.getSelector( socketChannel.socket().getLocalAddress(), socketChannel.socket().getLocalPort()).getWebAppRootPath(); String uri = req.requestURI().toString(); fileCache.add(FileCache.DEFAULT_SERVLET_NAME,docroot, uri, req.serverName().toString(), req.getResponse().getMimeHeaders(), false); } else if (handlerCode == Interceptor.REQUEST_LINE_PARSED) { if (fileCache.sendCache(req)){ return Interceptor.BREAK; } } return Interceptor.CONTINUE; }
bytesSent=req.getResponse().getBytesWritten(); int responseStatus = req.getResponse().getStatus();
bytesSent+=req.getResponse().getBytesWritten(); int responseStatus = req.getResponse().getStatus();
bytesSent+=req.getResponse().getBytesWritten(); int responseStatus = req.getResponse().getStatus();
uri, req.serverName().toString(), req.getResponse().getMimeHeaders(), false); } else { uri, req.serverName().toString(), req.getResponse().getMimeHeaders(), false);
if (protocolHandler == null) { try { handleUnsupportedVersion(request.getResponse()); return true; } catch (IOException ignored) { app, request, request.getResponse(), protocolHandler, mapper); protocolHandler.setNetworkHandler(handler); protocolHandler.setKey(key);
/** * Intercept the request and decide if we cache the static resource. If the * static resource is already cached, return it. */ public int handle(Request req, int handlerCode) throws IOException{ if (fileCache == null) return Interceptor.CONTINUE; if (handlerCode == Interceptor.RESPONSE_PROCEEDED && fileCache.isEnabled()){ String docroot = SelectorThread.getWebAppRootPath(); MessageBytes mb = req.requestURI(); String uri = req.requestURI().toString(); fileCache.add(FileCache.DEFAULT_SERVLET_NAME,docroot,uri, req.getResponse().getMimeHeaders(),false); } else if (handlerCode == Interceptor.REQUEST_LINE_PARSED) { ByteChunk requestURI = req.requestURI().getByteChunk(); if (fileCache.sendCache(requestURI.getBytes(), requestURI.getStart(), requestURI.getLength(), socketChannel, keepAlive(req))){ return Interceptor.BREAK; } } return Interceptor.CONTINUE; }