ObjFW  Check-in [5854471001]

Overview
Comment:Include the complete result in an OFHTTPRequestFailedException.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 585447100192d956f82c9b9d3b47864556d871de6046dc613f596a2d2e4d6a68
User & Date: js on 2011-04-30 15:26:02
Other Links: manifest | tags
Context
2011-04-30
20:48
Update buildsys. check-in: 8a12f038aa user: js tags: trunk
15:26
Include the complete result in an OFHTTPRequestFailedException. check-in: 5854471001 user: js tags: trunk
2011-04-28
18:44
Optimize sending of headers in OFHTTPRequest. check-in: 9575887d67 user: js tags: trunk
Changes

Modified src/OFDataArray.m from [8cfd028dbb] to [0e2718679c].

150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
150
151
152
153
154
155
156

157
158
159
160
161
162
163
164







-
+







	request = [OFHTTPRequest requestWithURL: URL];
	result = [request perform];

	if ([result statusCode] != 200)
		@throw [OFHTTPRequestFailedException
		    newWithClass: [request class]
		     HTTPRequest: request
		      statusCode: [result statusCode]];
			  result: result];

	self = [[result data] retain];
	[pool release];
	return self;
}

- initWithBase64EncodedString: (OFString*)string

Modified src/OFHTTPRequest.m from [8d29aa8502] to [1fb93fc8c1].

283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
283
284
285
286
287
288
289







290
291
292
293
294
295
296







-
-
-
-
-
-
-







		    ![line hasPrefix: @"HTTP/1.1 "])
			@throw [OFInvalidServerReplyException
			    newWithClass: isa];

		status = (int)[[line substringFromIndex: 9
						toIndex: 12] decimalValue];

		if (status != 200 && status != 301 && status != 302 &&
		    status != 303)
			@throw [OFHTTPRequestFailedException
			    newWithClass: isa
			     HTTPRequest: self
			      statusCode: status];

		serverHeaders = [OFMutableDictionary dictionary];

		while ((line = [sock readLine]) != nil) {
			OFString *key, *value;
			const char *line_c = [line cString], *tmp;

			if ([line isEqual: @""])
390
391
392
393
394
395
396





397


398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413







414
415
416
417
418
419
420
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426







+
+
+
+
+
-
+
+
















+
+
+
+
+
+
+







		    [serverHeaders objectForKey: @"Content-Length"]) != nil) {
			intmax_t cl = [contentLengthHeader decimalValue];

			if (cl > SIZE_MAX)
				@throw [OFOutOfRangeException
				    newWithClass: isa];

			/*
			 * We only want to throw on these status codes as we
			 * will throw an OFHTTPRequestFailedException for all
			 * other status codes later.
			 */
			if (cl != bytesReceived)
			if (cl != bytesReceived && (status == 200 ||
			    status == 301 || status == 302 || status == 303))
				@throw [OFTruncatedDataException
				    newWithClass: isa];
		}

		/*
		 * Class swizzle the dictionary to be immutable. We pass it as
		 * OFDictionary*, so it can't be modified anyway. But not
		 * swizzling it would create a real copy each time -[copy] is
		 * called.
		 */
		serverHeaders->isa = [OFDictionary class];

		result = [[OFHTTPRequestResult alloc]
		    initWithStatusCode: status
			       headers: serverHeaders
				  data: data];

		if (status != 200 && status != 301 && status != 302 &&
		    status != 303)
			@throw [OFHTTPRequestFailedException
			    newWithClass: isa
			     HTTPRequest: self
				  result: result];
	} @finally {
		[pool release];
	}

	return [result autorelease];
}
@end

Modified src/OFString.m from [e3d5101e79] to [02548d1e5f].

730
731
732
733
734
735
736
737

738
739
740
741
742
743
744
730
731
732
733
734
735
736

737
738
739
740
741
742
743
744







-
+







	request = [OFHTTPRequest requestWithURL: URL];
	result = [request perform];

	if ([result statusCode] != 200)
		@throw [OFHTTPRequestFailedException
		    newWithClass: [request class]
		     HTTPRequest: request
		      statusCode: [result statusCode]];
			  result: result];

	if (encoding == OF_STRING_ENCODING_AUTODETECT &&
	    (contentType = [[result headers] objectForKey: @"Content-Type"])) {
		contentType = [[contentType mutableCopy] autorelease];
		[contentType lower];

		if ([contentType hasSuffix: @"charset=UTF-8"])

Modified src/exceptions/OFHTTPRequestFailedException.h from [35852f997f] to [583fdc4f7f].

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
61
62
63

64
65

66
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
61
62
63

64
65

66
67







+







-
+




-
+





-
+




-
+






-
+




-
+







-
+

-
+

 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"

@class OFHTTPRequest;
@class OFHTTPRequestResult;

/**
 * \brief An exception indicating that a HTTP request failed.
 */
@interface OFHTTPRequestFailedException: OFException
{
	OFHTTPRequest *HTTPRequest;
	short statusCode;
	OFHTTPRequestResult *result;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, nonatomic) OFHTTPRequest *HTTPRequest;
@property (readonly) short statusCode;
@property (readonly, nonatomic) OFHTTPRequestResult *result;
#endif

/**
 * \param class_ The class of the object which caused the exception
 * \param request The HTTP request which failed
 * \param code The status code of the fialed HTTP request
 * \param result The result of the failed HTTP request
 * \return A new HTTP request failed exception
 */
+ newWithClass: (Class)class_
   HTTPRequest: (OFHTTPRequest*)request
    statusCode: (short)code;
	result: (OFHTTPRequestResult*)result;

/**
 * Initializes an already allocated HTTP request failed exception
 *
 * \param class_ The class of the object which caused the exception
 * \param request The HTTP request which failed
 * \param code The status code of the fialed HTTP request
 * \param result The result of the failed HTTP request
 * \return A new HTTP request failed exception
 */
- initWithClass: (Class)class_
    HTTPRequest: (OFHTTPRequest*)request
     statusCode: (short)code;
	 result: (OFHTTPRequestResult*)result;

/**
 * \return The HTTP request which failed
 */
- (OFHTTPRequest*)HTTPRequest;

/**
 * \return The status code of the HTTP request
 * \return The result of the failed HTTP request
 */
- (short)statusCode;
- (OFHTTPRequestResult*)result;
@end

Modified src/exceptions/OFHTTPRequestFailedException.m from [c537d9db5f] to [f4379dee3a].

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
61
62
63

64
65
66
67
68
69
70
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
61
62
63
64
65
66
67
68
69
70
71







-
+



-
+












-
+





-
+











+







#import "OFAutoreleasePool.h"

#import "OFNotImplementedException.h"

@implementation OFHTTPRequestFailedException
+ newWithClass: (Class)class_
   HTTPRequest: (OFHTTPRequest*)request
    statusCode: (short)code
	result: (OFHTTPRequestResult*)result
{
	return [[self alloc] initWithClass: class_
			       HTTPRequest: request
				statusCode: code];
				    result: result];
}

- initWithClass: (Class)class_
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException newWithClass: c
					      selector: _cmd];
}

- initWithClass: (Class)class_
    HTTPRequest: (OFHTTPRequest*)request
     statusCode: (short)code
	 result: (OFHTTPRequestResult*)result_
{
	self = [super initWithClass: class_];

	@try {
		HTTPRequest = [request retain];
		statusCode = code;
		result = [result_ retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[HTTPRequest release];
	[result release];

	[super dealloc];
}

- (OFString*)description
{
	OFAutoreleasePool *pool;
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104

105
106

107
108
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104

105
106

107
108
109







-
+











-
+

-
+


		break;
	}

	pool = [[OFAutoreleasePool alloc] init];

	description = [[OFString alloc] initWithFormat:
	    @"A HTTP %s request in class %@ with URL %@ failed with code %d",
	    type, inClass, [HTTPRequest URL], statusCode];
	    type, inClass, [HTTPRequest URL], [result statusCode]];

	[pool release];

	return description;
}

- (OFHTTPRequest*)HTTPRequest
{
	return HTTPRequest;
}

- (short)statusCode
- (OFHTTPRequestResult*)result
{
	return statusCode;
	return result;
}
@end