ObjFW  Check-in [629e8d915a]

Overview
Comment:OFHTTPRequest: Remove body
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 629e8d915a0b68533e5270d68ce99281a620aead599217459e7d93e37871d488
User & Date: js on 2018-02-25 02:55:40
Other Links: manifest | tags
Context
2018-02-25
04:21
OFObject: Bring +[new] back check-in: d6bf2b12dd user: js tags: trunk
02:55
OFHTTPRequest: Remove body check-in: 629e8d915a user: js tags: trunk
02:38
OFHTTPServer: Move the body out of the request check-in: f756fb2ff6 user: js tags: trunk
Changes

Modified src/OFHTTPRequest.h from [c71064978e] to [7ce0d63ac4].

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 */
@interface OFHTTPRequest: OFObject <OFCopying>
{
	OFURL *_URL;
	of_http_request_method_t _method;
	of_http_request_protocol_version_t _protocolVersion;
	OFDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _headers;
	OFData *_Nullable _body;
	OFString *_Nullable _remoteAddress;
}

/*!
 * @brief The URL of the HTTP request.
 */
@property (copy, nonatomic) OFURL *URL;







<







69
70
71
72
73
74
75

76
77
78
79
80
81
82
 */
@interface OFHTTPRequest: OFObject <OFCopying>
{
	OFURL *_URL;
	of_http_request_method_t _method;
	of_http_request_protocol_version_t _protocolVersion;
	OFDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _headers;

	OFString *_Nullable _remoteAddress;
}

/*!
 * @brief The URL of the HTTP request.
 */
@property (copy, nonatomic) OFURL *URL;
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

/*!
 * @brief The headers for the HTTP request.
 */
@property OF_NULLABLE_PROPERTY (copy, nonatomic)
    OFDictionary OF_GENERIC(OFString *, OFString *) *headers;

/*!
 * @brief The entity body of the HTTP request.
 */
@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFData *body;

/*!
 * @brief The remote address from which the request originates.
 */
@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *remoteAddress;

/*!
 * @brief Creates a new OFHTTPRequest.







<
<
<
<
<







98
99
100
101
102
103
104





105
106
107
108
109
110
111

/*!
 * @brief The headers for the HTTP request.
 */
@property OF_NULLABLE_PROPERTY (copy, nonatomic)
    OFDictionary OF_GENERIC(OFString *, OFString *) *headers;






/*!
 * @brief The remote address from which the request originates.
 */
@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *remoteAddress;

/*!
 * @brief Creates a new OFHTTPRequest.
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*!
 * @brief Sets the protocol version of the HTTP request to the version
 *	  described by the specified string.
 *
 * @param string A string describing an HTTP version
 */
- (void)setProtocolVersionFromString: (OFString *)string;

/*!
 * @brief Sets the entity body of the HTTP request to the specified string
 *	  encoded in UTF-8.
 *
 * @param string The string to use for the entity body
 */
- (void)setBodyFromString: (OFString *)string;

/*!
 * @brief Sets the entity body of the HTTP request to the specified string
 *	  encoded in the specified encoding.
 *
 * @param string The string to use for the entity body
 * @param encoding The encoding to encode the string with
 */
- (void)setBodyFromString: (OFString *)string
		 encoding: (of_string_encoding_t)encoding;
@end

#ifdef __cplusplus
extern "C" {
#endif
/*!
 * @brief Returns a C string describing the specified request method.







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







133
134
135
136
137
138
139


















140
141
142
143
144
145
146
/*!
 * @brief Sets the protocol version of the HTTP request to the version
 *	  described by the specified string.
 *
 * @param string A string describing an HTTP version
 */
- (void)setProtocolVersionFromString: (OFString *)string;


















@end

#ifdef __cplusplus
extern "C" {
#endif
/*!
 * @brief Returns a C string describing the specified request method.

Modified src/OFHTTPRequest.m from [470b55b5f2] to [9ef3db2e96].

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
	if (strcmp(string, "CONNECT") == 0)
		return OF_HTTP_REQUEST_METHOD_CONNECT;

	@throw [OFInvalidFormatException exception];
}

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

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








|







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
	if (strcmp(string, "CONNECT") == 0)
		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];
}

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
	return self;
}

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

	[super dealloc];
}

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

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

	return copy;







<














<







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
	return self;
}

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

	[_remoteAddress release];

	[super dealloc];
}

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

	@try {
		copy->_method = _method;
		copy->_protocolVersion = _protocolVersion;
		[copy setURL: _URL];
		[copy setHeaders: _headers];

		[copy setRemoteAddress: _remoteAddress];
	} @catch (id e) {
		[copy release];
		@throw e;
	}

	return copy;
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
189
190
191
	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->_body isEqual: _body] ||
	    ![request->_remoteAddress isEqual: _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, [_body hash]);
	OF_HASH_ADD_HASH(hash, [_remoteAddress hash]);

	OF_HASH_FINALIZE(hash);

	return hash;
}








<

















<







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
	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])
		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_FINALIZE(hash);

	return hash;
}

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
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
283
284
- (OFString *)protocolVersionString
{
	return [OFString stringWithFormat: @"%u.%u",
					   _protocolVersion.major,
					   _protocolVersion.minor];
}

- (void)setBodyFromString: (OFString *)string
{
	[self setBodyFromString: string
		       encoding: OF_STRING_ENCODING_UTF_8];
}

- (void)setBodyFromString: (OFString *)string
		 encoding: (of_string_encoding_t)encoding
{
	void *pool = objc_autoreleasePoolPush();

	[self setBody: [OFData
	    dataWithItems: [string cStringWithEncoding: encoding]
		    count: [string cStringLengthWithEncoding: encoding]]];

	objc_autoreleasePoolPop(pool);
}

- (OFString *)description
{
	void *pool = objc_autoreleasePoolPush();
	const char *method = of_http_request_method_to_string(_method);
	OFString *indentedHeaders, *indentedBody, *ret;

	indentedHeaders = [[_headers description]
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];
	indentedBody = [[_body description]
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];

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

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




|


<
<
<







<


|
<






228
229
230
231
232
233
234


















235
236
237
238
239
240
241



242
243
244
245
246
247
248

249
250
251

252
253
254
255
256
257
- (OFString *)protocolVersionString
{
	return [OFString stringWithFormat: @"%u.%u",
					   _protocolVersion.major,
					   _protocolVersion.minor];
}



















- (OFString *)description
{
	void *pool = objc_autoreleasePoolPush();
	const char *method = of_http_request_method_to_string(_method);
	OFString *indentedHeaders, *ret;

	indentedHeaders = [[_headers description]



	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];

	ret = [[OFString alloc] initWithFormat:
	    @"<%@:\n\tURL = %@\n"
	    @"\tMethod = %s\n"
	    @"\tHeaders = %@\n"

	    @"\tRemote address = %@\n"
	    @">",
	    [self class], _URL, method, indentedHeaders, _remoteAddress];


	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end