@@ -59,11 +59,11 @@ size_t _URLIndex; int _errorCode; OFString *_outputPath, *_currentFileName; bool _continue, _force, _detectFileName, _detectedFileName; bool _quiet, _verbose, _insecure; - OFData *_body; + OFStream *_body; of_http_request_method_t _method; OFMutableDictionary *_clientHeaders; OFHTTPClient *_HTTPClient; char *_buffer; OFStream *_output; @@ -283,22 +283,22 @@ [_clientHeaders setObject: value forKey: name]; } -- (void)setBody: (OFString *)file +- (void)setBody: (OFString *)path { + uintmax_t bodySize; + [_body release]; - - if ([file isEqual: @"-"]) { - void *pool = objc_autoreleasePoolPush(); - - _body = [[of_stdin readDataUntilEndOfStream] copy]; - - objc_autoreleasePoolPop(pool); - } else - _body = [[OFData alloc] initWithContentsOfFile: file]; + _body = [[OFFile alloc] initWithPath: path + mode: @"r"]; + + bodySize = [[[OFFileManager defaultManager] + attributesOfItemAtPath: path] fileSize]; + [_clientHeaders setObject: [OFString stringWithFormat: @"%ju", bodySize] + forKey: @"Content-Length"]; } - (void)setMethod: (OFString *)method { void *pool = objc_autoreleasePoolPush(); @@ -508,10 +508,27 @@ { if (_insecure && [sock respondsToSelector: @selector(setCertificateVerificationEnabled:)]) [sock setCertificateVerificationEnabled: false]; } + +- (void)client: (OFHTTPClient *)client + requestsBody: (OFStream *)body + request: (OFHTTPRequest *)request + context: (id)context +{ + /* TODO: Do asynchronously and print status */ + while (![_body isAtEndOfStream]) { + char buffer[4096]; + size_t length; + + length = [_body readIntoBuffer: buffer + length: 4096]; + [body writeBuffer: buffer + length: length]; + } +} - (bool)client: (OFHTTPClient *)client shouldFollowRedirect: (OFURL *)URL statusCode: (int)statusCode request: (OFHTTPRequest *)request @@ -544,11 +561,11 @@ return true; } - (void)client: (OFHTTPClient *)client didEncounterException: (id)e - forRequest: (OFHTTPRequest *)request + request: (OFHTTPRequest *)request context: (id)context { if ([e isKindOfClass: [OFAddressTranslationFailedException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; @@ -954,11 +971,10 @@ } request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: _method]; - [request setBody: _body]; [_HTTPClient asyncPerformRequest: request context: nil]; return;