summaryrefslogtreecommitdiff
path: root/platform/ios/test/OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+JSON.m
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/test/OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+JSON.m')
-rw-r--r--platform/ios/test/OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+JSON.m31
1 files changed, 31 insertions, 0 deletions
diff --git a/platform/ios/test/OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+JSON.m b/platform/ios/test/OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+JSON.m
new file mode 100644
index 0000000000..aebcb99080
--- /dev/null
+++ b/platform/ios/test/OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+JSON.m
@@ -0,0 +1,31 @@
+//
+// OHHTTPStubsResponse+JSON.m
+// OHHTTPStubs
+//
+// Created by Olivier Halligon on 01/09/13.
+// Copyright (c) 2013 AliSoftware. All rights reserved.
+//
+
+#import "OHHTTPStubsResponse+JSON.h"
+
+@implementation OHHTTPStubsResponse (JSON)
+
+/*! @name Building a response from JSON objects */
+
++ (instancetype)responseWithJSONObject:(id)jsonObject
+ statusCode:(int)statusCode
+ headers:(NSDictionary *)httpHeaders
+{
+ if (!httpHeaders[@"Content-Type"])
+ {
+ NSMutableDictionary* mutableHeaders = [NSMutableDictionary dictionaryWithDictionary:httpHeaders];
+ mutableHeaders[@"Content-Type"] = @"application/json";
+ httpHeaders = [NSDictionary dictionaryWithDictionary:mutableHeaders]; // make immutable again
+ }
+
+ return [self responseWithData:[NSJSONSerialization dataWithJSONObject:jsonObject options:0 error:nil]
+ statusCode:statusCode
+ headers:httpHeaders];
+}
+
+@end