|
|
|
|
@ -68,6 +68,7 @@ public class Connect { |
|
|
|
|
if (req.getData() != null && "json".equals(req.getPostType())) return getJsonBody(req); |
|
|
|
|
if (req.getData() != null && "form".equals(req.getPostType())) return getFormBody(req); |
|
|
|
|
if (req.getData() != null && "form-data".equals(req.getPostType())) return getFormDataBody(req); |
|
|
|
|
if (req.getData() != null && "raw".equals(req.getPostType())) return getRawBody(req); |
|
|
|
|
if (req.getBody() != null && contentType != null) return RequestBody.create(req.getBody(), MediaType.get(contentType)); |
|
|
|
|
return RequestBody.create("", null); |
|
|
|
|
} |
|
|
|
|
@ -76,6 +77,10 @@ public class Connect { |
|
|
|
|
return RequestBody.create(req.getData().toString(), MediaType.get("application/json")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static RequestBody getRawBody(Req req) { |
|
|
|
|
return RequestBody.create(req.getData().toString(), MediaType.get("application/json; charset=utf-8")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static RequestBody getFormBody(Req req) { |
|
|
|
|
FormBody.Builder builder = new FormBody.Builder(); |
|
|
|
|
Map<String, String> params = Json.toMap(req.getData()); |
|
|
|
|
@ -91,6 +96,8 @@ public class Connect { |
|
|
|
|
return builder.build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void setHeader(QuickJSContext ctx, Response res, JSObject object) { |
|
|
|
|
for (Map.Entry<String, List<String>> entry : res.headers().toMultimap().entrySet()) { |
|
|
|
|
if (entry.getValue().size() == 1) object.setProperty(entry.getKey(), entry.getValue().get(0)); |
|
|
|
|
|