ObjFW  Diff

Differences From Artifact [0d964b4cba]:

To Artifact [36ad6829ee]:


44
45
46
47
48
49
50


51
52
53
54
55
56
57
#import "OFNotOpenException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
#import "OFUnsupportedVersionException.h"
#import "OFWriteFailedException.h"



#define REDIRECTS_DEFAULT 10

@interface OFHTTPClientRequestHandler: OFObject <OFTCPSocketDelegate>
{
@public
	OFHTTPClient *_client;







>
>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#import "OFNotOpenException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
#import "OFUnsupportedVersionException.h"
#import "OFWriteFailedException.h"

#import "socket_helpers.h"

#define REDIRECTS_DEFAULT 10

@interface OFHTTPClientRequestHandler: OFObject <OFTCPSocketDelegate>
{
@public
	OFHTTPClient *_client;
727
728
729
730
731
732
733

734
735
736
737
738
739
740
741
742
743
744
	}

	return self;
}

- (void)dealloc
{

	[self close];

	[_handler release];
	[_socket release];

	[super dealloc];
}

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







>
|


<







729
730
731
732
733
734
735
736
737
738
739

740
741
742
743
744
745
746
	}

	return self;
}

- (void)dealloc
{
	if (_socket != nil)
		[self close];

	[_handler release];


	[super dealloc];
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
		       length: (size_t)length
{
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799


800
801
802
803
804
805
806
{
	return _atEndOfStream;
}

- (void)close
{
	if (_socket == nil)
		return;

	if (_toWrite > 0)
		@throw [OFTruncatedDataException exception];

	_socket.delegate = _handler;
	[_socket asyncReadLine];

	[_socket release];
	_socket = nil;


}

- (int)fileDescriptorForWriting
{
	return _socket.fileDescriptorForWriting;
}
@end







|









>
>







785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
{
	return _atEndOfStream;
}

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

	if (_toWrite > 0)
		@throw [OFTruncatedDataException exception];

	_socket.delegate = _handler;
	[_socket asyncReadLine];

	[_socket release];
	_socket = nil;

	[super close];
}

- (int)fileDescriptorForWriting
{
	return _socket.fileDescriptorForWriting;
}
@end
815
816
817
818
819
820
821
822

823
824
825
826
827
828
829
	_socket = [sock retain];

	return self;
}

- (void)dealloc
{
	[_socket release];


	[super dealloc];
}

- (void)setHeaders: (OFDictionary *)headers
{
	OFString *contentLength;







|
>







819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
	_socket = [sock retain];

	return self;
}

- (void)dealloc
{
	if (_socket != nil)
		[self close];

	[super dealloc];
}

- (void)setHeaders: (OFDictionary *)headers
{
	OFString *contentLength;
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
				       length: length];

		if (ret > length)
			@throw [OFOutOfRangeException exception];

		_toRead -= ret;

		if (_toRead == 0) {
			_atEndOfStream = true;

			if (!_keepAlive) {
				[_socket release];
				_socket = nil;
			}
		}

		return ret;
	}

	/* Chunked */
	if (_toRead > 0) {
		if (length > _toRead)
			length = (size_t)_toRead;







|


<
<
<
<
<
<







883
884
885
886
887
888
889
890
891
892






893
894
895
896
897
898
899
				       length: length];

		if (ret > length)
			@throw [OFOutOfRangeException exception];

		_toRead -= ret;

		if (_toRead == 0)
			_atEndOfStream = true;







		return ret;
	}

	/* Chunked */
	if (_toRead > 0) {
		if (length > _toRead)
			length = (size_t)_toRead;
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
					@throw [OFInvalidServerReplyException
					    exception];
				}

				if (line.length > 0)
					@throw [OFInvalidServerReplyException
					    exception];
			} else {
				[_socket release];
				_socket = nil;
			}
		}

		objc_autoreleasePoolPop(pool);

		return 0;
	}







<
<
<







946
947
948
949
950
951
952



953
954
955
956
957
958
959
					@throw [OFInvalidServerReplyException
					    exception];
				}

				if (line.length > 0)
					@throw [OFInvalidServerReplyException
					    exception];



			}
		}

		objc_autoreleasePoolPop(pool);

		return 0;
	}
988
989
990
991
992
993
994



995
996
997
998
999
1000
1001
- (bool)hasDataInReadBuffer
{
	return (super.hasDataInReadBuffer || _socket.hasDataInReadBuffer);
}

- (void)close
{



	_atEndOfStream = false;

	[_socket release];
	_socket = nil;

	[super close];
}







>
>
>







984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
- (bool)hasDataInReadBuffer
{
	return (super.hasDataInReadBuffer || _socket.hasDataInReadBuffer);
}

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

	_atEndOfStream = false;

	[_socket release];
	_socket = nil;

	[super close];
}