ObjFW  Diff

Differences From Artifact [5ac9f0f46d]:

To Artifact [d46048ca78]:


310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
	  server: (OFHTTPServer*)server;
- (bool)socket: (OFTCPSocket*)socket
   didReadLine: (OFString*)line
     exception: (OFException*)exception;
- (bool)parseProlog: (OFString*)line;
- (bool)parseHeaders: (OFString*)line;
-      (bool)socket: (OFTCPSocket*)socket
  didReadIntoBuffer: (const char*)buffer
	     length: (size_t)length
	  exception: (OFException*)exception;
- (bool)sendErrorAndClose: (short)statusCode;
- (void)createResponse;
@end

@implementation OFHTTPServer_Connection







|







310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
	  server: (OFHTTPServer*)server;
- (bool)socket: (OFTCPSocket*)socket
   didReadLine: (OFString*)line
     exception: (OFException*)exception;
- (bool)parseProlog: (OFString*)line;
- (bool)parseHeaders: (OFString*)line;
-      (bool)socket: (OFTCPSocket*)socket
  didReadIntoBuffer: (char*)buffer
	     length: (size_t)length
	  exception: (OFException*)exception;
- (bool)sendErrorAndClose: (short)statusCode;
- (void)createResponse;
@end

@implementation OFHTTPServer_Connection
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

- (bool)parseHeaders: (OFString*)line
{
	OFString *key, *value;
	size_t pos;

	if ([line length] == 0) {
		size_t contentLength;

		@try {
			contentLength = (size_t)[[_headers
			    objectForKey: @"Content-Length"] decimalValue];
		} @catch (OFInvalidFormatException *e) {
			return [self sendErrorAndClose: 400];
		}

		if (contentLength > 0) {
			char *buffer;







|


|







453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

- (bool)parseHeaders: (OFString*)line
{
	OFString *key, *value;
	size_t pos;

	if ([line length] == 0) {
		intmax_t contentLength;

		@try {
			contentLength = [[_headers
			    objectForKey: @"Content-Length"] decimalValue];
		} @catch (OFInvalidFormatException *e) {
			return [self sendErrorAndClose: 400];
		}

		if (contentLength > 0) {
			char *buffer;
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549








550
551
552
553
554
555
556
		}
	}

	return true;
}

-      (bool)socket: (OFTCPSocket*)socket
  didReadIntoBuffer: (const char*)buffer
	     length: (size_t)length
	  exception: (OFException*)exception
{
	if ([socket isAtEndOfStream] || exception != nil)
		return false;

	[_entity addItems: buffer
		    count: length];

	if ([_entity count] >= _contentLength) {








		@try {
			[self createResponse];
		} @catch (OFWriteFailedException *e) {
			return false;
		}

		return false;







|










>
>
>
>
>
>
>
>







532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
		}
	}

	return true;
}

-      (bool)socket: (OFTCPSocket*)socket
  didReadIntoBuffer: (char*)buffer
	     length: (size_t)length
	  exception: (OFException*)exception
{
	if ([socket isAtEndOfStream] || exception != nil)
		return false;

	[_entity addItems: buffer
		    count: length];

	if ([_entity count] >= _contentLength) {
		/*
		 * Manually free the buffer here. While this is not required
		 * now as the async read is the only thing referencing self and
		 * the buffer is allocated on self, it is required once
		 * Connection: keep-alive is implemented.
		 */
		[self freeMemory: buffer];

		@try {
			[self createResponse];
		} @catch (OFWriteFailedException *e) {
			return false;
		}

		return false;