-
Notifications
You must be signed in to change notification settings - Fork 0
/
OCGIHeader.m
60 lines (53 loc) · 1.52 KB
/
OCGIHeader.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#import <Foundation/Foundation.h>
#include <stdio.h>
#import "OCGIEncoding.h"
#import "OCGIHeader.h"
@implementation OCGIHeader
+(void) location:(NSString *)redirectUrl
{
cgiHeaderLocation((char *)[redirectUrl cStringUsingEncoding:OCGI_ENCODING]);
}
+(void) status:(NSNumber *)status message:(NSString *)statusMessage
{
/* Originally, cgic append two lines of newline to
the output of the header of a HTTP response.
We may use multiple header informations in a
response; therefore, we write our own code. */
fprintf(stdout, "Status: %d %s\n",
[status intValue],
(char *)[statusMessage cStringUsingEncoding:OCGI_ENCODING]);
}
+(void) contentType:(NSString *)mimeType
{
/* Originally, cgic append two lines of newline to
the output of the header of a HTTP response.
We may use multiple header informations in a
response; therefore, we write our own code. */
fprintf(stdout, "Content-type: %s\n",
(char *)[mimeType cStringUsingEncoding:OCGI_ENCODING]);
}
+(void) ok
{
[[self class]
status: [NSNumber numberWithInt: 200]
message: OCGI_HTTP_STATUS_200];
}
+(void) notFound
{
[[self class]
status: [NSNumber numberWithInt: 404]
message: OCGI_HTTP_STATUS_404];
}
+(void) internalServerError
{
[[self class]
status: [NSNumber numberWithInt: 500]
message: OCGI_HTTP_STATUS_500];
}
+(void) forbidden
{
[[self class]
status: [NSNumber numberWithInt: 403]
message: OCGI_HTTP_STATUS_403];
}
@end