001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.jboot.app; 017 018import io.undertow.servlet.api.DeploymentInfo; 019import io.undertow.servlet.api.MimeMapping; 020 021import java.util.HashMap; 022import java.util.Map; 023 024/** 025 * @author michael yang (fuhai999@gmail.com) 026 * @Date: 2019/12/3 027 */ 028public class HttpContentTypes { 029 030 private static Map<String, String> mappings = new HashMap<>(); 031 032 static { 033 034 /** 035 * 视频相关 036 */ 037 mappings.put("asf", "video/x-ms-asf"); 038 mappings.put("asx", "video/x-ms-asf"); 039 mappings.put("avi", "video/avi"); 040 mappings.put("flv", "video/x-flv"); 041 mappings.put("mp4", "video/mp4"); 042 mappings.put("mpeg", "video/mpeg"); 043 mappings.put("mps", "video/x-mpeg"); 044 mappings.put("mpv", "video/mpg"); 045 mappings.put("mov", "video/quicktime"); 046 mappings.put("mpa", "video/x-mpg"); 047 mappings.put("mpe", "video/x-mpg"); 048 mappings.put("m4e", "video/mpeg4"); 049 mappings.put("m2v", "video/x-mpeg"); 050 mappings.put("wmv", "video/x-ms-wmv"); 051 mappings.put("3gp", "video/3gpp"); 052 mappings.put("ts", "video/MP2T"); 053 054 055 /** 056 * 音频相关 057 */ 058 mappings.put("mp3", "audio/mpeg"); 059 mappings.put("mp2", "audio/mp2"); 060 mappings.put("m3u", "audio/x-mpegurl"); 061 mappings.put("m3u8", "audio/x-mpegurl"); 062 mappings.put("mpga", "audio/rn-mpeg"); 063 mappings.put("ra", "audio/vnd.rn-realaudio"); 064 mappings.put("ram", "audio/x-pn-realaudio"); 065 mappings.put("wav", "audio/wav"); 066 mappings.put("wax", "audio/x-ms-wax"); 067 mappings.put("wma", "audio/x-ms-wma"); 068 069 /** 070 * 文档相关 071 */ 072 mappings.put("pdf", "application/pdf"); 073 mappings.put("xml", "application/xml"); 074 mappings.put("json", "application/json"); 075 mappings.put("doc", "application/msword"); 076 mappings.put("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); 077 mappings.put("xls", "application/vnd.ms-excel"); 078 mappings.put("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); 079 mappings.put("pot", "application/vnd.ms-powerpoint"); 080 mappings.put("ppt", "application/vnd.ms-powerpoint"); 081 mappings.put("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"); 082 } 083 084 /** 085 * 让 undertow 支持音视频格式文件在线播放 086 */ 087 public static void init(DeploymentInfo di) { 088 for (Map.Entry<String, String> entry : mappings.entrySet()) { 089 di.addMimeMapping(new MimeMapping(entry.getKey(), entry.getValue())); 090 } 091 } 092 093}