improve downloading GPX+KML:
- "Content-Disposition: attachment" header with "filename" - specific mime-types resolves nrenner/brouter-web#6
This commit is contained in:
parent
5fd1e2e734
commit
2528ca67b6
3 changed files with 32 additions and 3 deletions
|
@ -105,7 +105,7 @@ public class RouteServer extends Thread
|
|||
else
|
||||
{
|
||||
OsmTrack track = cr.getFoundTrack();
|
||||
writeHttpHeader(bw, handler.getMimeType());
|
||||
writeHttpHeader(bw, handler.getMimeType(), handler.getFileName());
|
||||
if ( track != null )
|
||||
{
|
||||
bw.write( handler.formatTrack(track) );
|
||||
|
@ -211,11 +211,20 @@ public class RouteServer extends Thread
|
|||
}
|
||||
|
||||
private static void writeHttpHeader( BufferedWriter bw, String mimeType ) throws IOException
|
||||
{
|
||||
writeHttpHeader( bw, mimeType, null );
|
||||
}
|
||||
|
||||
private static void writeHttpHeader( BufferedWriter bw, String mimeType, String fileName ) throws IOException
|
||||
{
|
||||
// http-header
|
||||
bw.write( "HTTP/1.1 200 OK\n" );
|
||||
bw.write( "Connection: close\n" );
|
||||
bw.write( "Content-Type: " + mimeType + "; charset=utf-8\n" );
|
||||
if ( fileName != null )
|
||||
{
|
||||
bw.write( "Content-Disposition: attachment; filename=" + fileName + "\n" );
|
||||
}
|
||||
bw.write( "Access-Control-Allow-Origin: *\n" );
|
||||
bw.write( "\n" );
|
||||
}
|
||||
|
|
|
@ -26,4 +26,6 @@ public abstract class RequestHandler
|
|||
public abstract String formatTrack(OsmTrack track);
|
||||
|
||||
public abstract String getMimeType();
|
||||
|
||||
public abstract String getFileName();
|
||||
}
|
|
@ -133,9 +133,13 @@ public class ServerHandler extends RequestHandler {
|
|||
String format = params.get( "format" );
|
||||
if ( format != null )
|
||||
{
|
||||
if ( "gpx".equals( format ) || "kml".equals( format ) )
|
||||
if ( "gpx".equals( format ) )
|
||||
{
|
||||
result = "text/xml";
|
||||
result = "application/gpx+xml";
|
||||
}
|
||||
else if ( "kml".equals( format ) )
|
||||
{
|
||||
result = "application/vnd.google-earth.kml+xml";
|
||||
}
|
||||
else if ( "csv".equals( format ) )
|
||||
{
|
||||
|
@ -146,6 +150,20 @@ public class ServerHandler extends RequestHandler {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName()
|
||||
{
|
||||
String fileName = null;
|
||||
String format = params.get( "format" );
|
||||
|
||||
if ( format != null )
|
||||
{
|
||||
fileName = "brouter." + format;
|
||||
}
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readPosition( String vlon, String vlat, String name )
|
||||
{
|
||||
if ( vlon == null ) throw new IllegalArgumentException( "lon " + name + " not found in input" );
|
||||
|
|
Loading…
Reference in a new issue