@@ -90,10 +90,12 @@ [stream writeString: @"\n"]; [stream writeLine: OF_LOCALIZED(@"full_usage", @"Options:\n " @"-b --body " @" Specify the file to send as body\n " + @" " + @" (- for standard input)\n " @"-c --continue " @" Continue download of existing file\n " @"-f --force " @" Force / overwrite existing file\n " @"-h --help " @@ -318,20 +320,36 @@ forKey: name]; } - (void)setBody: (OFString *)path { - uintmax_t bodySize; + OFString *contentLength = nil; [_body release]; - _body = [[OFFile alloc] initWithPath: path - mode: @"r"]; + _body = nil; - bodySize = [[OFFileManager defaultManager] attributesOfItemAtPath: path] - .fileSize; - [_clientHeaders setObject: [OFString stringWithFormat: @"%ju", bodySize] - forKey: @"Content-Length"]; + if ([path isEqual: @"-"]) + _body = [of_stdin copy]; + else { + _body = [[OFFile alloc] initWithPath: path + mode: @"r"]; + + @try { + uintmax_t fileSize = [[OFFileManager defaultManager] + attributesOfItemAtPath: path].fileSize; + + contentLength = + [OFString stringWithFormat: @"%ju", fileSize]; + [_clientHeaders setObject: contentLength + forKey: @"Content-Length"]; + } @catch (OFRetrieveItemAttributesFailedException *e) { + } + } + + if (contentLength == nil) + [_clientHeaders setObject: @"chunked" + forKey: @"Transfer-Encoding"]; } - (void)setMethod: (OFString *)method { void *pool = objc_autoreleasePoolPush();