/** * Set a mime mapping * * @param extension the extension * @param type the mime type */ public void addMimeMapping(String extension, String type) { _mimeMap.put(StringUtils.asciiToLowerCase(extension), normalizeMimeType(type)); }
@Override public String getHeader(String name) { if (name == null) return null; return _headers.getValue(StringUtils.asciiToLowerCase(name), 0); }
@Override public String getHeader(String name) { if (name == null) return null; return _headers.getValue(StringUtils.asciiToLowerCase(name), 0); }
public Entry get(String name) { Entry entry = __staticNameMap.get(name); if (entry != null) return entry; return _nameMap.get(StringUtils.asciiToLowerCase(name)); }
public Entry get(String name) { Entry entry = __staticNameMap.get(name); if (entry != null) return entry; return _nameMap.get(StringUtils.asciiToLowerCase(name)); }
/** * Set a mime mapping * * @param extension the extension * @param type the mime type */ public void addMimeMapping(String extension, String type) { _mimeMap.put(StringUtils.asciiToLowerCase(extension), normalizeMimeType(type)); }
/** * @param mimeMap A Map of file extension to mime-type. */ public void setMimeMap(Map<String, String> mimeMap) { _mimeMap.clear(); if (mimeMap != null) { for (Entry<String, String> ext : mimeMap.entrySet()) { _mimeMap.put(StringUtils.asciiToLowerCase(ext.getKey()), normalizeMimeType(ext.getValue())); } } }
@Override public void parsedField(String key, String value) { // Add to headers and mark if one of these fields. // headers.put(StringUtils.asciiToLowerCase(key), value); if (key.equalsIgnoreCase("content-disposition")) contentDisposition = value; else if (key.equalsIgnoreCase("content-type")) contentType = value; // Transfer encoding is not longer considers as it is deprecated as per // https://tools.ietf.org/html/rfc7578#section-4.7 }
@Override public void parsedField(String key, String value) { // Add to headers and mark if one of these fields. // headers.put(StringUtils.asciiToLowerCase(key), value); if (key.equalsIgnoreCase("content-disposition")) contentDisposition = value; else if (key.equalsIgnoreCase("content-type")) contentType = value; // Transfer encoding is not longer considers as it is deprecated as per // https://tools.ietf.org/html/rfc7578#section-4.7 }
/** * @param mimeMap A Map of file extension to mime-type. */ public void setMimeMap(Map<String, String> mimeMap) { _mimeMap.clear(); if (mimeMap != null) { for (Entry<String, String> ext : mimeMap.entrySet()) { _mimeMap.put(StringUtils.asciiToLowerCase(ext.getKey()), normalizeMimeType(ext.getValue())); } } }
/** * Get the MIME type by filename extension. * Lookup only the static default mime map. * * @param filename A file name * @return MIME type matching the longest dot extension of the * file name. */ public static String getDefaultMimeByExtension(String filename) { String type = null; if (filename != null) { int i = -1; while (type == null) { i = filename.indexOf(".", i + 1); if (i < 0 || i >= filename.length()) break; String ext = StringUtils.asciiToLowerCase(filename.substring(i + 1)); type = __dftMimeMap.get(ext); } } if (type == null) { type = __dftMimeMap.get("*"); } return type; }
/** * Get the MIME type by filename extension. * Lookup only the static default mime map. * * @param filename A file name * @return MIME type matching the longest dot extension of the * file name. */ public static String getDefaultMimeByExtension(String filename) { String type = null; if (filename != null) { int i = -1; while (type == null) { i = filename.indexOf(".", i + 1); if (i < 0 || i >= filename.length()) break; String ext = StringUtils.asciiToLowerCase(filename.substring(i + 1)); type = __dftMimeMap.get(ext); } } if (type == null) { type = __dftMimeMap.get("*"); } return type; }
/** * Get the MIME type by filename extension. * Lookup the content and static default mime maps. * * @param filename A file name * @return MIME type matching the longest dot extension of the * file name. */ public String getMimeByExtension(String filename) { String type = null; if (filename != null) { int i = -1; while (type == null) { i = filename.indexOf(".", i + 1); if (i < 0 || i >= filename.length()) break; String ext = StringUtils.asciiToLowerCase(filename.substring(i + 1)); type = _mimeMap.get(ext); if (type == null) type = __dftMimeMap.get(ext); } } if (type == null) { type = _mimeMap.get("*"); if (type == null) { type = __dftMimeMap.get("*"); } } return type; }
/** * Get the MIME type by filename extension. * Lookup the content and static default mime maps. * * @param filename A file name * @return MIME type matching the longest dot extension of the * file name. */ public String getMimeByExtension(String filename) { String type = null; if (filename != null) { int i = -1; while (type == null) { i = filename.indexOf(".", i + 1); if (i < 0 || i >= filename.length()) break; String ext = StringUtils.asciiToLowerCase(filename.substring(i + 1)); type = _mimeMap.get(ext); if (type == null) type = __dftMimeMap.get(ext); } } if (type == null) { type = _mimeMap.get("*"); if (type == null) { type = __dftMimeMap.get("*"); } } return type; }
public Entry add(HttpField field) { Entry entry = new Entry(field); int size = entry.getSize(); if (size > _maxDynamicTableSizeInBytes) { if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] !added size %d>%d", hashCode(), size, _maxDynamicTableSizeInBytes)); _dynamicTable.evictAll(); return null; } _dynamicTableSizeInBytes += size; _dynamicTable.add(entry); _fieldMap.put(field, entry); _nameMap.put(StringUtils.asciiToLowerCase(field.getName()), entry); if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] added %s", hashCode(), entry)); _dynamicTable.evict(); return entry; }
private void evict() { while (_dynamicTableSizeInBytes > _maxDynamicTableSizeInBytes) { Entry entry = _entries[_offset]; _entries[_offset] = null; _offset = (_offset + 1) % _entries.length; _size--; if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] evict %s", HpackContext.this.hashCode(), entry)); _dynamicTableSizeInBytes -= entry.getSize(); entry._slot = -1; _fieldMap.remove(entry.getHttpField()); String lc = StringUtils.asciiToLowerCase(entry.getHttpField().getName()); if (entry == _nameMap.get(lc)) _nameMap.remove(lc); } if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] entries=%d, size=%d, max=%d", HpackContext.this.hashCode(), _dynamicTable.size(), _dynamicTableSizeInBytes, _maxDynamicTableSizeInBytes)); }
public Entry add(HttpField field) { Entry entry = new Entry(field); int size = entry.getSize(); if (size > _maxDynamicTableSizeInBytes) { if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] !added size %d>%d", hashCode(), size, _maxDynamicTableSizeInBytes)); _dynamicTable.evictAll(); return null; } _dynamicTableSizeInBytes += size; _dynamicTable.add(entry); _fieldMap.put(field, entry); _nameMap.put(StringUtils.asciiToLowerCase(field.getName()), entry); if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] added %s", hashCode(), entry)); _dynamicTable.evict(); return entry; }
private void evict() { while (_dynamicTableSizeInBytes > _maxDynamicTableSizeInBytes) { Entry entry = _entries[_offset]; _entries[_offset] = null; _offset = (_offset + 1) % _entries.length; _size--; if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] evict %s", HpackContext.this.hashCode(), entry)); _dynamicTableSizeInBytes -= entry.getSize(); entry._slot = -1; _fieldMap.remove(entry.getHttpField()); String lc = StringUtils.asciiToLowerCase(entry.getHttpField().getName()); if (entry == _nameMap.get(lc)) _nameMap.remove(lc); } if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] entries=%d, size=%d, max=%d", HpackContext.this.hashCode(), _dynamicTable.size(), _dynamicTableSizeInBytes, _maxDynamicTableSizeInBytes)); }
private static String normalizeMimeType(String type) { MimeTypes.Type t = CACHE.get(type); if (t != null) return t.asString(); return StringUtils.asciiToLowerCase(type); }
private static String normalizeMimeType(String type) { MimeTypes.Type t = CACHE.get(type); if (t != null) return t.asString(); return StringUtils.asciiToLowerCase(type); }