ObjFW  Diff

Differences From Artifact [5bb85c3a07]:

To Artifact [cdc79122cb]:


57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
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;
	OFData *_body;
	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
288

289


290
291
292


293
294
295
296


297
298
299


300
301
302
303
304
305
306
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 *)file
- (void)setBody: (OFString *)path
{
	uintmax_t bodySize;

	[_body release];

	if ([file isEqual: @"-"]) {
	_body = [[OFFile alloc] initWithPath: path
					mode: @"r"];
		void *pool = objc_autoreleasePoolPush();

		_body = [[of_stdin readDataUntilEndOfStream] copy];

	bodySize = [[[OFFileManager defaultManager]
	    attributesOfItemAtPath: path] fileSize];
		objc_autoreleasePoolPop(pool);
	} else
		_body = [[OFData alloc] initWithContentsOfFile: file];
	[_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
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
549

550
551
552
553
554
555
556
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
	     forRequest: (OFHTTPRequest *)request
		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
959
960
961
962
963
964
965
966
967
968
969
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];
	[request setBody: _body];

	[_HTTPClient asyncPerformRequest: request
				 context: nil];
	return;

next:
	[self performSelector: @selector(downloadNextURL)
		   afterDelay: 0];
}
@end