Fix Springboot+Tomcat http status missing, fix memory url leak
This commit is contained in:
@@ -110,7 +110,12 @@ public class Controller implements Initializable {
|
||||
sp.getItems().add(ta);
|
||||
sp.setOrientation(Orientation.VERTICAL);
|
||||
|
||||
return new Tab("untitled", sp);
|
||||
Tab tab = new Tab("untitled", sp);
|
||||
tab.setOnCloseRequest(arg0 -> {
|
||||
requests.remove(tab.hashCode());
|
||||
});
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -7,37 +7,52 @@
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="365.0" prefWidth="707.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<Label layoutX="25.0" layoutY="183.0" text="Made with Java 14.0.2 (GUI with JavaFX 15)">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font></Label>
|
||||
<Label layoutX="25.0" layoutY="147.0" text="Author: Alexis Delhaie (@alexlegarnd)">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font></Label>
|
||||
<ImageView fitHeight="111.0" fitWidth="707.0" pickOnBounds="true" preserveRatio="true" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<image>
|
||||
<Image url="@banner.png" />
|
||||
</image></ImageView>
|
||||
<Label layoutX="25.0" layoutY="220.0" text="Installer made with Delphi 10.3 Community">
|
||||
<Label layoutX="537.0" layoutY="327.0" text="Version 0.1.1 (Not finished)" AnchorPane.bottomAnchor="16.0" AnchorPane.rightAnchor="16.0">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label layoutX="25.0" layoutY="257.0" text="Installer Bootstrap made with Python 3">
|
||||
<GridPane layoutX="32.0" layoutY="123.0" prefHeight="224.0" prefWidth="348.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Author: Alexis Delhaie (@alexlegarnd)">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label layoutX="422.0" layoutY="158.0" text="EndPoint">
|
||||
<Label text="Made with Java 14.0.2 (GUI with JavaFX 15)" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="48.0" />
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label layoutX="444.0" layoutY="230.0" text="Version 0.1 (Not finished)">
|
||||
<Label text="Installer made with Delphi 10.3 Community" GridPane.rowIndex="2">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="Installer Bootstrap made with Python 3" GridPane.rowIndex="3">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</GridPane>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="428.0" layoutY="111.0" prefHeight="224.0" prefWidth="216.0" text=" (((///////////////////////( *(((///////////////////////// , /(///////////////////////// /((/////////////////////// /(((////////////////////// / ((((((/////////////////// (((((((((((( ((((((((///////////////// (((((((((((((((((( .((((((((((/////////////// ((((((((((((((((((((((. ((((((((((((((/////////// (((((((((((((((((((((((((( (((((((((((((((((//////// ((((((((((((((((((((((((((((. ((((((((((((((((((((///// ((((((((((((((((((((((((((((((( ((((((((((((((((((((((((/ &(((((((((((((((((((((((((((((((( ((((((((((((((((((((((((( ((((((((((((((((((((((((((((((((( (( .(((((((((((((((( #####((((((((((((((((((((((((((((( (((((((((((((((((( #########(((((((((((((((((((((((( *((((*. (((((((((((((((((((( #############((((((((((((( ((((((((((((((((( ((((((((((((((((((((( ##################(((((((((((* (((((((((((((((((((. ((((((((((((((((((( &#####################(((((((((((, (((((((((((((((((((( (((((((((((((((( #########################(((((((( (((((((((((((((( ((((((((((((((( #############################((. ((((((((((/ /((((((((((((( ############################## ((((( (((((((((((( ############################# *((((((((((( ############################# ((((((((((( ############################ (((((((((( ############################ (((((((((( ############################, ((((((((((( ############################### #########(((( ############################################# ##################################### ######################### " textAlignment="CENTER" AnchorPane.bottomAnchor="30.0" AnchorPane.rightAnchor="63.0" AnchorPane.topAnchor="111.0">
|
||||
<font>
|
||||
<Font name="Consolas" size="4.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
@@ -19,7 +19,7 @@ public class HttpClient {
|
||||
public final static String CRLF = "\r\n";
|
||||
public final static int DEFAULT_TIMEOUT = 10000;
|
||||
|
||||
private boolean allowInvalidSsl;
|
||||
private final boolean allowInvalidSsl;
|
||||
|
||||
public HttpClient() { this(false); }
|
||||
public HttpClient(boolean allowInvalidSsl) { this.allowInvalidSsl = allowInvalidSsl; }
|
||||
|
||||
94
src/ovh/alexisdelhaie/endpoint/http/HttpStatus.java
Normal file
94
src/ovh/alexisdelhaie/endpoint/http/HttpStatus.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package ovh.alexisdelhaie.endpoint.http;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum HttpStatus {
|
||||
CONTINUE(100, "Continue"),
|
||||
SWITCHING_PROTOCOLS(101, "Switching Protocols"),
|
||||
|
||||
OK(200, "OK"),
|
||||
CREATED(201, "Created"),
|
||||
ACCEPTED(202, "Accepted"),
|
||||
NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"),
|
||||
NO_CONTENT(204, "No content"),
|
||||
RESET_CONTENT(205, "Reset Content"),
|
||||
PARTIAL_CONTENT(206, "Partial Content"),
|
||||
|
||||
MULTIPLE_CHOICES(300, "Multiple Choices"),
|
||||
MOVED_PERMANENTLY(301, "Moved Permanently"),
|
||||
FOUND(302, "Found"),
|
||||
SEE_OTHER(303, "See Other"),
|
||||
NOT_MODIFIED(304, "Not Modified"),
|
||||
USE_PROXY(305, "Use Proxy"),
|
||||
SWITCH_PROXY(306, "Switch Proxy"),
|
||||
TEMPORARY_REDIRECT(307, "Temporary Redirect"),
|
||||
PERMANENT_REDIRECT(308, "Permanent Redirect"),
|
||||
TOO_MANY_REDIRECTS(310, "Too many Redirects"),
|
||||
|
||||
BAD_REQUEST(400, "Bad Request"),
|
||||
UNAUTHORIZED(401, "Unauthorized"),
|
||||
PAYMENT_REQUIRED(402, "Payment Required"),
|
||||
FORBIDDEN(403, "Forbidden"),
|
||||
NOT_FOUND(404, "Not Found"),
|
||||
METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
|
||||
NOT_ACCEPTABLE(406, "Not Acceptable"),
|
||||
PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),
|
||||
REQUEST_TIME_OUT(408, "Request Timeout"),
|
||||
CONFLICT(409, "Conflict"),
|
||||
GONE(410, "Gone"),
|
||||
LENGTH_REQUIRED(411, "Length Required"),
|
||||
PRECONDITION_FAILED(412, "Precondition Failed"),
|
||||
PAYLOAD_TOO_LARGE(413, "Payload Too Large"),
|
||||
URI_TOO_LONG(414, "URI Too Long"),
|
||||
UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
|
||||
RANGE_NOT_SATISFIABLE(416, "Range Not Satisfiable "),
|
||||
EXPECTATION_FAILED(417, "Expectation Failed"),
|
||||
IM_A_TEAPOT(418, "I'm a teapot"), //for fun
|
||||
MISDIRECTED_REQUEST(421, "Misdirected Request"),
|
||||
TOO_EARLY(425, "Too Early"),
|
||||
UPGRADE_REQUIRED(426, "Upgrade Required"),
|
||||
PRECONDITION_REQUIRED(428, "Precondition Required"),
|
||||
TOO_MANY_REQUESTS(429, "Too Many Requests"),
|
||||
REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),
|
||||
RETRY_WITH(449, "Retry With"),
|
||||
BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS(450, "Blocked by Windows Parental Controls"),
|
||||
UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"),
|
||||
|
||||
INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
|
||||
NOT_IMPLEMENTED(501, "Not Implemented"),
|
||||
BAD_GATEWAY(502, "Bad Gateway"),
|
||||
SERVICE_UNAVAILABLE(503, "Service Unavailable"),
|
||||
GATEWAY_TIME_OUT(504, "Gateway Timeout"),
|
||||
HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version Not Supported"),
|
||||
VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"),
|
||||
BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"),
|
||||
NOT_EXTENDED(510, "Not Extended"),
|
||||
NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
||||
HttpStatus(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
private static final Map<Integer, HttpStatus> map;
|
||||
|
||||
static {
|
||||
map = new HashMap<>();
|
||||
for (HttpStatus v : HttpStatus.values()) {
|
||||
map.put(v.code, v);
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpStatus findByCode(int i) {
|
||||
return map.get(i);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,13 +7,13 @@ import java.util.Objects;
|
||||
|
||||
public class Request {
|
||||
|
||||
private String host;
|
||||
private String scheme;
|
||||
private String path;
|
||||
private int port;
|
||||
private HashMap<String, String> params;
|
||||
private HashMap<String, String> customHeaders;
|
||||
private String body;
|
||||
private final String host;
|
||||
private final String scheme;
|
||||
private final String path;
|
||||
private final int port;
|
||||
private final HashMap<String, String> params;
|
||||
private final HashMap<String, String> customHeaders;
|
||||
private final String body;
|
||||
private String rawRequest;
|
||||
|
||||
Request(String host, String scheme, String path, int port,
|
||||
|
||||
@@ -16,8 +16,8 @@ public class RequestBuilder {
|
||||
private String scheme;
|
||||
private String path;
|
||||
private int port;
|
||||
private HashMap<String, String> params;
|
||||
private HashMap<String, String> customHeaders;
|
||||
private final HashMap<String, String> params;
|
||||
private final HashMap<String, String> customHeaders;
|
||||
private String body;
|
||||
|
||||
public RequestBuilder (String url) throws MalformedURLException {
|
||||
|
||||
@@ -12,21 +12,20 @@ public class Response {
|
||||
public final static String CRLF = "\r\n";
|
||||
public final static String DOUBLE_CRLF = "\r\n\r\n";
|
||||
|
||||
private HashMap<String, String> headers;
|
||||
private String rawHeaders;
|
||||
private final HashMap<String, String> headers;
|
||||
private final String rawHeaders;
|
||||
private String rawResponse;
|
||||
private String body;
|
||||
private final String body;
|
||||
private int statusCode;
|
||||
private String status;
|
||||
private long time;
|
||||
private Request request;
|
||||
private final long time;
|
||||
private final Request request;
|
||||
|
||||
Response(byte[] res, long time, Request r) throws UnsupportedEncodingException {
|
||||
headers = new HashMap<>();
|
||||
rawResponse = new String(res, StandardCharsets.UTF_8);
|
||||
int crlf = rawResponse.indexOf(DOUBLE_CRLF);
|
||||
String h = rawResponse.substring(0, crlf);
|
||||
rawHeaders = h;
|
||||
rawHeaders = rawResponse.substring(0, crlf);
|
||||
parseHeaders();
|
||||
rawResponse = new String(res, getEncoding());
|
||||
body = rawResponse.substring(crlf + DOUBLE_CRLF.length());
|
||||
@@ -46,11 +45,22 @@ public class Response {
|
||||
}
|
||||
|
||||
private void parseStatus(String l) {
|
||||
Pattern p = Pattern.compile("(HTTP/1.1)\\s([0-9]{3})\\s(.+)");
|
||||
Pattern p = Pattern.compile("^(HTTP/1.1)\\s([0-9]{3})\\s(.+)$");
|
||||
Matcher m = p.matcher(l);
|
||||
if (m.matches()) {
|
||||
statusCode = Integer.parseInt(m.group(2));
|
||||
status = m.group(3);
|
||||
} else {
|
||||
p = Pattern.compile("^(HTTP/1.1)\\s([0-9]{3})$");
|
||||
m = p.matcher(l);
|
||||
if (m.matches()) {
|
||||
statusCode = Integer.parseInt(m.group(2));
|
||||
HttpStatus httpStatus = HttpStatus.findByCode(statusCode);
|
||||
status = (httpStatus != null) ? httpStatus.getMessage() : "";
|
||||
} else {
|
||||
statusCode = -1;
|
||||
status = "Cannot get status form HTTP Response";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user