io.vertx.core.http.impl.MimeMapping Java Examples

The following examples show how to use io.vertx.core.http.impl.MimeMapping. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AssetServingEndpoint.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
@Override
public Handler<RoutingContext> handler() {
    return rc -> {
        String path = rc.request().path();
        path = path.substring(8);   //Remove "/assets/", which is 8 characters
        String mime;
        String newPath;
        if (path.contains("webjars")) {
            newPath = "META-INF/resources/" + path.substring(path.indexOf("webjars"));
        } else {
            newPath = fileAssetPath + (path.startsWith("/") ? path.substring(1) : path);
        }
        mime = MimeMapping.getMimeTypeForFilename(FilenameUtils.getName(newPath));

        //System.out.println("PATH: " + path + " - mime = " + mime);
        rc.response()
                .putHeader("content-type", mime)
                .sendFile(newPath);
    };
}
 
Example #2
Source File: RoutingContext.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Set Content-Disposition get to "attachment" with optional {@code filename} mime type.
 *
 * @param filename the filename for the attachment
 */
@Fluent
default RoutingContext attachment(String filename) {
  if (filename != null) {
    String contentType = MimeMapping.getMimeTypeForFilename(filename);

    if (contentType != null) {
      response()
        .putHeader(HttpHeaders.CONTENT_TYPE, contentType);
    }

  }

  response()
    .putHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename);

  return this;
}
 
Example #3
Source File: StartupContext.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Override
public String getMimeType(String file) {
    return MimeMapping.getMimeTypeForFilename(file);
}
 
Example #4
Source File: VertxVaadinService.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Override
public String getMimeType(String resourceName) {
    return MimeMapping.getMimeTypeForFilename(resourceName);
}