Differences From Artifact [5bb85c3a07]:
- File utils/ofhttp/OFHTTP.m — part of check-in [8377e80ba9] at 2018-01-03 23:00:34 on branch trunk — ofhttp: Fix file name not always being reset (user: js, size: 26427) [annotate] [blame] [check-ins using]
To Artifact [cdc79122cb]:
- File
utils/ofhttp/OFHTTP.m
— part of check-in
[8681bba25e]
at
2018-02-18 00:20:39
on branch trunk
— OFHTTPClient: Add a callback for the request body
This is in preparation for removing the body from OFHTTPRequest.
Having it as OFData that is part of the OFHTTPRequest was a bad idea, as
it does not allow streaming. (user: js, size: 26836) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
57 58 59 60 61 62 63 | { OFArray OF_GENERIC(OFString *) *_URLs; size_t _URLIndex; int _errorCode; OFString *_outputPath, *_currentFileName; bool _continue, _force, _detectFileName, _detectedFileName; bool _quiet, _verbose, _insecure; | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | { OFArray OF_GENERIC(OFString *) *_URLs; size_t _URLIndex; int _errorCode; OFString *_outputPath, *_currentFileName; bool _continue, _force, _detectFileName, _detectedFileName; bool _quiet, _verbose, _insecure; OFStream *_body; of_http_request_method_t _method; OFMutableDictionary *_clientHeaders; OFHTTPClient *_HTTPClient; char *_buffer; OFStream *_output; intmax_t _received, _length, _resumedFrom; ProgressBar *_progressBar; |
︙ | ︙ | |||
281 282 283 284 285 286 287 | of_range(pos + 1, [header length] - pos - 1)]; value = [value stringByDeletingEnclosingWhitespaces]; [_clientHeaders setObject: value forKey: name]; } | | > > | | < | | < | | | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | of_range(pos + 1, [header length] - pos - 1)]; value = [value stringByDeletingEnclosingWhitespaces]; [_clientHeaders setObject: value forKey: name]; } - (void)setBody: (OFString *)path { uintmax_t bodySize; [_body release]; _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(); method = [method uppercaseString]; |
︙ | ︙ | |||
506 507 508 509 510 511 512 513 514 515 516 517 518 519 | request: (OFHTTPRequest *)request context: (id)context { if (_insecure && [sock respondsToSelector: @selector(setCertificateVerificationEnabled:)]) [sock setCertificateVerificationEnabled: false]; } - (bool)client: (OFHTTPClient *)client shouldFollowRedirect: (OFURL *)URL statusCode: (int)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response context: (id)context | > > > > > > > > > > > > > > > > > | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | request: (OFHTTPRequest *)request context: (id)context { 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 response: (OFHTTPResponse *)response context: (id)context |
︙ | ︙ | |||
542 543 544 545 546 547 548 | [of_stdout writeFormat: @"☇ %@", [URL string]]; return true; } - (void)client: (OFHTTPClient *)client didEncounterException: (id)e | | | 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | [of_stdout writeFormat: @"☇ %@", [URL string]]; return true; } - (void)client: (OFHTTPClient *)client didEncounterException: (id)e request: (OFHTTPRequest *)request context: (id)context { if ([e isKindOfClass: [OFAddressTranslationFailedException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: |
︙ | ︙ | |||
952 953 954 955 956 957 958 | } @catch (OFRetrieveItemAttributesFailedException *e) { } } request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: _method]; | < | 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 | } @catch (OFRetrieveItemAttributesFailedException *e) { } } request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: _method]; [_HTTPClient asyncPerformRequest: request context: nil]; return; next: [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } @end |