Allow set the mimetype over the content type
This commit is contained in:
parent
f77fd4d4b0
commit
519a264040
@ -35,15 +35,15 @@ public class NanoHTTPDWebserver extends NanoHTTPD{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a request object
|
* Create a request object
|
||||||
*
|
* <p>
|
||||||
* [
|
* [
|
||||||
* "requestId": requestUUID,
|
* "requestId": requestUUID,
|
||||||
" body": request.jsonObject ?? "",
|
* " body": request.jsonObject ?? "",
|
||||||
" headers": request.headers,
|
* " headers": request.headers,
|
||||||
" method": request.method,
|
* " method": request.method,
|
||||||
" path": request.url.path,
|
* " path": request.url.path,
|
||||||
" query": request.url.query ?? ""
|
* " query": request.url.query ?? ""
|
||||||
]
|
* ]
|
||||||
*
|
*
|
||||||
* @param session
|
* @param session
|
||||||
* @return
|
* @return
|
||||||
@ -59,6 +59,15 @@ public class NanoHTTPDWebserver extends NanoHTTPD{
|
|||||||
return jsonRequest;
|
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
|
@Override
|
||||||
public Response serve(IHTTPSession session) {
|
public Response serve(IHTTPSession session) {
|
||||||
Log.d(this.getClass().getName(), "New request is incoming!");
|
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);
|
JSONObject responseObject = (JSONObject) this.webserver.responses.get(requestUUID);
|
||||||
Log.d(this.getClass().getName(), "responseObject: " + responseObject.toString());
|
Log.d(this.getClass().getName(), "responseObject: " + responseObject.toString());
|
||||||
Response response = null;
|
Response response = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = newFixedLengthResponse(
|
response = newFixedLengthResponse(
|
||||||
Response.Status.lookup(responseObject.getInt("status")),
|
Response.Status.lookup(responseObject.getInt("status")),
|
||||||
"text/plain",
|
getContentType(responseObject),
|
||||||
responseObject.getString("body")
|
responseObject.getString("body")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user