robbiehanson / CocoaHTTPServer

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

how to set the response's content_type? #187

Open bellazhouyi opened 7 years ago

bellazhouyi commented 7 years ago

i want add content_type to response,but i don't know how to added? thanks to answer the question.

hkalexling commented 6 years ago

Just subclass HTTPDataResponse. For example:

// JSONHTTPResponse.h

#import <Cocoa/Cocoa.h>
#import <CocoaHTTPServer/HTTPDataResponse.h>

@interface JSONHTTPResponse : HTTPDataResponse

@end
// JSONHTTPResponse.m

#import "JSONHTTPResponse.h"

@implementation JSONHTTPResponse

- (NSDictionary *)httpHeaders {
    return @{@"Content-Type": @"application/json"};
}

@end
bellazhouyi commented 6 years ago

Thanks