Improve logs in HttpEventTask of sentinel-transport-simple-http module
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
parent
47100e64ba
commit
f6badb0622
|
|
@ -72,10 +72,10 @@ public class HttpEventTask implements Runnable {
|
||||||
new OutputStreamWriter(outputStream, Charset.forName(SentinelConfig.charset())));
|
new OutputStreamWriter(outputStream, Charset.forName(SentinelConfig.charset())));
|
||||||
|
|
||||||
String line = in.readLine();
|
String line = in.readLine();
|
||||||
CommandCenterLog.info("[SimpleHttpCommandCenter] socket income: " + line
|
CommandCenterLog.info("[SimpleHttpCommandCenter] Socket income: " + line
|
||||||
+ "," + socket.getInetAddress());
|
+ ", addr: " + socket.getInetAddress());
|
||||||
CommandRequest request = parseRequest(line);
|
CommandRequest request = parseRequest(line);
|
||||||
|
|
||||||
if (line.length() > 4 && StringUtil.equalsIgnoreCase("POST", line.substring(0, 4))) {
|
if (line.length() > 4 && StringUtil.equalsIgnoreCase("POST", line.substring(0, 4))) {
|
||||||
// Deal with post method
|
// Deal with post method
|
||||||
// Now simple-http only support form-encoded post request.
|
// Now simple-http only support form-encoded post request.
|
||||||
|
|
@ -95,12 +95,12 @@ public class HttpEventTask implements Runnable {
|
||||||
parseParams(postData, request);
|
parseParams(postData, request);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyLine = in.readLine();
|
bodyLine = in.readLine();
|
||||||
if (bodyLine == null) {
|
if (bodyLine == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Body seperator
|
// Body separator
|
||||||
if (StringUtil.isEmpty(bodyLine)) {
|
if (StringUtil.isEmpty(bodyLine)) {
|
||||||
bodyNext = true;
|
bodyNext = true;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -114,22 +114,24 @@ public class HttpEventTask implements Runnable {
|
||||||
String header = bodyLine.substring(index + 1).trim();
|
String header = bodyLine.substring(index + 1).trim();
|
||||||
if (StringUtil.equalsIgnoreCase("content-type", headerName)) {
|
if (StringUtil.equalsIgnoreCase("content-type", headerName)) {
|
||||||
int idx = header.indexOf(";");
|
int idx = header.indexOf(";");
|
||||||
if (idx > 0){
|
if (idx > 0) {
|
||||||
header = header.substring(0, idx).trim();
|
header = header.substring(0, idx).trim();
|
||||||
}
|
}
|
||||||
if (StringUtil.equals("application/x-www-form-urlencoded", header)) {
|
if (StringUtil.equals("application/x-www-form-urlencoded", header)) {
|
||||||
supported = true;
|
supported = true;
|
||||||
} else {
|
} else {
|
||||||
|
CommandCenterLog.warn("Content-Type not supported: " + header);
|
||||||
// not support request
|
// not support request
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (StringUtil.equalsIgnoreCase("content-length", headerName)) {
|
} else if (StringUtil.equalsIgnoreCase("content-length", headerName)) {
|
||||||
try {
|
try {
|
||||||
int len = new Integer(header);
|
int len = Integer.parseInt(header);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
maxLength = len;
|
maxLength = len;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
CommandCenterLog.warn("Malformed content-length header value: " + header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +267,7 @@ public class HttpEventTask implements Runnable {
|
||||||
parseParams(parameterStr, request);
|
parseParams(parameterStr, request);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseParams(String queryString, CommandRequest request) {
|
private void parseParams(String queryString, CommandRequest request) {
|
||||||
for (String parameter : queryString.split("&")) {
|
for (String parameter : queryString.split("&")) {
|
||||||
if (StringUtil.isBlank(parameter)) {
|
if (StringUtil.isBlank(parameter)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue