Allow set the mimetype over the content type
This commit is contained in:
parent
f77fd4d4b0
commit
519a264040
@ -19,7 +19,7 @@ import java.util.Iterator;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NanoHTTPDWebserver extends NanoHTTPD{
|
||||
public class NanoHTTPDWebserver extends NanoHTTPD {
|
||||
|
||||
Webserver webserver;
|
||||
|
||||
@ -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")
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user