Skip to content

Commit 5b178a4

Browse files
committed
优化 mediaTypes
1 parent d27c66b commit 5b178a4

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

okhttps/src/main/java/com/ejlchina/okhttps/HttpTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public C addFilePara(String name, String filePath) {
506506
/**
507507
* 添加文件参数(以 multipart/form-data 形式上传)
508508
* @param name 参数名
509-
* @param type 文件类型/扩展名: 如 txt、png、jpg、doc 等,参考 @{ HTTP$Builder#mediaTypes }
509+
* @param type 文件类型/扩展名: 如 txt、png、jpg、doc 等,参考 {@link HTTP.Builder#getMediaTypes() }
510510
* @param filePath 文件路径
511511
* @return HttpTask 实例
512512
*/

okhttps/src/main/java/com/ejlchina/okhttps/internal/AbstractHttpClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,15 @@ public MediaType mediaType(String type) {
161161
return MediaType.parse(mediaType);
162162
}
163163
if (type != null) {
164+
if (type.indexOf('/') < 0) {
165+
type = "application/" + type;
166+
}
164167
MediaType mType = MediaType.parse(type);
165168
if (mType != null) {
166169
return mType;
167170
}
168171
}
169-
return MediaType.parse("application/octet-stream");
172+
return MediaType.parse("application/unknown");
170173
}
171174

172175
@Override

okhttps/src/main/java/com/ejlchina/okhttps/okhttp/OkHttpBuilderImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,22 @@ public class OkHttpBuilderImpl implements HTTP.Builder {
5050

5151
public OkHttpBuilderImpl() {
5252
mediaTypes = new HashMap<>();
53-
mediaTypes.put("*", "application/octet-stream");
5453
mediaTypes.put("png", "image/png");
5554
mediaTypes.put("jpg", "image/jpeg");
5655
mediaTypes.put("jpeg", "image/jpeg");
5756
mediaTypes.put("wav", "audio/wav");
5857
mediaTypes.put("mp3", "audio/mp3");
59-
mediaTypes.put("mp4", "video/mpeg4");
58+
mediaTypes.put("mp4", "video/mp4");
6059
mediaTypes.put("txt", "text/plain");
6160
mediaTypes.put("xls", "application/x-xls");
61+
mediaTypes.put("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
6262
mediaTypes.put("xml", "text/xml");
6363
mediaTypes.put("apk", "application/vnd.android.package-archive");
6464
mediaTypes.put("doc", "application/msword");
65-
mediaTypes.put("pdf", "application/pdf");
65+
mediaTypes.put("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
6666
mediaTypes.put("html", "text/html");
67+
mediaTypes.put("rar", "application/x-rar");
68+
mediaTypes.put("jar", "application/x-java-archive");
6769
contentTypes = new ArrayList<>();
6870
contentTypes.add("application/x-www-form-urlencoded; charset={charset}");
6971
contentTypes.add("application/json; charset={charset}");

0 commit comments

Comments
 (0)