user-agent exclusion

This commit is contained in:
Arndt Brenschede 2018-10-27 21:55:59 +02:00
parent 394eff30fa
commit 9e88f37816
2 changed files with 59 additions and 30 deletions

View file

@ -63,9 +63,50 @@ public class RouteServer extends Thread
br = new BufferedReader( new InputStreamReader( clientSocket.getInputStream() , "UTF-8") ); br = new BufferedReader( new InputStreamReader( clientSocket.getInputStream() , "UTF-8") );
bw = new BufferedWriter( new OutputStreamWriter( clientSocket.getOutputStream(), "UTF-8" ) ); bw = new BufferedWriter( new OutputStreamWriter( clientSocket.getOutputStream(), "UTF-8" ) );
// we just read the first line // first line
String getline = br.readLine(); String getline = null;
if ( getline == null || getline.startsWith("GET /favicon.ico") ) String agent = null;
// more headers until first empty line
for(;;)
{
// headers
String line = br.readLine();
if ( line == null )
{
return;
}
if ( line.length() == 0 )
{
break;
}
if ( getline == null )
{
getline = line;
}
if ( line.startsWith( "User-Agent: " ) )
{
agent = line.substring( "User-Agent: ".length() );
}
}
String excludedAgents = System.getProperty( "excludedAgents" );
if ( agent != null && excludedAgents != null )
{
StringTokenizer tk = new StringTokenizer( excludedAgents, "," );
while( tk.hasMoreTokens() )
{
if ( agent.indexOf( tk.nextToken() ) >= 0 )
{
writeHttpHeader( bw );
bw.write( "Bad agent: " + agent );
bw.flush();
return;
}
}
}
if ( getline.startsWith("GET /favicon.ico") )
{ {
return; return;
} }

View file

@ -84,15 +84,6 @@ public class ProfileUploadHandler
{ {
// Content-Type: text/plain;charset=UTF-8 // Content-Type: text/plain;charset=UTF-8
for(;;)
{
// headers
String line = ir.readLine();
if ( line == null ) break;
// blank line before content after headers
if ( line.length() == 0 )
{
int numChars = 0; int numChars = 0;
// Content-Length header is in bytes (!= characters for UTF8), // Content-Length header is in bytes (!= characters for UTF8),
@ -112,9 +103,6 @@ public class ProfileUploadHandler
if (numChars > MAX_LENGTH) if (numChars > MAX_LENGTH)
throw new IOException("Maximum number of characters exceeded (" + MAX_LENGTH + ", " + id + ")"); throw new IOException("Maximum number of characters exceeded (" + MAX_LENGTH + ", " + id + ")");
} }
break;
}
}
} }
private String toJSON( Map<String, String> data ) private String toJSON( Map<String, String> data )