some changes
This commit is contained in:
parent
23349618ff
commit
d53ed81773
@ -14,51 +14,63 @@ import java.util.*;
|
|||||||
public abstract class FormDataHandler implements HttpHandler {
|
public abstract class FormDataHandler implements HttpHandler {
|
||||||
@Override
|
@Override
|
||||||
public void handle(HttpExchange httpExchange) throws IOException {
|
public void handle(HttpExchange httpExchange) throws IOException {
|
||||||
Headers headers = httpExchange.getRequestHeaders();
|
System.out.println(httpExchange);
|
||||||
String contentType = headers.getFirst("Content-Type");
|
|
||||||
String data = new String(httpExchange.getRequestBody().readAllBytes());
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
|
||||||
|
|
||||||
if (contentType.startsWith("multipart/form-data")) {
|
Headers headers = httpExchange.getRequestHeaders();
|
||||||
String boundary = "--" + contentType.substring(contentType.indexOf("boundary=") + 9) + "\r\n";
|
|
||||||
for (String part : data.split(boundary)) {
|
if (headers.containsKey("Content-type")) {
|
||||||
String[] lines = part.split("\r\n");
|
Map<String, Object> params = new HashMap<>();
|
||||||
if (lines.length >= 3) {
|
|
||||||
if (lines[0].startsWith("Content-Disposition: form-data; name=\"")) {
|
String contentType = headers.getFirst("Content-Type");
|
||||||
String name = lines[0].substring("Content-Disposition: form-data; name=\"".length());
|
String data = new String(httpExchange.getRequestBody().readAllBytes());
|
||||||
name = name.substring(0, name.length() - 1);
|
|
||||||
String value = lines[2];
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
params.put(name, value);
|
String boundary = "--" + contentType.substring(contentType.indexOf("boundary=") + 9) + "\r\n";
|
||||||
|
for (String part : data.split(boundary)) {
|
||||||
|
String[] lines = part.split("\r\n");
|
||||||
|
if (lines.length >= 3) {
|
||||||
|
if (lines[0].startsWith("Content-Disposition: form-data; name=\"")) {
|
||||||
|
String name = lines[0].substring("Content-Disposition: form-data; name=\"".length());
|
||||||
|
name = name.substring(0, name.length() - 1);
|
||||||
|
String value = lines[2];
|
||||||
|
params.put(name, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (contentType.startsWith("application/json")) {
|
||||||
} else if (contentType.startsWith("application/json")) {
|
try {
|
||||||
try {
|
Object o = new JSONParser().parse(data);
|
||||||
Object o = new JSONParser().parse(data);
|
if (o instanceof Map) {
|
||||||
if (o instanceof Map) {
|
for (Map.Entry<Object, Object> e : ((Map<Object, Object>) o).entrySet())
|
||||||
for (Map.Entry<Object, Object> e : ((Map<Object, Object>) o).entrySet())
|
params.put(e.getKey().toString(), e.getValue());
|
||||||
params.put(e.getKey().toString(), e.getValue());
|
} else {
|
||||||
} else {
|
params.put("data", o);
|
||||||
params.put("data", o);
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (ParseException e) {
|
} else if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
||||||
|
if (data.startsWith("?")) data = data.substring(1);
|
||||||
|
for (String s : data.split("&")) {
|
||||||
|
String[] ss = s.split("=");
|
||||||
|
String k = URLDecoder.decode(ss[0], Charsets.UTF_8);
|
||||||
|
String v = URLDecoder.decode(ss[1], Charsets.UTF_8);
|
||||||
|
params.put(k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
handle(httpExchange, params, data);
|
||||||
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
} else {
|
||||||
if (data.startsWith("?")) data = data.substring(1);
|
try {
|
||||||
for (String s : data.split("&")) {
|
handle(httpExchange, new HashMap<>(), "");
|
||||||
String[] ss = s.split("=");
|
} catch (Exception e) {
|
||||||
String k = URLDecoder.decode(ss[0], Charsets.UTF_8);
|
e.printStackTrace();
|
||||||
String v = URLDecoder.decode(ss[1], Charsets.UTF_8);
|
|
||||||
params.put(k, v);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
handle(httpExchange, params, data);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void handle(HttpExchange httpExchange,Map<String,Object> parts,String data) throws IOException;
|
public abstract void handle(HttpExchange httpExchange,Map<String,Object> parts,String data) throws IOException;
|
||||||
|
@ -47,6 +47,8 @@ public class SitePart extends FormDataHandler {
|
|||||||
String method = e.getRequestMethod();
|
String method = e.getRequestMethod();
|
||||||
String path = e.getRequestURI().getPath();
|
String path = e.getRequestURI().getPath();
|
||||||
|
|
||||||
|
System.out.println(response+" "+status_code+" "+path+" "+method);
|
||||||
|
|
||||||
if (method.equals("GET")) {
|
if (method.equals("GET")) {
|
||||||
if (path.equals(Main.me.vote_page)) {
|
if (path.equals(Main.me.vote_page)) {
|
||||||
if (params.containsKey("nickname") &&
|
if (params.containsKey("nickname") &&
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
site_host: localhost # IP адрес для сайта
|
site_host: localhost # IP адрес для сайта
|
||||||
site_port: 8080 # Порт для сайта
|
site_port: 8080 # Порт для сайта
|
||||||
site_backlog: 5 # Максимальное кол-во подключений одновременно
|
site_backlog: 0 # Максимальное кол-во подключений одновременно
|
||||||
|
|
||||||
secret_token: "ваш_секретный_токен" # Секретный токен с FroggyMonitor
|
secret_token: "ваш_секретный_токен" # Секретный токен с FroggyMonitor
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
name: MonitoringReward
|
name: FroggyMonitorReward
|
||||||
version: '${project.version}'
|
version: '${project.version}'
|
||||||
main: ru.froggymonitor.rewardplugin.Main
|
main: ru.froggymonitor.rewardplugin.Main
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
|
Loading…
Reference in New Issue
Block a user