/** * Set the content length (in bytes) for this Response. * * @param length The new content length */ public void setContentLength(int length) { if (isCommitted()) return; // Ignore any call from an included servlet if (included) return; if (usingWriter) return; response.setContentLength(length); }
/** * Set internal fields for special header names. * Called from set/addHeader. * Return true if the header is special, no need to set the header. */ private boolean checkSpecialHeader( String name, String value) { // XXX Eliminate redundant fields !!! // ( both header and in special fields ) if( name.equalsIgnoreCase( "Content-Type" ) ) { setContentType( value ); return true; } if( name.equalsIgnoreCase( "Content-Length" ) ) { try { int cL=Integer.parseInt( value ); setContentLength( cL ); return true; } catch( NumberFormatException ex ) { // Do nothing - the spec doesn't have any "throws" // and the user might know what he's doing return false; } } if( name.equalsIgnoreCase( "Content-Language" ) ) { // XXX XXX Need to construct Locale or something else } return false; }
/** * Set internal fields for special header names. * Called from set/addHeader. * Return true if the header is special, no need to set the header. */ private boolean checkSpecialHeader( String name, String value) { // XXX Eliminate redundant fields !!! // ( both header and in special fields ) if( name.equalsIgnoreCase( "Content-Type" ) ) { setContentType( value ); return true; } if( name.equalsIgnoreCase( "Content-Length" ) ) { try { int cL=Integer.parseInt( value ); setContentLength( cL ); return true; } catch( NumberFormatException ex ) { // Do nothing - the spec doesn't have any "throws" // and the user might know what he's doing return false; } } if( name.equalsIgnoreCase( "Content-Language" ) ) { // XXX XXX Need to construct Locale or something else } return false; }
/** * Set internal fields for special header names. * Called from set/addHeader. * Return true if the header is special, no need to set the header. */ private boolean checkSpecialHeader( String name, String value) { // XXX Eliminate redundant fields !!! // ( both header and in special fields ) if("Content-Type".equalsIgnoreCase(name)) { setContentType( value ); return true; } if("Content-Length".equalsIgnoreCase(name)) { try { int cL=Integer.parseInt( value ); setContentLength( cL ); return true; } catch( NumberFormatException ex ) { // Do nothing - the spec doesn't have any "throws" // and the user might know what he's doing return false; } } if("Content-Language".equalsIgnoreCase(name)) { // XXX XXX Need to construct Locale or something else } return false; }
/** * Set the content length (in bytes) for this Response. * * @param length The new content length */ public void setContentLength(int length) { checkResponse(); if (isCommitted()) return; // Ignore any call from an included servlet if (included) return; if (usingWriter) return; response.setContentLength(length); }
/** * Set the content length (in bytes) for this Response. * * @param length The new content length */ public void setContentLength(int length) { checkResponse(); if (isCommitted()) return; // Ignore any call from an included servlet if (included) return; if (usingWriter) return; response.setContentLength(length); }
res.setStatus(404); ByteBuffer bb = HtmlHelper.getErrorPage("Not Found", "HTTP/1.1 404 Not Found\r\n", "Grizzly"); res.setContentLength(bb.limit()); res.setContentType("text/html"); res.flushHeaders();
res.setContentLength((int)resource.length()); res.sendHeaders();
res.setContentLength((int)resource.length()); res.sendHeaders();
/** * 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(); } }
/** * Close the output buffer. This tries to calculate the response size if * the response has not been committed yet. * * @throws IOException An underlying IOException occurred */ public void close() throws IOException { if (closed) return; if (suspended) return; if ((!coyoteResponse.isCommitted()) && (coyoteResponse.getContentLength() == -1)) { // Flushing the char buffer if (state == CHAR_STATE) { cb.flushBuffer(); state = BYTE_STATE; } // If this didn't cause a commit of the response, the final content // length can be calculated if (!coyoteResponse.isCommitted()) { coyoteResponse.setContentLength(bb.getLength()); } } doFlush(false); closed = true; coyoteResponse.finish(); }
/** * Close the output buffer. This tries to calculate the response size if * the response has not been committed yet. * * @throws IOException An underlying IOException occurred */ public void close() throws IOException { if (closed) return; if (suspended) return; if ((!response.isCommitted()) && (response.getContentLength() == -1)) { // Flushing the char buffer if (state == CHAR_STATE) { cb.flushBuffer(); state = BYTE_STATE; } // If this didn't cause a commit of the response, the final content // length can be calculated if (!response.isCommitted()) { response.setContentLength(bb.getLength()); } } doFlush(false); closed = true; response.finish(); }
/** * Close the output buffer. This tries to calculate the response size if * the response has not been committed yet. * * @throws IOException An underlying IOException occurred */ public void close() throws IOException { if (closed) return; if (suspended) return; if ((!coyoteResponse.isCommitted()) && (coyoteResponse.getContentLength() == -1)) { // Flushing the char buffer if (state == CHAR_STATE) { cb.flushBuffer(); state = BYTE_STATE; } // If this didn't cause a commit of the response, the final content // length can be calculated if (!coyoteResponse.isCommitted()) { coyoteResponse.setContentLength(bb.getLength()); } } doFlush(false); closed = true; coyoteResponse.finish(); }
+ " " + messageDropConnection(status) + "\r\n", serverName); response.setContentLength(bb.limit()); response.setContentType("text/html");
response.setContentLength(-1); response.setContentLength(-1); } else { String contentType = response.getContentType();
response.setContentLength(-1); response.setContentLength(-1); } else { String contentType = response.getContentType();