From 20959bad2df2177a02aecba97865003244f5180c Mon Sep 17 00:00:00 2001 From: Alexis Delhaie Date: Fri, 2 Oct 2020 21:27:37 +0200 Subject: [PATCH] Chunk parsing algo, HTTP/1.0, fixing http status with tomcat --- .../controllers/ConfigurationController.java | 20 ++++++++-- .../endpoint/controllers/Controller.java | 21 +++++++--- .../endpoint/controllers/about.fxml | 17 +++++---- .../endpoint/controllers/configuration.fxml | 38 +++++++++++-------- .../endpoint/controllers/responsetab.fxml | 2 +- .../endpoint/http/HttpClient.java | 17 ++++++--- .../alexisdelhaie/endpoint/http/Response.java | 21 +++++++++- .../endpoint/http/parsers/Chunked.java | 25 ++++++++++++ 8 files changed, 121 insertions(+), 40 deletions(-) create mode 100644 src/ovh/alexisdelhaie/endpoint/http/parsers/Chunked.java diff --git a/src/ovh/alexisdelhaie/endpoint/controllers/ConfigurationController.java b/src/ovh/alexisdelhaie/endpoint/controllers/ConfigurationController.java index cbc4e07..d82605e 100644 --- a/src/ovh/alexisdelhaie/endpoint/controllers/ConfigurationController.java +++ b/src/ovh/alexisdelhaie/endpoint/controllers/ConfigurationController.java @@ -1,12 +1,14 @@ package ovh.alexisdelhaie.endpoint.controllers; +import javafx.collections.FXCollections; +import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; -import javafx.fxml.Initializable; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.CheckBox; +import javafx.scene.control.ChoiceBox; import javafx.scene.image.Image; import javafx.scene.input.MouseEvent; import javafx.stage.Modality; @@ -14,8 +16,6 @@ import javafx.stage.Stage; import ovh.alexisdelhaie.endpoint.configuration.ConfigurationProperties; import java.io.IOException; -import java.net.URL; -import java.util.ResourceBundle; public class ConfigurationController { @@ -27,15 +27,21 @@ public class ConfigurationController private CheckBox allowInvalidSsl; @FXML private CheckBox allowDowngrade; + @FXML + private ChoiceBox httpVersion; public void setStageAndSetupListeners(Stage s) { primaryStage = s; } public void setConfigurationProperties(ConfigurationProperties properties) { + String[] versions = { "HTTP/1.1", "HTTP/1.0" }; + httpVersion.setItems(FXCollections.observableArrayList(versions)); configurationProperties = properties; allowInvalidSsl.setSelected(properties.getBooleanProperty("allowInvalidSsl", false)); allowDowngrade.setSelected(properties.getBooleanProperty("allowDowngrade", true)); + httpVersion.setValue(properties.getStringProperty("httpVersion", versions[0])); + httpVersion.setOnAction(this::onChoiceBoxValueChanged); } @FXML @@ -44,13 +50,19 @@ public class ConfigurationController configurationProperties.setProperty(c.getId(), String.valueOf(c.isSelected())); } + @SuppressWarnings("unchecked") + private void onChoiceBoxValueChanged(ActionEvent event) { + ChoiceBox c = (ChoiceBox) event.getSource(); + configurationProperties.setProperty(c.getId(), c.getValue()); + } + @FXML private void showAboutDialog() { try { Stage dialog = new Stage(); Parent xml = FXMLLoader.load(getClass().getResource("about.fxml")); dialog.initOwner(primaryStage); - dialog.setScene(new Scene(xml, 677, 365)); + dialog.setScene(new Scene(xml, 707, 365)); dialog.setMaxHeight(365); dialog.setMinHeight(365); dialog.setMaxWidth(707); diff --git a/src/ovh/alexisdelhaie/endpoint/controllers/Controller.java b/src/ovh/alexisdelhaie/endpoint/controllers/Controller.java index e546f88..ee4ce00 100644 --- a/src/ovh/alexisdelhaie/endpoint/controllers/Controller.java +++ b/src/ovh/alexisdelhaie/endpoint/controllers/Controller.java @@ -84,6 +84,7 @@ public class Controller implements Initializable { private Stage primaryStage; private HashMap requests; + private HashMap methods; private ConfigurationProperties properties; @@ -91,11 +92,16 @@ public class Controller implements Initializable { public void initialize(URL location, ResourceBundle resources) { properties = new ConfigurationProperties(); requests = new HashMap<>(); + methods = new HashMap<>(); String[] method = { "GET", "POST", "HEAD", "PUT", "DELETE" }; httpMethod.setItems(FXCollections.observableArrayList(method)); httpMethod.setValue(method[0]); + httpMethod.setOnAction(actionEvent -> httpMethodChanged()); tabs.getSelectionModel().selectedItemProperty().addListener( - (ov, t, t1) -> requestInput.setText((t1 != null) ? requests.get(t1.hashCode()) : "") + (ov, t, t1) -> { + requestInput.setText((t1 != null) ? requests.get(t1.hashCode()) : ""); + httpMethod.setValue((t1 != null) ? methods.get(t1.hashCode()) : httpMethod.getValue()); + } ); createNewTab(); } @@ -111,6 +117,7 @@ public class Controller implements Initializable { TabPane options = new TabPane(); TextArea ta = new TextArea(); + ta.setEditable(false); options.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); options.getTabs().addAll(params, auth, headers, body, response); @@ -121,6 +128,7 @@ public class Controller implements Initializable { Tab tab = new Tab("untitled", sp); tab.setOnCloseRequest(arg0 -> { requests.remove(tab.hashCode()); + methods.remove(tab.hashCode()); }); return tab; @@ -209,10 +217,7 @@ public class Controller implements Initializable { Request r = new RequestBuilder(requestInput.getText()) .setCustomHeaders(getCustomHeaders()) .build(); - HttpClient hc = new HttpClient( - properties.getBooleanProperty("allowInvalidSsl", false), - properties.getBooleanProperty("allowDowngrade", true) - ); + HttpClient hc = new HttpClient(properties); switch (method) { case "GET" -> response = hc.get(r); case "POST" -> response = hc.post(r, getBody()); @@ -395,6 +400,7 @@ public class Controller implements Initializable { new Thread(() -> { Tab t = newTab(); requests.put(t.hashCode(), ""); + methods.put(t.hashCode(), httpMethod.getValue()); Platform.runLater(() -> { tabs.getTabs().add(t); tabs.getSelectionModel().select(t); @@ -436,6 +442,11 @@ public class Controller implements Initializable { } } + private void httpMethodChanged() { + Tab tab = tabs.getSelectionModel().getSelectedItem(); + methods.put(tab.hashCode(), httpMethod.getValue()); + } + @FXML private void requestInputOnKeyPressed() { Tab tab = tabs.getSelectionModel().getSelectedItem(); diff --git a/src/ovh/alexisdelhaie/endpoint/controllers/about.fxml b/src/ovh/alexisdelhaie/endpoint/controllers/about.fxml index 942aa44..7a844f5 100644 --- a/src/ovh/alexisdelhaie/endpoint/controllers/about.fxml +++ b/src/ovh/alexisdelhaie/endpoint/controllers/about.fxml @@ -11,17 +11,13 @@ - + @@ -32,17 +28,22 @@ -