Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for external SVG files on both IOS and Android #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions src/android/NanoHTTPD.java
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,10 @@ else if ( len < 1024 * 1024 )
}

res.addHeader( "Accept-Ranges", "bytes"); // Announce that the file server accepts partial content requestes

// Add CORS header
res.addHeader( "Access-Control-Allow-Origin", "*");

return res;
}

Expand All @@ -1104,30 +1108,35 @@ else if ( len < 1024 * 1024 )
static
{
StringTokenizer st = new StringTokenizer(
"css text/css "+
"htm text/html "+
"html text/html "+
"xml text/xml "+
"txt text/plain "+
"asc text/plain "+
"gif image/gif "+
"jpg image/jpeg "+
"jpeg image/jpeg "+
"png image/png "+
"mp3 audio/mpeg "+
"m3u audio/mpeg-url " +
"mp4 video/mp4 " +
"ogv video/ogg " +
"flv video/x-flv " +
"mov video/quicktime " +
"swf application/x-shockwave-flash " +
"js application/javascript "+
"pdf application/pdf "+
"doc application/msword "+
"ogg application/x-ogg "+
"zip application/octet-stream "+
"exe application/octet-stream "+
"class application/octet-stream " );
"css text/css "+
"htm text/html "+
"html text/html "+
"xml text/xml "+
"java java=text/x-java-source "+
"md text/plain "+
"txt text/plain "+
"asc text/plain "+
"gif image/gif "+
"jpg image/jpeg "+
"jpeg image/jpeg "+
"png image/png "+
"svg image/svg+xml "+
"mp3 audio/mpeg "+
"m3u audio/mpeg-url " +
"mp4 video/mp4 " +
"ogv video/ogg " +
"flv video/x-flv " +
"mov video/quicktime " +
"swf application/x-shockwave-flash " +
"js application/javascript "+
"pdf application/pdf "+
"doc application/msword "+
"ogg application/x-ogg "+
"zip application/octet-stream "+
"exe application/octet-stream "+
"class application/octet-stream "+
"m3u8 application/vnd.apple.mpegurl "+
"ts video/mp2t " );
while ( st.hasMoreTokens())
theMimeTypes.put( st.nextToken(), st.nextToken());
}
Expand Down
3 changes: 3 additions & 0 deletions src/ios/CocoaHttpd/HTTPConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,9 @@ - (void)sendResponseHeadersAndBody
}
}

// Add CORS header
[response setHeaderField:@"Access-Control-Allow-Origin" value:@"*"];

// Add optional lastModified header
if ([httpResponse respondsToSelector:@selector(lastModified)])
{
Expand Down
9 changes: 9 additions & 0 deletions src/ios/CocoaHttpd/Responses/HTTPFileResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,13 @@ - (void)dealloc

}


- (NSDictionary *)httpHeaders {
//HTTPLogTrace();
if ([[filePath pathExtension] isEqualToString:@"svg"]) {
return [NSDictionary dictionaryWithObject:@"image/svg+xml" forKey:@"Content-Type"];
}
return [NSDictionary new];
}

@end