ObjFW  Diff

Differences From Artifact [3d2d594ca8]:

To Artifact [b30a887ade]:


18
19
20
21
22
23
24


25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include "config.h"

#include <errno.h>
#include <string.h>

#import "OFHTTPClient.h"


#import "OFHTTPRequest.h"
#import "OFHTTPResponse.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFTCPSocket.h"
#import "OFDictionary.h"
#import "OFData.h"

#import "OFAlreadyConnectedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFNotImplementedException.h"







>
>


|
|

<
|







18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39

#include "config.h"

#include <errno.h>
#include <string.h>

#import "OFHTTPClient.h"
#import "OFData.h"
#import "OFDictionary.h"
#import "OFHTTPRequest.h"
#import "OFHTTPResponse.h"
#import "OFNumber.h"
#import "OFString.h"
#import "OFTCPSocket.h"

#import "OFURL.h"

#import "OFAlreadyConnectedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFNotImplementedException.h"
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

static OFString *
constructRequestString(OFHTTPRequest *request)
{
	void *pool = objc_autoreleasePoolPush();
	of_http_request_method_t method = [request method];
	OFURL *URL = [request URL];
	OFString *scheme = [URL scheme], *path = [URL path];
	OFString *user = [URL user], *password = [URL password];
	OFData *body = [request body];
	OFMutableString *requestString;
	OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers;
	OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator;
	OFString *key, *object;








|







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

static OFString *
constructRequestString(OFHTTPRequest *request)
{
	void *pool = objc_autoreleasePoolPush();
	of_http_request_method_t method = [request method];
	OFURL *URL = [request URL];
	OFString *path = [URL path];
	OFString *user = [URL user], *password = [URL password];
	OFData *body = [request body];
	OFMutableString *requestString;
	OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers;
	OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator;
	OFString *key, *object;

106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
	[requestString appendString: @"\r\n"];

	headers = [[[request headers] mutableCopy] autorelease];
	if (headers == nil)
		headers = [OFMutableDictionary dictionary];

	if ([headers objectForKey: @"Host"] == nil) {
		if (([scheme isEqual: @"http"] && [URL port] != 80) ||
		    ([scheme isEqual: @"https"] && [URL port] != 443)) {

			OFString *host = [OFString stringWithFormat:
			    @"%@:%d", [URL host], [URL port]];

			[headers setObject: host
				    forKey: @"Host"];
		} else
			[headers setObject: [URL host]
				    forKey: @"Host"];
	}







|
|
>

|







107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
	[requestString appendString: @"\r\n"];

	headers = [[[request headers] mutableCopy] autorelease];
	if (headers == nil)
		headers = [OFMutableDictionary dictionary];

	if ([headers objectForKey: @"Host"] == nil) {
		OFNumber *port = [URL port];

		if (port != nil) {
			OFString *host = [OFString stringWithFormat:
			    @"%@:%@", [URL host], port];

			[headers setObject: host
				    forKey: @"Host"];
		} else
			[headers setObject: [URL host]
				    forKey: @"Host"];
	}
705
706
707
708
709
710
711


712
713
714
715
716
717
718
719
720

721
722

723





724
725
726
727
728
729
730
731
732
		[self closeAndReconnect];
}

- (void)closeAndReconnect
{
	OFURL *URL = [_request URL];
	OFTCPSocket *sock;



	[_client close];

	if ([[URL scheme] isEqual: @"https"]) {
		if (of_tls_socket_class == Nil)
			@throw [OFUnsupportedProtocolException
			    exceptionWithURL: URL];

		sock = [[[of_tls_socket_class alloc] init] autorelease];

	} else
		sock = [OFTCPSocket socket];







	[sock asyncConnectToHost: [URL host]
			    port: [URL port]
			  target: self
			selector: @selector(socketDidConnect:context:
				      exception:)
			 context: nil];
}
@end








>
>









>
|

>
|
>
>
>
>
>

|







707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
		[self closeAndReconnect];
}

- (void)closeAndReconnect
{
	OFURL *URL = [_request URL];
	OFTCPSocket *sock;
	uint16_t port;
	OFNumber *URLPort;

	[_client close];

	if ([[URL scheme] isEqual: @"https"]) {
		if (of_tls_socket_class == Nil)
			@throw [OFUnsupportedProtocolException
			    exceptionWithURL: URL];

		sock = [[[of_tls_socket_class alloc] init] autorelease];
		port = 443;
	} else {
		sock = [OFTCPSocket socket];
		port = 80;
	}

	URLPort = [URL port];
	if (URLPort != nil)
		port = [URLPort uInt16Value];

	[sock asyncConnectToHost: [URL host]
			    port: port
			  target: self
			selector: @selector(socketDidConnect:context:
				      exception:)
			 context: nil];
}
@end