Refine search
context.getMimeTypes().addMimeMapping(extension, mimeType); context.getMetaData().setOrigin("extension."+extension, descriptor); break; context.getMimeTypes().addMimeMapping(extension, mimeType); context.getMetaData().setOrigin("extension."+extension, descriptor); if (!context.getMimeTypes().getMimeByExtension("."+extension).equals(mimeType)) throw new IllegalStateException("Conflicting mime-type "+mimeType+" for extension "+extension+" in "+descriptor.getResource()); break; LOG.warn(new Throwable()); // TODO throw ISE?
Content(String pathInContext,Resource resource) { _key=pathInContext; _resource=resource; _contentType=_mimeTypes.getMimeByExtension(_resource.toString()); boolean exists=resource.exists(); _lastModified=exists?resource.lastModified():-1; _lastModifiedBytes=_lastModified<0?null:new ByteArrayBuffer(HttpFields.formatDate(_lastModified)); _length=exists?(int)resource.length():0; _cachedSize.addAndGet(_length); _cachedFiles.incrementAndGet(); _lastAccessed=System.currentTimeMillis(); _etagBuffer=_etags?new ByteArrayBuffer(resource.getWeakETag()):null; }
if (resource==null || !resource.exists()) if (!_aliases && resource.getAlias()!=null) LOG.info(resource+" aliased to "+resource.getAlias()); return; baseRequest.getResponse().getHttpFields().put(HttpHeaders.ETAG_BUFFER,etag); return; Buffer mime=_mimeTypes.getMimeByExtension(resource.toString()); if (mime==null) mime=_mimeTypes.getMimeByExtension(request.getPathInfo()); response.setDateHeader(HttpHeaders.LAST_MODIFIED,last_modified); if (_etags) baseRequest.getResponse().getHttpFields().put(HttpHeaders.ETAG_BUFFER,etag);
if (sc>0 && (sc<200 || sc==204 || sc==205 || sc>=300)) LOG.debug("{} exclude by status {}",this,sc); noCompression(); _interceptor.write(content, complete, callback); if (ct!=null) ct=MimeTypes.getContentTypeWithoutCharset(ct); if (!_factory.isMimeTypeGzipable(StringUtil.asciiToLowerCase(ct))) LOG.debug("{} exclude by mimeType {}",this,ct); noCompression(); _interceptor.write(content, complete, callback); if (ce != null) LOG.debug("{} exclude by content-encoding {}",this,ce); noCompression(); _interceptor.write(content, complete, callback); fields.add(_vary); String etag=fields.get(HttpHeader.ETAG); if (etag!=null)
if (sc>0 && (sc<200 || sc==204 || sc==205 || sc>=300)) LOG.debug("{} exclude by status {}",this,sc); noCompression(); String response_etag = response.getHttpFields().get(HttpHeader.ETAG); if (request_etags!=null && response_etag!=null) response.getHttpFields().put(HttpHeader.ETAG,response_etag_gzip); if (ct!=null) ct=MimeTypes.getContentTypeWithoutCharset(ct); if (!_factory.isMimeTypeGzipable(StringUtil.asciiToLowerCase(ct))) LOG.debug("{} exclude by mimeType {}",this,ct); noCompression(); _interceptor.write(content, complete, callback); String ce=fields.get(HttpHeader.CONTENT_ENCODING); if (ce != null) LOG.debug("{} exclude by content-encoding {}",this,ce); noCompression(); _interceptor.write(content, complete, callback);
CachedHttpContent(String pathInContext,Resource resource,CachedHttpContent gzipped) { _key=pathInContext; _resource=resource; String contentType = _mimeTypes.getMimeByExtension(_resource.toString()); _contentType=contentType==null?null:new PreEncodedHttpField(HttpHeader.CONTENT_TYPE,contentType); _characterEncoding = _contentType==null?null:MimeTypes.getCharsetFromContentType(contentType); _mimeType = _contentType==null?null:MimeTypes.CACHE.get(MimeTypes.getContentTypeWithoutCharset(contentType)); boolean exists=resource.exists(); _lastModifiedValue=exists?resource.lastModified():-1L; _lastModified=_lastModifiedValue==-1?null :new PreEncodedHttpField(HttpHeader.LAST_MODIFIED,DateGenerator.formatDate(_lastModifiedValue)); _contentLengthValue=exists?(int)resource.length():0; _contentLength=new PreEncodedHttpField(HttpHeader.CONTENT_LENGTH,Long.toString(_contentLengthValue)); if (_cachedFiles.incrementAndGet()>_maxCachedFiles) shrinkCache(); _lastAccessed=System.currentTimeMillis(); _etag=ResourceCache.this._etags?new PreEncodedHttpField(HttpHeader.ETAG,resource.getWeakETag()):null; _gzipped=gzipped==null?null:new CachedGzipHttpContent(this,gzipped); }
private HttpContent load(String pathInContext, Resource resource) throws IOException { Content content=null; if (resource==null || !resource.exists()) return null; // Will it fit in the cache? if (!resource.isDirectory() && isCacheable(resource)) { // Create the Content (to increment the cache sizes before adding the content content = new Content(pathInContext,resource); // reduce the cache to an acceptable size. shrinkCache(); // Add it to the cache. Content added = _cache.putIfAbsent(pathInContext,content); if (added!=null) { content.invalidate(); content=added; } return content; } return new HttpContent.ResourceAsHttpContent(resource,_mimeTypes.getMimeByExtension(resource.toString()),getMaxCachedFileSize(),_etags); }
private HttpContent load(String pathInContext, Resource resource, int maxBufferSize) throws IOException { if (resource==null || !resource.exists()) return null; if (resource.isDirectory()) return new ResourceHttpContent(resource,_mimeTypes.getMimeByExtension(resource.toString()),maxBufferSize); // Look for a gzip resource or content String mt = _mimeTypes.getMimeByExtension(pathInContext); if (_gzip) { // Is there a gzip resource? String pathInContextGz=pathInContext+".gz"; Resource resourceGz=_factory.getResource(pathInContextGz); if (resourceGz.exists() && resourceGz.lastModified()>=resource.lastModified() && resourceGz.length()<resource.length()) return new ResourceHttpContent(resource,mt,maxBufferSize, new ResourceHttpContent(resourceGz,_mimeTypes.getMimeByExtension(pathInContextGz),maxBufferSize)); } return new ResourceHttpContent(resource,mt,maxBufferSize); }
@Override public void write(ByteBuffer content, boolean last, Callback callback) if (LOG.isDebugEnabled()) LOG.debug("{} write last={} {}",this,last,BufferUtil.toDetailString(content)); else ct=MimeTypes.getContentTypeWithoutCharset(ct); _aggregating=isMimeTypeBufferable(StringUtil.asciiToLowerCase(ct)); _buffers.add(content); if (LOG.isDebugEnabled()) LOG.debug("{} committing {}",this,_buffers.size()); commit(_buffers,callback);
@Override public void headerComplete() throws IOException { _contentType = _fields.get(HttpHeaders.CONTENT_TYPE_BUFFER); if(_contentType!=null) { String charset = MimeTypes.getCharsetFromContentType(_contentType); if(charset!=null) _charset = charset; } }
_mimeType = null; _contentType = null; _fields.remove(HttpHeader.CONTENT_TYPE); charset = _mimeType.getCharset().toString(); else charset = MimeTypes.getCharsetFromContentType(contentType); _contentType = MimeTypes.getContentTypeWithoutCharset(_contentType); if (_characterEncoding != null) _contentType = _contentType + ";charset=" + _characterEncoding; _fields.put(field); else _fields.put(HttpHeader.CONTENT_TYPE, _contentType);
LOG.debug("{} handle {} in {}",this,baseRequest,context); LOG.debug("{} already intercepting {}",this,request); _handler.handle(target,baseRequest, request, response); return; LOG.debug("{} excluded by method {}",this,request); _handler.handle(target,baseRequest, request, response); return; String mimeType = context==null?MimeTypes.getDefaultMimeByExtension(path):context.getMimeType(path); if (mimeType!=null) mimeType = MimeTypes.getContentTypeWithoutCharset(mimeType); if (!isMimeTypeBufferable(mimeType))
if (_contentType != null) _contentType = MimeTypes.getContentTypeWithoutCharset(_contentType); HttpField field = HttpField.CONTENT_TYPE.get(_contentType); if (field!=null) _fields.put(field); else _fields.put(HttpHeader.CONTENT_TYPE, _contentType); if (_contentType != null) _contentType = MimeTypes.getContentTypeWithoutCharset(_contentType) + ";charset=" + _characterEncoding; HttpField field = HttpField.CONTENT_TYPE.get(_contentType); if (field!=null) _fields.put(field); else _fields.put(HttpHeader.CONTENT_TYPE, _contentType);
/** Add the RDF MIME Type mappins */ public static void setMimeTypes(ServletContextHandler context) { MimeTypes mimeTypes = new MimeTypes(); // RDF syntax mimeTypes.addMimeMapping("nt", WebContent.contentTypeNTriples); mimeTypes.addMimeMapping("nq", WebContent.contentTypeNQuads); mimeTypes.addMimeMapping("ttl", WebContent.contentTypeTurtle+";charset=utf-8"); mimeTypes.addMimeMapping("trig", WebContent.contentTypeTriG+";charset=utf-8"); mimeTypes.addMimeMapping("rdf", WebContent.contentTypeRDFXML); mimeTypes.addMimeMapping("jsonld", WebContent.contentTypeJSONLD); mimeTypes.addMimeMapping("rj", WebContent.contentTypeRDFJSON); mimeTypes.addMimeMapping("rt", WebContent.contentTypeRDFThrift); mimeTypes.addMimeMapping("trdf", WebContent.contentTypeRDFThrift); // SPARQL syntax mimeTypes.addMimeMapping("rq", WebContent.contentTypeSPARQLQuery); mimeTypes.addMimeMapping("ru", WebContent.contentTypeSPARQLUpdate); // SPARQL Result set mimeTypes.addMimeMapping("rsj", WebContent.contentTypeResultsJSON); mimeTypes.addMimeMapping("rsx", WebContent.contentTypeResultsXML); mimeTypes.addMimeMapping("srt", WebContent.contentTypeResultsThrift); // Other mimeTypes.addMimeMapping("txt", WebContent.contentTypeTextPlain); mimeTypes.addMimeMapping("csv", WebContent.contentTypeTextCSV); mimeTypes.addMimeMapping("tsv", WebContent.contentTypeTextTSV); context.setMimeTypes(mimeTypes); }
@Override public String getMimeType(String file) { if (_mimeTypes == null) return null; return _mimeTypes.getMimeByExtension(file); }
public void setContentType(String value) { _contentType = MimeTypes.CACHE.lookup(value); _charset = MimeTypes.getCharsetFromContentType(_contentType); _fields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); }
/** * @return Returns the mimeTypes. */ public MimeTypes getMimeTypes() { if (_mimeTypes == null) _mimeTypes = new MimeTypes(); return _mimeTypes; }
_fields.put(lm); _fields.put(content.getContentLength()); _contentLength=content.getContentLengthValue(); _fields.putLongField(HttpHeader.CONTENT_LENGTH,contentLength); _contentLength=contentLength; __explicitCharset.contains(_encodingFrom)) setContentType(MimeTypes.getContentTypeWithoutCharset(content.getContentTypeValue()));
/** * Set a mime mapping. * * @param extension Extension * @param type Mime type */ public void addMimeMapping(String extension, String type) { handler.getMimeTypes().addMimeMapping(extension, type); }