ObjFW  Diff

Differences From Artifact [3efdaebeee]:

To Artifact [36dd983976]:


29
30
31
32
33
34
35

36
37
38


39
40
41
42
43
44
45
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48







+



+
+







#import "OFHTTPResponse.h"
#import "OFTCPSocket.h"
#import "OFTimer.h"

#import "OFAlreadyConnectedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotConnectedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFWriteFailedException.h"

#import "socket_helpers.h"

#define BUFFER_SIZE 1024

/*
 * FIXME: Key normalization replaces headers like "DNT" with "Dnt".
 * FIXME: Errors are not reported to the user.
 */
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184







-
+







				       freeWhenDone: true];
}

@interface OFHTTPServerResponse: OFHTTPResponse
{
	OFTCPSocket *_socket;
	OFHTTPServer *_server;
	bool _chunked, _headersSent, _closed;
	bool _chunked, _headersSent;
}

- initWithSocket: (OFTCPSocket*)socket
	  server: (OFHTTPServer*)server;
@end

@implementation OFHTTPServerResponse
189
190
191
192
193
194
195
196
197


198
199
200
201
202
203
204
205
206
192
193
194
195
196
197
198


199
200
201

202
203
204
205
206
207
208







-
-
+
+

-







	_server = [server retain];

	return self;
}

- (void)dealloc
{
	if (!_closed)
		[self close];
	if (_socket != nil)
		[self close];	/* includes [_socket release] */

	[_socket release];
	[_server release];

	[super dealloc];
}

- (void)OF_sendHeaders
{
234
235
236
237
238
239
240



241
242
243
244
245
246
247
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252







+
+
+







}

- (void)lowlevelWriteBuffer: (const void*)buffer
		     length: (size_t)length
{
	void *pool;

	if (_socket == nil)
		@throw [OFNotConnectedException exceptionWithSocket: self];

	if (!_headersSent)
		[self OF_sendHeaders];

	if (!_chunked) {
		[_socket writeBuffer: buffer
			      length: length];
		return;
255
256
257
258
259
260
261



262
263
264
265
266
267
268
269
270


271
272
273
274
275



276
277
278
279
280
281
282
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276


277
278

279
280
281
282
283
284
285
286
287
288
289
290
291
292







+
+
+







-
-
+
+
-




+
+
+







		      length: length];
	[_socket writeBuffer: "\r\n"
		      length: 2];
}

- (void)close
{
	if (_socket == nil)
		@throw [OFNotConnectedException exceptionWithSocket: self];

	if (!_headersSent)
		[self OF_sendHeaders];

	if (_chunked)
		[_socket writeBuffer: "0\r\n\r\n"
			      length: 5];

	[_socket close];

	[_socket release];
	_socket = nil;
	_closed = true;
}

- (int)fileDescriptorForWriting
{
	if (_socket == nil)
		return INVALID_SOCKET;

	return [_socket fileDescriptorForWriting];
}
@end

@interface OFHTTPServer_Connection: OFObject
{
	OFTCPSocket *_socket;
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
568
569
570
571
572
573
574

575
576
577
578
579
580
581







-








	[_socket writeFormat: @"HTTP/1.1 %d %s\r\n"
			      @"Date: %@\r\n"
			      @"Server: %@\r\n"
			      @"\r\n",
			      statusCode, statusCodeToString(statusCode),
			      date, [_server name]];
	[_socket close];

	return false;
}

- (void)createResponse
{
	OFURL *URL;