@Test public void shouldBePythonFileWhenUsingSheBang() throws IOException { String contentType = underTest.determineContentType(true, () -> getClass().getResourceAsStream("conanfile.py"), MimeRulesSource.NOOP, "something/conanfile.py", "text/x-python"); assertThat(contentType, is("text/x-python")); }
@Nonnull @Override public String determineContentType(final boolean strictContentTypeValidation, final Supplier<InputStream> contentSupplier, @Nullable final MimeRulesSource mimeRulesSource, @Nullable final String contentName, @Nullable final String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".tgz")) { return ContentTypes.APPLICATION_GZIP; } else if (contentName.endsWith("/conanfile.py")) { return X_PYTHON; } else if (ConanFacetUtils.isPackageSnapshot(contentName)) { return ContentTypes.APPLICATION_JSON; } else if (ConanFacetUtils.isDigest(contentName)) { return ContentTypes.APPLICATION_JSON; } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); }
ConanContentValidator implements ContentValidator { @Nonnull @Override public String determineContentType(final boolean strictContentTypeValidation, final Supplier<InputStream> contentSupplier, @Nullable final MimeRulesSource mimeRulesSource, @Nullable final String contentName, @Nullable final String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".tgz")) { return ContentTypes.APPLICATION_GZIP; } else if (contentName.endsWith("/conanfile.py")) { return X_PYTHON; } else if (ConanFacetUtils.isPackageSnapshot(contentName)) { return ContentTypes.APPLICATION_JSON; } else if (ConanFacetUtils.isDigest(contentName)) { return ContentTypes.APPLICATION_JSON; } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); } }
ConanContentValidator implements ContentValidator { @Nonnull @Override public String determineContentType(final boolean strictContentTypeValidation, final Supplier<InputStream> contentSupplier, @Nullable final MimeRulesSource mimeRulesSource, @Nullable final String contentName, @Nullable final String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".tgz")) { return ContentTypes.APPLICATION_GZIP; } else if (contentName.endsWith("/conanfile.py")) { return X_PYTHON; } else if (ConanFacetUtils.isPackageSnapshot(contentName)) { return ContentTypes.APPLICATION_JSON; } else if (ConanFacetUtils.isDigest(contentName)) { return ContentTypes.APPLICATION_JSON; } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); } @Inject  ConanContentValidator(final DefaultContentValidator defaultContentValidator); }
ConanContentValidator implements ContentValidator { @Nonnull @Override public String determineContentType(final boolean strictContentTypeValidation, final Supplier<InputStream> contentSupplier, @Nullable final MimeRulesSource mimeRulesSource, @Nullable final String contentName, @Nullable final String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".tgz")) { return ContentTypes.APPLICATION_GZIP; } else if (contentName.endsWith("/conanfile.py")) { return X_PYTHON; } else if (ConanFacetUtils.isPackageSnapshot(contentName)) { return ContentTypes.APPLICATION_JSON; } else if (ConanFacetUtils.isDigest(contentName)) { return ContentTypes.APPLICATION_JSON; } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); } @Inject  ConanContentValidator(final DefaultContentValidator defaultContentValidator); @Nonnull @Override String determineContentType(final boolean strictContentTypeValidation,
                                     final Supplier<InputStream> contentSupplier,
                                     @Nullable final MimeRulesSource mimeRulesSource,
                                     @Nullable final String contentName,
                                     @Nullable final String declaredContentType); }
ConanContentValidator implements ContentValidator { @Nonnull @Override public String determineContentType(final boolean strictContentTypeValidation, final Supplier<InputStream> contentSupplier, @Nullable final MimeRulesSource mimeRulesSource, @Nullable final String contentName, @Nullable final String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".tgz")) { return ContentTypes.APPLICATION_GZIP; } else if (contentName.endsWith("/conanfile.py")) { return X_PYTHON; } else if (ConanFacetUtils.isPackageSnapshot(contentName)) { return ContentTypes.APPLICATION_JSON; } else if (ConanFacetUtils.isDigest(contentName)) { return ContentTypes.APPLICATION_JSON; } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); } @Inject  ConanContentValidator(final DefaultContentValidator defaultContentValidator); @Nonnull @Override String determineContentType(final boolean strictContentTypeValidation,
                                     final Supplier<InputStream> contentSupplier,
                                     @Nullable final MimeRulesSource mimeRulesSource,
                                     @Nullable final String contentName,
                                     @Nullable final String declaredContentType);  }