Allow set the mimetype over the content type

This commit is contained in:
Michael Bykovski 2018-01-25 11:14:31 +01:00
parent f77fd4d4b0
commit 519a264040

View File

@ -35,15 +35,15 @@ public class NanoHTTPDWebserver extends NanoHTTPD{
/**
* Create a request object
*
* <p>
* [
* "requestId": requestUUID,
" body": request.jsonObject ?? "",
" headers": request.headers,
" method": request.method,
" path": request.url.path,
" query": request.url.query ?? ""
]
* " body": request.jsonObject ?? "",
* " headers": request.headers,
* " method": request.method,
* " path": request.url.path,
* " query": request.url.query ?? ""
* ]
*
* @param session
* @return
@ -59,6 +59,15 @@ public class NanoHTTPDWebserver extends NanoHTTPD{
return jsonRequest;
}
private String getContentType(JSONObject responseObject) throws JSONException {
if (responseObject.has("headers") &&
responseObject.getJSONObject("headers").has("Content-Type")) {
return responseObject.getJSONObject("headers").getString("Content-Type");
} else {
return "text/plain";
}
}
@Override
public Response serve(IHTTPSession session) {
Log.d(this.getClass().getName(), "New request is incoming!");
@ -86,10 +95,11 @@ public class NanoHTTPDWebserver extends NanoHTTPD{
JSONObject responseObject = (JSONObject) this.webserver.responses.get(requestUUID);
Log.d(this.getClass().getName(), "responseObject: " + responseObject.toString());
Response response = null;
try {
response = newFixedLengthResponse(
Response.Status.lookup(responseObject.getInt("status")),
"text/plain",
getContentType(responseObject),
responseObject.getString("body")
);