ObjFW  Check-in [efbbf65df2]

Overview
Comment:OFHTTPClient: Improve redirection checking logic
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: efbbf65df2da590d5b3fba4ac7644901c6ebec005b759cbbb80daaadf5aac99a
User & Date: js on 2020-04-01 21:41:32
Other Links: manifest | tags
Context
2020-04-01
22:36
Use case insensitive compare for URL scheme check-in: ccc1b1989d user: js tags: trunk
21:41
OFHTTPClient: Improve redirection checking logic check-in: efbbf65df2 user: js tags: trunk
2020-03-29
16:57
Add fish completion for ofdns check-in: b13594ccc6 user: js tags: trunk
Changes

Modified src/OFHTTPClient.m from [d88637be29] to [d31701c86f].

333
334
335
336
337
338
339
340
341
342
343
344
345
346

347
348

349
350
351

352













353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
		_client->_socket = [sock retain];
		_client->_lastURL = [URL copy];
		_client->_lastWasHEAD =
		    (_request.method == OF_HTTP_REQUEST_METHOD_HEAD);
		_client->_lastResponse = [response retain];
	}

	/* FIXME: Case-insensitive check of redirect's scheme */
	if (_redirects > 0 && (_status == 301 || _status == 302 ||
	    _status == 303 || _status == 307) &&
	    (location = [_serverHeaders objectForKey: @"Location"]) != nil &&
	    (_client->_insecureRedirectsAllowed ||
	    [URL.scheme isEqual: @"http"] ||
	    [location hasPrefix: @"https://"])) {

		OFURL *newURL;
		bool follow;


		newURL = [OFURL URLWithString: location
				relativeToURL: URL];















		if ([_client->_delegate respondsToSelector: @selector(client:
		    shouldFollowRedirect:statusCode:request:response:)])
			follow = [_client->_delegate client: _client
				       shouldFollowRedirect: newURL
						 statusCode: _status
						    request: _request
						   response: response];
		else
			follow = defaultShouldFollow(_request.method, _status);

		if (follow) {
			OFDictionary OF_GENERIC(OFString *, OFString *)
			    *headers = _request.headers;
			OFHTTPRequest *newRequest =
			    [[_request copy] autorelease];







<


|
<
<
<
>

<
>



>

>
>
>
>
>
>
>
>
>
>
>
>
>
|
|





|







333
334
335
336
337
338
339

340
341
342



343
344

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
		_client->_socket = [sock retain];
		_client->_lastURL = [URL copy];
		_client->_lastWasHEAD =
		    (_request.method == OF_HTTP_REQUEST_METHOD_HEAD);
		_client->_lastResponse = [response retain];
	}


	if (_redirects > 0 && (_status == 301 || _status == 302 ||
	    _status == 303 || _status == 307) &&
	    (location = [_serverHeaders objectForKey: @"Location"]) != nil) {



		bool follow = true;
		OFURL *newURL;

		OFString *newURLScheme;

		newURL = [OFURL URLWithString: location
				relativeToURL: URL];
		newURLScheme = newURL.scheme;

		if ([newURLScheme caseInsensitiveCompare: @"http"] !=
		    OF_ORDERED_SAME &&
		    [newURLScheme caseInsensitiveCompare: @"https"] !=
		    OF_ORDERED_SAME)
			follow = false;

		if (!_client->_insecureRedirectsAllowed &&
		    [URL.scheme caseInsensitiveCompare: @"https"] ==
		    OF_ORDERED_SAME &&
		    [newURLScheme caseInsensitiveCompare: @"http"] ==
		    OF_ORDERED_SAME)
			follow = false;

		if (follow && [_client->_delegate respondsToSelector: @selector(
		    client:shouldFollowRedirect:statusCode:request:response:)])
			follow = [_client->_delegate client: _client
				       shouldFollowRedirect: newURL
						 statusCode: _status
						    request: _request
						   response: response];
		else if (follow)
			follow = defaultShouldFollow(_request.method, _status);

		if (follow) {
			OFDictionary OF_GENERIC(OFString *, OFString *)
			    *headers = _request.headers;
			OFHTTPRequest *newRequest =
			    [[_request copy] autorelease];