Skip to content

Commit

Permalink
bugfix: URL regexp somtimes caused stack overflow exception
Browse files Browse the repository at this point in the history
bugfix: clients stopped working after first 502
  • Loading branch information
koto committed Jan 12, 2012
1 parent c57522c commit 3405d73
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions proxy-backend/malaria/MalariaServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void serveSocket(Socket client, ServerSocket proxySocket, String hostname
while (!done) {
byte[] buffer = new byte[4096];
int length = clientIn.read(buffer, 0, buffer.length);
if (new String(buffer, 0, length, "UTF8").equals("HTTP/1.1 502 Not accessible")) {
if (new String(buffer, 0, length, "UTF8").startsWith("HTTP/1.1 502 Not accessible")) {
proxyOut.write(buffer, 0, length);
proxyOut.flush();
proxyClient.close();
Expand Down Expand Up @@ -121,14 +121,14 @@ public void serveSocket(Socket client, ServerSocket proxySocket, String hostname

private String[] parseRequest(String proxyMessage) {
ArrayList<String> parts = new ArrayList<String>();
Pattern hostAndAccept = Pattern.compile("(GET|POST) ([^ ]+)(.|[\\s])+Accept: ([\\S]+)(.|[\\s])+");
Pattern hostAndAccept = Pattern.compile("^(GET|POST) ([^ ]+).+?Accept: ([\\S]+).*", Pattern.DOTALL);
Matcher m = hostAndAccept.matcher(proxyMessage);
if (!m.matches()) {
return null;
}
parts.add(m.group(1));
parts.add(m.group(2));
parts.add(m.group(4));
parts.add(m.group(3));
String[] headersAndData = proxyMessage.split("\r\n\r\n", 2);
if (headersAndData.length > 1) {
parts.add(headersAndData[1]);
Expand Down

0 comments on commit 3405d73

Please sign in to comment.