robbiehanson / CocoaHTTPServer

A small, lightweight, embeddable HTTP server for Mac OS X or iOS applications
Other
5.6k stars 1.31k forks source link

Serving SVG images and assets. #106

Closed tobinharris closed 10 years ago

tobinharris commented 10 years ago

We struggled to find a solution for serving SVG image assets using CocoaHTTPServer. Eventually did this which worked well...

Basically we added this to the top of our view controller, although the monkey patch could be put somewhere more sensible :)

@interface HTTPFileResponse (Svg)
@end

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

@end
tobinharris commented 10 years ago

Closing.

allanGoldZhiKang commented 5 years ago

Closing.

After u create the category insert

import "HTTPFileResponse+Svg.h"

below

import "HTTPServer.h"