Differences From Artifact [b07f7b6ae5]:
- File
utils/ofhttp/OFHTTP.m
— part of check-in
[e3e38ed68d]
at
2017-01-10 19:51:12
on branch trunk
— Do not use DATADIR as a define
This creates a conflict on Windows. (user: js, size: 23986) [annotate] [blame] [check-ins using]
To Artifact [cc6aaa39b2]:
- File utils/ofhttp/OFHTTP.m — part of check-in [d040a0989d] at 2017-01-29 19:08:46 on branch trunk — ofhttp: Add --insecure flag to ignore TLS errors (user: js, size: 24418) [annotate] [blame] [check-ins using]
| ︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "OFHTTPClient.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFOptionsParser.h" #import "OFStdIOStream.h" #import "OFSystemInfo.h" #import "OFTCPSocket.h" #import "OFURL.h" #import "OFLocalization.h" #import "OFAddressTranslationFailedException.h" #import "OFConnectionFailedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidFormatException.h" | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #import "OFHTTPClient.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFOptionsParser.h" #import "OFStdIOStream.h" #import "OFSystemInfo.h" #import "OFTCPSocket.h" #import "OFTLSSocket.h" #import "OFURL.h" #import "OFLocalization.h" #import "OFAddressTranslationFailedException.h" #import "OFConnectionFailedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidFormatException.h" |
| ︙ | ︙ | |||
52 53 54 55 56 57 58 |
@interface OFHTTP: OFObject <OFHTTPClientDelegate>
{
OFArray OF_GENERIC(OFString*) *_URLs;
size_t _URLIndex;
int _errorCode;
OFString *_outputPath;
| | | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
@interface OFHTTP: OFObject <OFHTTPClientDelegate>
{
OFArray OF_GENERIC(OFString*) *_URLs;
size_t _URLIndex;
int _errorCode;
OFString *_outputPath;
bool _continue, _force, _detectFileName, _quiet, _verbose, _insecure;
OFDataArray *_body;
of_http_request_method_t _method;
OFMutableDictionary *_clientHeaders;
OFHTTPClient *_HTTPClient;
char *_buffer;
OFStream *_output;
intmax_t _received, _length, _resumedFrom;
|
| ︙ | ︙ | |||
98 99 100 101 102 103 104 | @"-O --detect-filename" @" Do a HEAD request to detect the file name\n " @"-P --proxy " @" Specify SOCKS5 proxy\n " @"-q --quiet " @" Quiet mode (no output, except errors)\n " @"-v --verbose " | | > > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
@"-O --detect-filename"
@" Do a HEAD request to detect the file name\n "
@"-P --proxy "
@" Specify SOCKS5 proxy\n "
@"-q --quiet "
@" Quiet mode (no output, except errors)\n "
@"-v --verbose "
@" Verbose mode (print headers)\n "
@" --insecure "
@" Ignore TLS errors\n")];
[OFApplication terminateWithStatus: status];
}
@implementation OFHTTP
- init
{
|
| ︙ | ︙ | |||
237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
{ 'H', @"header", 1, NULL, NULL },
{ 'm', @"method", 1, NULL, NULL },
{ 'o', @"output", 1, NULL, &outputPath },
{ 'O', @"detect-filename", 0, &_detectFileName, NULL },
{ 'P', @"socks5-proxy", 1, NULL, NULL },
{ 'q', @"quiet", 0, &_quiet, NULL },
{ 'v', @"verbose", 0, &_verbose, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser = [OFOptionsParser
parserWithOptions: options];
of_unichar_t option;
[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
| > | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
{ 'H', @"header", 1, NULL, NULL },
{ 'm', @"method", 1, NULL, NULL },
{ 'o', @"output", 1, NULL, &outputPath },
{ 'O', @"detect-filename", 0, &_detectFileName, NULL },
{ 'P', @"socks5-proxy", 1, NULL, NULL },
{ 'q', @"quiet", 0, &_quiet, NULL },
{ 'v', @"verbose", 0, &_verbose, NULL },
{ '\0', @"insecure", 0, &_insecure, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser = [OFOptionsParser
parserWithOptions: options];
of_unichar_t option;
[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
|
| ︙ | ︙ | |||
342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
[self performSelector: @selector(downloadNextURL)
afterDelay: 0];
}
- (bool)client: (OFHTTPClient*)client
shouldFollowRedirect: (OFURL*)URL
statusCode: (int)statusCode
request: (OFHTTPRequest*)request
response: (OFHTTPResponse*)response
{
| > > > > > > > > > | 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
[self performSelector: @selector(downloadNextURL)
afterDelay: 0];
}
- (void)client: (OFHTTPClient*)client
didCreateSocket: (OF_KINDOF(OFTCPSocket*))socket
request: (OFHTTPRequest*)request
{
if (_insecure && [socket respondsToSelector:
@selector(setCertificateVerificationEnabled:)])
[socket setCertificateVerificationEnabled: false];
}
- (bool)client: (OFHTTPClient*)client
shouldFollowRedirect: (OFURL*)URL
statusCode: (int)statusCode
request: (OFHTTPRequest*)request
response: (OFHTTPResponse*)response
{
|
| ︙ | ︙ | |||
418 419 420 421 422 423 424 |
@"prog", [OFApplication programName],
@"url", [[request URL] string])];
} @catch (OFUnsupportedProtocolException *e) {
if (!_quiet)
[of_stdout writeString: @"\n"];
[of_stderr writeString: OF_LOCALIZED(@"no_ssl_library",
| | | | 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
@"prog", [OFApplication programName],
@"url", [[request URL] string])];
} @catch (OFUnsupportedProtocolException *e) {
if (!_quiet)
[of_stdout writeString: @"\n"];
[of_stderr writeString: OF_LOCALIZED(@"no_ssl_library",
@"%[prog]: No TLS library loaded!\n"
@" In order to download via https, you need to preload an "
@"TLS library for ObjFW\n"
"such as ObjOpenSSL!\n",
@"prog", [OFApplication programName])];
} @catch (OFReadOrWriteFailedException *e) {
OFString *error = OF_LOCALIZED(
@"download_failed_read_or_write_failed_any",
@"Read or write failed");
|
| ︙ | ︙ |