Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -13,10 +13,11 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" +#import "OFString.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif @@ -185,10 +186,28 @@ * * @param entity The entity body of the HTTP request */ - (void)setEntity: (OFDataArray*)entity; +/*! + * @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; + +/*! + * @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; + /*! * @brief Returns the entity body of the HTTP request. * * @return The entity body of the HTTP request */ Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -260,10 +260,29 @@ - (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]; + + objc_autoreleasePoolPop(pool); +} - (OFDataArray*)entity { OF_GETTER(_entity, true) }