/** * Parser for the first (!) line from the HTTP request<br> * Sets up the URL, method and remote hostname. * * @return an InetAddress for the hostname, null on errors with a statuscode!=SC_OK */ public InetAddress parseRequest(String a, int method_index) { if (server.debug) server.writeLog(a); String f; int pos; url = ""; if (ssl) { f = a.substring(8); } else { method = a.substring(0, a.indexOf(" ")); // first word in the line pos = a.indexOf(":"); // locate first : if (pos == -1) { // occours with "GET / HTTP/1.1" url = a.substring(a.indexOf(" ") + 1, a.lastIndexOf(" ")); if (method_index == 0) { // method_index==0 --> GET if (url.indexOf(server.WEB_CONFIG_FILE) != -1) statuscode = connection.SC_CONFIG_RQ; else statuscode = connection.SC_FILE_REQUEST; } else { if (method_index == 1 && url.indexOf(server.WEB_CONFIG_FILE) != -1) { // allow // "POST" // for // admin // log // in statuscode = connection.SC_CONFIG_RQ; } else { statuscode = connection.SC_INTERNAL_SERVER_ERROR; errordescription = "This WWW proxy supports only the \"GET\" method while acting as webserver."; } } return null; } f = a.substring(pos + 3); // removes "http://" } pos = f.indexOf(" "); // locate space, should be the space before // "HTTP/1.1" if (pos == -1) { // buggy request statuscode = connection.SC_CLIENT_ERROR; errordescription = "Your browser sent an invalid request: \"" + a + "\""; return null; } f = f.substring(0, pos); // removes all after space // if the url contains a space... it's not our mistake...(url's must // never contain a space character) pos = f.indexOf("/"); // locate the first slash if (pos != -1) { url = f.substring(pos); // saves path without hostname f = f.substring(0, pos); // reduce string to the hostname } else url = "/"; // occurs with this request: // "GET http://localhost HTTP/1.1" pos = f.indexOf(":"); // check for the portnumber if (pos != -1) { String l_port = f.substring(pos + 1); l_port = l_port.indexOf(" ") != -1 ? l_port.substring(0, l_port.indexOf(" ")) : l_port; int i_port = 80; try { i_port = Integer.parseInt(l_port); } catch (NumberFormatException e_get_host) { server.writeLog("get_Host :" + e_get_host + " !!!!"); } f = f.substring(0, pos); remote_port = i_port; } else remote_port = 80; remote_host_name = f; InetAddress address = null; if (server.log_access) server.logAccess( connection.getLocalSocket().getInetAddress().getHostAddress() + " " + method + " " + getFullURL()); try { address = InetAddress.getByName(f); if (remote_port == server.port && address.equals(InetAddress.getLocalHost())) { if (url.indexOf(server.WEB_CONFIG_FILE) != -1 && (method_index == 0 || method_index == 1)) statuscode = connection.SC_CONFIG_RQ; else if (method_index > 0) { statuscode = connection.SC_INTERNAL_SERVER_ERROR; errordescription = "This WWW proxy supports only the \"GET\" method while acting as webserver."; } else statuscode = connection.SC_FILE_REQUEST; } } catch (UnknownHostException e_u_host) { if (!server.use_proxy) statuscode = connection.SC_HOST_NOT_FOUND; } return address; }