/** * 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 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; }
response.setContentType(type);
response.setContentType(type);
response.setContentType(type);
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();
String ct= MimeType.get(ext); if( ct!=null) { res.setContentType(ct); res.setContentType(MimeType.get("html"));
String ct = MimeType.get(ext, defaultContentType); if (ct != null) { res.setContentType(ct); res.setContentType(defaultContentType);
String ct= MimeType.get(ext); if( ct!=null) { res.setContentType(ct); res.setContentType(MimeType.get("html"));
String ct= MimeType.get(ext); if( ct!=null) { res.setContentType(ct); res.setContentType(MimeType.get("html"));
/** * 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(); } }
serverName); response.setContentLength(bb.limit()); response.setContentType("text/html");