ObjFW  Diff

Differences From Artifact [9ef3db2e96]:

To Artifact [f2c9b5d838]:

  • File src/OFHTTPRequest.m — part of check-in [8f810ecb7e] at 2018-08-11 14:00:46 on branch trunk — Change the layout of of_socket_address_t

    Instead of containing a struct sockaddr_storage - which does not exist
    on all supported platforms - it now contains a union of all struct
    sockaddr_* types.

    Additionally, if struct sockaddr_in6 does not exist, it is defined so
    that an IPv6 can be stored even if the system does not support IPv6. (user: js, size: 6168) [annotate] [blame] [check-ins using]


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
76
77
78
79
80
81
82

83
84
85
86
87
88
89







-







		return OF_HTTP_REQUEST_METHOD_CONNECT;

	@throw [OFInvalidFormatException exception];
}

@implementation OFHTTPRequest
@synthesize URL = _URL, method = _method, headers = _headers;
@synthesize remoteAddress = _remoteAddress;

+ (instancetype)request
{
	return [[[self alloc] init] autorelease];
}

+ (instancetype)requestWithURL: (OFURL *)URL
117
118
119
120
121
122
123
124
125
126
127










128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153







-



+
+
+
+
+
+
+
+
+
+










-
+







	return self;
}

- (void)dealloc
{
	[_URL release];
	[_headers release];
	[_remoteAddress release];

	[super dealloc];
}

- (void)setRemoteAddress: (const of_socket_address_t *)remoteAddress
{
	_remoteAddress = *remoteAddress;
}

- (const of_socket_address_t *)remoteAddress
{
	return &_remoteAddress;
}

- (id)copy
{
	OFHTTPRequest *copy = [[OFHTTPRequest alloc] init];

	@try {
		copy->_method = _method;
		copy->_protocolVersion = _protocolVersion;
		[copy setURL: _URL];
		[copy setHeaders: _headers];
		[copy setRemoteAddress: _remoteAddress];
		[copy setRemoteAddress: &_remoteAddress];
	} @catch (id e) {
		[copy release];
		@throw e;
	}

	return copy;
}
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196







-
+
















-
+







	request = object;

	if (request->_method != _method ||
	    request->_protocolVersion.major != _protocolVersion.major ||
	    request->_protocolVersion.minor != _protocolVersion.minor ||
	    ![request->_URL isEqual: _URL] ||
	    ![request->_headers isEqual: _headers] ||
	    ![request->_remoteAddress isEqual: _remoteAddress])
	    !of_socket_address_equal(&request->_remoteAddress, &_remoteAddress))
		return false;

	return true;
}

- (uint32_t)hash
{
	uint32_t hash;

	OF_HASH_INIT(hash);

	OF_HASH_ADD(hash, _method);
	OF_HASH_ADD(hash, _protocolVersion.major);
	OF_HASH_ADD(hash, _protocolVersion.minor);
	OF_HASH_ADD_HASH(hash, [_URL hash]);
	OF_HASH_ADD_HASH(hash, [_headers hash]);
	OF_HASH_ADD_HASH(hash, [_remoteAddress hash]);
	OF_HASH_ADD_HASH(hash, of_socket_address_hash(&_remoteAddress));

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion
244
245
246
247
248
249
250
251


252
253
254
255
256
257
252
253
254
255
256
257
258

259
260
261
262
263
264
265
266







-
+
+







	ret = [[OFString alloc] initWithFormat:
	    @"<%@:\n\tURL = %@\n"
	    @"\tMethod = %s\n"
	    @"\tHeaders = %@\n"
	    @"\tRemote address = %@\n"
	    @">",
	    [self class], _URL, method, indentedHeaders, _remoteAddress];
	    [self class], _URL, method, indentedHeaders,
	    of_socket_address_ip_string(&_remoteAddress, NULL)];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end