Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -329,11 +329,11 @@ OFString *scheme = [URL scheme]; of_http_request_method_t method = [request method]; OFMutableString *requestString; OFString *user, *password; OFDictionary *headers = [request headers]; - OFDataArray *entity = [request entity]; + OFDataArray *body = [request body]; OFTCPSocket *socket; OFHTTPClientResponse *response; OFString *line, *version, *redirect, *connectionHeader; bool keepAlive; OFMutableDictionary *serverHeaders; @@ -422,15 +422,15 @@ if ([headers objectForKey: @"User-Agent"] == nil) [requestString appendString: @"User-Agent: Something using ObjFW " @"\r\n"]; - if (entity != nil) { + if (body != nil) { if ([headers objectForKey: @"Content-Length"] == nil) [requestString appendFormat: @"Content-Length: %zd\r\n", - [entity itemSize] * [entity count]]; + [body itemSize] * [body count]]; if ([headers objectForKey: @"Content-Type"] == nil) [requestString appendString: @"Content-Type: application/x-www-form-urlencoded; " @"charset=UTF-8\r\n"]; @@ -458,13 +458,13 @@ /* Reconnect in case a keep-alive connection timed out */ socket = [self OF_closeAndCreateSocketForRequest: request]; [socket writeString: requestString]; } - if (entity != nil) - [socket writeBuffer: [entity items] - length: [entity count] * [entity itemSize]]; + if (body != nil) + [socket writeBuffer: [body items] + length: [body count] * [body itemSize]]; @try { line = [socket readLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exception]; @@ -477,14 +477,14 @@ */ if (line == nil) { socket = [self OF_closeAndCreateSocketForRequest: request]; [socket writeString: requestString]; - if (entity != nil) - [socket writeBuffer: [entity items] - length: [entity count] * - [entity itemSize]]; + if (body != nil) + [socket writeBuffer: [body items] + length: [body count] * + [body itemSize]]; @try { line = [socket readLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exception]; @@ -632,11 +632,11 @@ OFHTTPRequest *newRequest; newRequest = [OFHTTPRequest requestWithURL: newURL]; [newRequest setMethod: method]; [newRequest setHeaders: headers]; - [newRequest setEntity: entity]; + [newRequest setBody: body]; /* * 303 means the request should be converted to a GET * request before redirection. This also means stripping * the entity of the request. @@ -658,11 +658,11 @@ forKey: key]; [newRequest setMethod: OF_HTTP_REQUEST_METHOD_GET]; [newRequest setHeaders: newHeaders]; - [newRequest setEntity: nil]; + [newRequest setBody: nil]; } [newRequest retain]; objc_autoreleasePoolPop(pool); [newRequest autorelease]; Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -72,20 +72,20 @@ { OFURL *_URL; of_http_request_method_t _method; of_http_request_protocol_version_t _protocolVersion; OFDictionary *_headers; - OFDataArray *_entity; + OFDataArray *_body; OFString *_remoteAddress; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFURL *URL; @property of_http_request_method_t method; @property of_http_request_protocol_version_t protocolVersion; @property (copy) OFDictionary *headers; -@property (retain) OFDataArray *entity; +@property (retain) OFDataArray *body; @property (copy) OFString *remoteAddress; #endif /*! * @brief Creates a new OFHTTPRequest. @@ -182,38 +182,38 @@ - (OFDictionary*)headers; /*! * @brief Sets the entity body of the HTTP request. * - * @param entity The entity body of the HTTP request + * @param body The entity body of the HTTP request */ -- (void)setEntity: (OFDataArray*)entity; +- (void)setBody: (OFDataArray*)body; /*! * @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)setEntityFromString: (OFString*)string; +- (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)setEntityFromString: (OFString*)string - encoding: (of_string_encoding_t)encoding; +- (void)setBodyFromString: (OFString*)string + encoding: (of_string_encoding_t)encoding; /*! * @brief Returns the entity body of the HTTP request. * * @return The entity body of the HTTP request */ -- (OFDataArray*)entity; +- (OFDataArray*)body; /*! * @brief Sets the remote address from which the request originates. * * @param remoteAddress The remote address from which the request originates Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -115,11 +115,11 @@ - (void)dealloc { [_URL release]; [_headers release]; - [_entity release]; + [_body release]; [_remoteAddress release]; [super dealloc]; } @@ -130,11 +130,11 @@ @try { copy->_method = _method; copy->_protocolVersion = _protocolVersion; [copy setURL: _URL]; [copy setHeaders: _headers]; - [copy setEntity: _entity]; + [copy setBody: _body]; [copy setRemoteAddress: _remoteAddress]; } @catch (id e) { [copy release]; @throw e; } @@ -154,11 +154,11 @@ if (request->_method != _method || request->_protocolVersion.major != _protocolVersion.major || request->_protocolVersion.minor != _protocolVersion.minor || ![request->_URL isEqual: _URL] || ![request->_headers isEqual: _headers] || - ![request->_entity isEqual: _entity] || + ![request->_body isEqual: _body] || ![request->_remoteAddress isEqual: _remoteAddress]) return false; return true; } @@ -172,11 +172,11 @@ 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, [_entity hash]); + OF_HASH_ADD_HASH(hash, [_body hash]); OF_HASH_ADD_HASH(hash, [_remoteAddress hash]); OF_HASH_FINALIZE(hash); return hash; @@ -256,37 +256,37 @@ - (OFDictionary*)headers { OF_GETTER(_headers, true) } -- (void)setEntity: (OFDataArray*)entity -{ - OF_SETTER(_entity, entity, true, 0) -} - -- (void)setEntityFromString: (OFString*)string -{ - [self setEntityFromString: string - encoding: OF_STRING_ENCODING_UTF_8]; -} - -- (void)setEntityFromString: (OFString*)string - encoding: (of_string_encoding_t)encoding -{ - void *pool = objc_autoreleasePoolPush(); - OFDataArray *entity = [OFDataArray dataArray]; - - [entity addItems: [string cStringWithEncoding: encoding] - count: [string cStringLengthWithEncoding: encoding]]; - [self setEntity: entity]; +- (void)setBody: (OFDataArray*)body +{ + OF_SETTER(_body, body, true, 0) +} + +- (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(); + OFDataArray *body = [OFDataArray dataArray]; + + [body addItems: [string cStringWithEncoding: encoding] + count: [string cStringLengthWithEncoding: encoding]]; + [self setBody: body]; objc_autoreleasePoolPop(pool); } -- (OFDataArray*)entity +- (OFDataArray*)body { - OF_GETTER(_entity, true) + OF_GETTER(_body, true) } - (void)setRemoteAddress: (OFString*)remoteAddress { OF_SETTER(_remoteAddress, remoteAddress, true, 1) @@ -299,29 +299,29 @@ - (OFString*)description { void *pool = objc_autoreleasePoolPush(); const char *method = of_http_request_method_to_string(_method); - OFString *indentedHeaders, *indentedEntity, *ret; + OFString *indentedHeaders, *indentedBody, *ret; indentedHeaders = [[_headers description] stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; - indentedEntity = [[_entity description] + indentedBody = [[_body description] stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; ret = [[OFString alloc] initWithFormat: @"<%@:\n\tURL = %@\n" @"\tMethod = %s\n" @"\tHeaders = %@\n" - @"\tEntity = %@\n" + @"\tBody = %@\n" @"\tRemote address = %@\n" @">", - [self class], _URL, method, indentedHeaders, indentedEntity, + [self class], _URL, method, indentedHeaders, indentedBody, _remoteAddress]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -301,11 +301,11 @@ of_http_request_method_t _method; OFString *_host, *_path; uint16_t _port; OFMutableDictionary *_headers; size_t _contentLength; - OFDataArray *_entity; + OFDataArray *_body; } - initWithSocket: (OFTCPSocket*)socket server: (OFHTTPServer*)server; - (bool)socket: (OFTCPSocket*)socket @@ -354,11 +354,11 @@ [_timer release]; [_host release]; [_path release]; [_headers release]; - [_entity release]; + [_body release]; [super dealloc]; } - (bool)socket: (OFTCPSocket*)socket @@ -468,11 +468,11 @@ if (contentLength > 0) { char *buffer; buffer = [self allocMemoryWithSize: BUFFER_SIZE]; - _entity = [[OFDataArray alloc] init]; + _body = [[OFDataArray alloc] init]; [_socket asyncReadIntoBuffer: buffer length: BUFFER_SIZE target: self selector: @selector(socket: @@ -541,14 +541,14 @@ exception: (OFException*)exception { if ([socket isAtEndOfStream] || exception != nil) return false; - [_entity addItems: buffer - count: length]; + [_body addItems: buffer + count: length]; - if ([_entity count] >= _contentLength) { + if ([_body 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. @@ -626,11 +626,11 @@ request = [OFHTTPRequest requestWithURL: URL]; [request setMethod: _method]; [request setProtocolVersion: (of_http_request_protocol_version_t){ 1, _HTTPMinorVersion }]; [request setHeaders: _headers]; - [request setEntity: _entity]; + [request setBody: _body]; [request setRemoteAddress: [_socket remoteAddress]]; response = [[[OFHTTPServerResponse alloc] initWithSocket: _socket server: _server] autorelease]; Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -53,11 +53,11 @@ OFArray *_URLs; size_t _URLIndex; int _errorCode; OFString *_outputPath; bool _continue, _detectFileName, _quiet; - OFDataArray *_entity; + OFDataArray *_body; of_http_request_method_t _method; OFMutableDictionary *_clientHeaders; OFHTTPClient *_HTTPClient; char *_buffer; OFStream *_output; @@ -76,12 +76,12 @@ [OFApplication programName]]; if (full) [stream writeString: @"\nOptions:\n" + @" -b Specify the file to send as body\n" @" -c Continue download of existing file\n" - @" -e Specify the file to send as entity\n" @" -h Show this help\n" @" -H Add a header (e.g. X-Foo:Bar)\n" @" -m Set the method of the HTTP request\n" @" -o Specify output file name\n" @" -O Do a HEAD request to detect file name\n" @@ -136,14 +136,14 @@ [_clientHeaders setObject: value forKey: name]; } -- (void)setEntity: (OFString*)entity +- (void)setBody: (OFString*)body { - [_entity release]; - _entity = [[OFDataArray alloc] initWithContentsOfFile: entity]; + [_body release]; + _body = [[OFDataArray alloc] initWithContentsOfFile: body]; } - (void)setMethod: (OFString*)method { void *pool = objc_autoreleasePoolPush(); @@ -202,21 +202,21 @@ } - (void)applicationDidFinishLaunching { OFOptionsParser *optionsParser = - [OFOptionsParser parserWithOptions: @"ce:hH:m:o:OP:q"]; + [OFOptionsParser parserWithOptions: @"bc:hH:m:o:OP:q"]; of_unichar_t option; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { + case 'b': + [self setBody: [optionsParser argument]]; + break; case 'c': _continue = true; break; - case 'e': - [self setEntity: [optionsParser argument]]; - break; case 'h': help(of_stdout, true, 0); break; case 'H': [self addHeader: [optionsParser argument]]; @@ -610,11 +610,11 @@ } request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: _method]; - [request setEntity: _entity]; + [request setBody: _body]; if ((response = [self performRequest: request]) == nil) { _errorCode = 1; goto next; }