ObjFW  Diff

Differences From Artifact [46acd12d86]:

To Artifact [ef85fc1d98]:


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
61

62
63

64
65

66
67

68
69

70
71

72
73

74
75

76
77
78
79
80
81
82
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

61
62

63
64

65
66

67
68

69
70

71
72

73
74

75
76
77
78
79
80
81
82







-
+


-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+






-
-
+
+


-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+








#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFUnsupportedVersionException.h"

const char *
of_http_request_method_to_string(of_http_request_method_t method)
OFHTTPRequestMethodName(OFHTTPRequestMethod method)
{
	switch (method) {
	case OF_HTTP_REQUEST_METHOD_OPTIONS:
	case OFHTTPRequestMethodOptions:
		return "OPTIONS";
	case OF_HTTP_REQUEST_METHOD_GET:
	case OFHTTPRequestMethodGet:
		return "GET";
	case OF_HTTP_REQUEST_METHOD_HEAD:
	case OFHTTPRequestMethodHead:
		return "HEAD";
	case OF_HTTP_REQUEST_METHOD_POST:
	case OFHTTPRequestMethodPost:
		return "POST";
	case OF_HTTP_REQUEST_METHOD_PUT:
	case OFHTTPRequestMethodPut:
		return "PUT";
	case OF_HTTP_REQUEST_METHOD_DELETE:
	case OFHTTPRequestMethodDelete:
		return "DELETE";
	case OF_HTTP_REQUEST_METHOD_TRACE:
	case OFHTTPRequestMethodTrace:
		return "TRACE";
	case OF_HTTP_REQUEST_METHOD_CONNECT:
	case OFHTTPRequestMethodConnect:
		return "CONNECT";
	}

	return NULL;
}

of_http_request_method_t
of_http_request_method_from_string(OFString *string)
OFHTTPRequestMethod
OFHTTPRequestMethodParseName(OFString *string)
{
	if ([string isEqual: @"OPTIONS"])
		return OF_HTTP_REQUEST_METHOD_OPTIONS;
		return OFHTTPRequestMethodOptions;
	if ([string isEqual: @"GET"])
		return OF_HTTP_REQUEST_METHOD_GET;
		return OFHTTPRequestMethodGet;
	if ([string isEqual: @"HEAD"])
		return OF_HTTP_REQUEST_METHOD_HEAD;
		return OFHTTPRequestMethodHead;
	if ([string isEqual: @"POST"])
		return OF_HTTP_REQUEST_METHOD_POST;
		return OFHTTPRequestMethodPost;
	if ([string isEqual: @"PUT"])
		return OF_HTTP_REQUEST_METHOD_PUT;
		return OFHTTPRequestMethodPut;
	if ([string isEqual: @"DELETE"])
		return OF_HTTP_REQUEST_METHOD_DELETE;
		return OFHTTPRequestMethodDelete;
	if ([string isEqual: @"TRACE"])
		return OF_HTTP_REQUEST_METHOD_TRACE;
		return OFHTTPRequestMethodTrace;
	if ([string isEqual: @"CONNECT"])
		return OF_HTTP_REQUEST_METHOD_CONNECT;
		return OFHTTPRequestMethodConnect;

	@throw [OFInvalidArgumentException exception];
}

@implementation OFHTTPRequest
@synthesize URL = _URL, method = _method, headers = _headers;

90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104







-
+







	return [[[self alloc] initWithURL: URL] autorelease];
}

- (instancetype)init
{
	self = [super init];

	_method = OF_HTTP_REQUEST_METHOD_GET;
	_method = OFHTTPRequestMethodGet;
	_protocolVersion.major = 1;
	_protocolVersion.minor = 1;

	return self;
}

- (instancetype)initWithURL: (OFURL *)URL
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233







-
+










-
+









-
+







		OF_HASH_ADD_HASH(hash, OFSocketAddressHash(&_remoteAddress));

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion
- (void)setProtocolVersion: (OFHTTPRequestProtocolVersion)protocolVersion
{
	if (protocolVersion.major != 1 || protocolVersion.minor > 1)
		@throw [OFUnsupportedVersionException exceptionWithVersion:
		    [OFString stringWithFormat: @"%hhu.%hhu",
						protocolVersion.major,
						protocolVersion.minor]];

	_protocolVersion = protocolVersion;
}

- (of_http_request_protocol_version_t)protocolVersion
- (OFHTTPRequestProtocolVersion)protocolVersion
{
	return _protocolVersion;
}

- (void)setProtocolVersionString: (OFString *)string
{
	void *pool = objc_autoreleasePoolPush();
	OFArray *components = [string componentsSeparatedByString: @"."];
	unsigned long long major, minor;
	of_http_request_protocol_version_t protocolVersion;
	OFHTTPRequestProtocolVersion protocolVersion;

	if (components.count != 2)
		@throw [OFInvalidFormatException exception];

	major = [components.firstObject unsignedLongLongValue];
	minor = [components.lastObject unsignedLongLongValue];

248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262







-
+







					   _protocolVersion.major,
					   _protocolVersion.minor];
}

- (OFString *)description
{
	void *pool = objc_autoreleasePoolPush();
	const char *method = of_http_request_method_to_string(_method);
	const char *method = OFHTTPRequestMethodName(_method);
	OFString *indentedHeaders, *remoteAddress, *ret;

	indentedHeaders = [_headers.description
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];

	if (_hasRemoteAddress)