handle CORS preflight request for profile upload (Safari)
This commit is contained in:
parent
062702c5a3
commit
99fb471c26
1 changed files with 31 additions and 10 deletions
|
@ -66,6 +66,17 @@ public class RouteServer extends Thread
|
||||||
handler = new ServerHandler( serviceContext, params );
|
handler = new ServerHandler( serviceContext, params );
|
||||||
}
|
}
|
||||||
else if ( url.startsWith( PROFILE_UPLOAD_URL ) )
|
else if ( url.startsWith( PROFILE_UPLOAD_URL ) )
|
||||||
|
{
|
||||||
|
if ( getline.startsWith("OPTIONS") )
|
||||||
|
{
|
||||||
|
// handle CORS preflight request (Safari)
|
||||||
|
String corsHeaders = "Access-Control-Allow-Methods: GET, POST\n"
|
||||||
|
+ "Access-Control-Allow-Headers: Content-Type\n";
|
||||||
|
writeHttpHeader( bw, "text/plain", null, corsHeaders );
|
||||||
|
bw.flush();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
writeHttpHeader(bw, "application/json");
|
writeHttpHeader(bw, "application/json");
|
||||||
|
|
||||||
|
@ -82,6 +93,7 @@ public class RouteServer extends Thread
|
||||||
bw.flush();
|
bw.flush();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException( "unknown request syntax: " + getline );
|
throw new IllegalArgumentException( "unknown request syntax: " + getline );
|
||||||
|
@ -213,6 +225,11 @@ public class RouteServer extends Thread
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeHttpHeader( BufferedWriter bw, String mimeType, String fileName ) throws IOException
|
private static void writeHttpHeader( BufferedWriter bw, String mimeType, String fileName ) throws IOException
|
||||||
|
{
|
||||||
|
writeHttpHeader( bw, mimeType, fileName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeHttpHeader( BufferedWriter bw, String mimeType, String fileName, String headers ) throws IOException
|
||||||
{
|
{
|
||||||
// http-header
|
// http-header
|
||||||
bw.write( "HTTP/1.1 200 OK\n" );
|
bw.write( "HTTP/1.1 200 OK\n" );
|
||||||
|
@ -223,6 +240,10 @@ public class RouteServer extends Thread
|
||||||
bw.write( "Content-Disposition: attachment; filename=" + fileName + "\n" );
|
bw.write( "Content-Disposition: attachment; filename=" + fileName + "\n" );
|
||||||
}
|
}
|
||||||
bw.write( "Access-Control-Allow-Origin: *\n" );
|
bw.write( "Access-Control-Allow-Origin: *\n" );
|
||||||
|
if ( headers != null )
|
||||||
|
{
|
||||||
|
bw.write( headers );
|
||||||
|
}
|
||||||
bw.write( "\n" );
|
bw.write( "\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue