/** * Extract the mime part from an Http Content-Type header */ public static String extractMimePart(String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException("No Content-Type specified."); } contentType = contentType.trim(); int separator = contentType.indexOf(';'); if (separator != -1) { contentType = contentType.substring(0, separator); } return contentType.trim().toLowerCase(); }
/** * Extract the mime part from an Http Content-Type header */ public static String extractMimePart(String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException("No Content-Type specified."); } contentType = contentType.trim(); int separator = contentType.indexOf(';'); if (separator != -1) { contentType = contentType.substring(0, separator); } return contentType.trim().toLowerCase(); }
/** * Extract the mime part from an Http Content-Type header */ public static String extractMimePart(String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException("No Content-Type specified."); } contentType = contentType.trim(); int separator = contentType.indexOf(';'); if (separator != -1) { contentType = contentType.substring(0, separator); } return contentType.trim().toLowerCase(); }
public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); }
public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); }
public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (StringUtils.isEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + StringUtils.join(allowedContentTypes, ", ") + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + StringUtils.join(allowedContentTypes, ", ") + " is required"); }
public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); }
public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (StringUtils.isEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + StringUtils.join(allowedContentTypes, ", ") + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + StringUtils.join(allowedContentTypes, ", ") + " is required"); }