Skip to content

Commit 19cf67e

Browse files
committed
Set own response content-type
1 parent ab51ec5 commit 19cf67e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/express/http/response/Response.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Response {
2424
private final OutputStream BODY;
2525
private final Headers HEADER;
2626

27-
private MediaType contentType = MediaType._txt;
27+
private String contentType = MediaType._txt.getMIME();
2828
private boolean isClose = false;
2929
private long contentLength = 0;
3030
private int status = 200;
@@ -112,7 +112,7 @@ public void sendStatus(@NotNull Status status) {
112112
/**
113113
* @return The current contentType
114114
*/
115-
public MediaType getContentType() {
115+
public String getContentType() {
116116
return contentType;
117117
}
118118

@@ -122,6 +122,15 @@ public MediaType getContentType() {
122122
* @param contentType - The contentType
123123
*/
124124
public void setContentType(MediaType contentType) {
125+
this.contentType = contentType.getMIME();
126+
}
127+
128+
/**
129+
* Set the contentType for this response.
130+
*
131+
* @param contentType - The contentType
132+
*/
133+
public void setContentType(String contentType) {
125134
this.contentType = contentType;
126135
}
127136

@@ -164,7 +173,9 @@ public void send(String s) {
164173
public void send(@NotNull File file) {
165174
if (checkIfClosed()) return;
166175
this.contentLength += file.length();
167-
this.contentType = Utils.getContentType(file);
176+
177+
MediaType mediaType = Utils.getContentType(file);
178+
this.contentType = mediaType == null ? null : mediaType.getMIME();
168179
sendHeaders();
169180

170181
try {
@@ -197,7 +208,7 @@ private void sendHeaders() {
197208
try {
198209

199210
// Fallback
200-
String contentType = getContentType().getExtension() == null ? MediaType._bin.getExtension() : getContentType().getMIME();
211+
String contentType = getContentType() == null ? MediaType._bin.getExtension() : getContentType();
201212

202213
// Set header and send response
203214
this.HEADER.set("Content-Type", contentType);

src/express/utils/MediaType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ public enum MediaType {
690690
_ice("ice", "x-conference/x-cooltalk"),
691691
_par("par", "text/plain-bas"),
692692
_yaml("yaml", "text/yaml"),
693-
_dmg("dmg", "application/x-apple-diskimage");
693+
_dmg("dmg", "application/x-apple-diskimage"),
694+
_xww("form", "application/x-www-form-urlencoded");
694695

695696
private String MIME;
696697
private String extension;

0 commit comments

Comments
 (0)