ObjFW  Diff

Differences From Artifact [b66ecb349c]:

To Artifact [eeb0db485d]:


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#import "OFDataArray.h"
#import "OFString.h"
#import "OFFile.h"
#import "OFURL.h"
#ifdef OF_HAVE_SOCKETS
# import "OFHTTPClient.h"
# import "OFHTTPRequest.h"
# import "OFHTTPRequestReply.h"
#endif
#import "OFDictionary.h"
#import "OFXMLElement.h"
#import "OFSystemInfo.h"

#ifdef OF_HAVE_SOCKETS
# import "OFHTTPRequestFailedException.h"







|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#import "OFDataArray.h"
#import "OFString.h"
#import "OFFile.h"
#import "OFURL.h"
#ifdef OF_HAVE_SOCKETS
# import "OFHTTPClient.h"
# import "OFHTTPRequest.h"
# import "OFHTTPResponse.h"
#endif
#import "OFDictionary.h"
#import "OFXMLElement.h"
#import "OFSystemInfo.h"

#ifdef OF_HAVE_SOCKETS
# import "OFHTTPRequestFailedException.h"
186
187
188
189
190
191
192
193
194
195
196
197
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

- initWithContentsOfURL: (OFURL*)URL
{
	void *pool;
#ifdef OF_HAVE_SOCKETS
	OFHTTPClient *client;
	OFHTTPRequest *request;
	OFHTTPRequestReply *reply;
	OFDictionary *headers;
	OFString *contentLength;
#endif
	Class c;

	c = [self class];
	[self release];

	pool = objc_autoreleasePoolPush();

	if ([[URL scheme] isEqual: @"file"]) {
		self = [[c alloc] initWithContentsOfFile: [URL path]];
		objc_autoreleasePoolPop(pool);
		return self;
	}

#ifdef OF_HAVE_SOCKETS
	client = [OFHTTPClient client];
	request = [OFHTTPRequest requestWithURL: URL];
	reply = [client performRequest: request];

	if ([reply statusCode] != 200)
		@throw [OFHTTPRequestFailedException
		    exceptionWithRequest: request
				   reply: reply];

	/*
	 * TODO: This can be optimized by allocating a data array with the
	 * capacity from the Content-Length header.
	 */
	self = [[reply readDataArrayTillEndOfStream] retain];

	headers = [reply headers];
	if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil)
		if ([self count] != (size_t)[contentLength decimalValue])
			@throw [OFTruncatedDataException exception];
#else
	@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
#endif








|



















|

|


|





|

|







186
187
188
189
190
191
192
193
194
195
196
197
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

- initWithContentsOfURL: (OFURL*)URL
{
	void *pool;
#ifdef OF_HAVE_SOCKETS
	OFHTTPClient *client;
	OFHTTPRequest *request;
	OFHTTPResponse *response;
	OFDictionary *headers;
	OFString *contentLength;
#endif
	Class c;

	c = [self class];
	[self release];

	pool = objc_autoreleasePoolPush();

	if ([[URL scheme] isEqual: @"file"]) {
		self = [[c alloc] initWithContentsOfFile: [URL path]];
		objc_autoreleasePoolPop(pool);
		return self;
	}

#ifdef OF_HAVE_SOCKETS
	client = [OFHTTPClient client];
	request = [OFHTTPRequest requestWithURL: URL];
	response = [client performRequest: request];

	if ([response statusCode] != 200)
		@throw [OFHTTPRequestFailedException
		    exceptionWithRequest: request
				response: response];

	/*
	 * TODO: This can be optimized by allocating a data array with the
	 * capacity from the Content-Length header.
	 */
	self = [[response readDataArrayTillEndOfStream] retain];

	headers = [response headers];
	if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil)
		if ([self count] != (size_t)[contentLength decimalValue])
			@throw [OFTruncatedDataException exception];
#else
	@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
#endif