Browse Source

-HTTP: fixed a bug that made https unusable
-Fixed formatters

Wulf Pfeiffer 10 years ago
parent
commit
5c3814e9c2

+ 4 - 1
src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java

@@ -157,7 +157,10 @@ public class HTTP implements Protocol {
 		List<Packet> responsePackets = new ArrayList<Packet>();
 		this.request = request;
 
-		if (!request.contains(httpVersion)) {
+		if (request.startsWith("G")) {
+			//weird if clause but required for https
+			responsePackets.add(buildPacket(STATUS_CODE_200, GET));
+		} else if (!request.contains(httpVersion)) {
 			responsePackets.add(buildPacket(STATUS_CODE_505, ""));
 		} else if (request.contains(GET)) {
 			responsePackets.add(buildPacket(STATUS_CODE_200, GET));

+ 11 - 6
src/de/tudarmstadt/informatik/hostage/wrapper/Packet.java

@@ -1,9 +1,12 @@
 package de.tudarmstadt.informatik.hostage.wrapper;
 
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+
 /**
  * Wrapper class for the payload of a network packet.
  * 
  * @author Mihai Plasoianu
+ * @author Wulf Pfeiffer
  */
 public class Packet {
 
@@ -40,20 +43,22 @@ public class Packet {
 
 	/**
 	 * Returns a String representation of the payload.
+	 * If the payload contains a ASCII character the whole
+	 * String will be represented as a String of a byte values.
+	 * E.g.: the byte[] {0x01, 0x4A, 0x03} would look like
+	 * the String "01, 4A, 03".
+	 * Otherwise a normal String will be created with the payload.
 	 * 
 	 * @return String representation.
 	 */
 	@Override
 	public String toString() {
-		StringBuilder builder = new StringBuilder(payload.length);
 		for (int i = 0; i < payload.length; ++i) {
-			if (payload[i] < 10) {
-				builder.append("{0x").append(payload[i]).append("}");
-			} else {
-				builder.append(Character.toString((char) payload[i]));
+			if (((char) payload[i]) < 9) {
+				return HelperUtils.bytesToHexString(payload);
 			}
 		}
-		return builder.toString();
+		return new String(payload);
 	}
 
 }