ObjFW  Check-in [f67621fa4d]

Overview
Comment:OFHTTPServer: Send 400 on invalid path/query
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f67621fa4db616a31e9393fe091ee9dc5ac678a9d1cc9b6d23ff6be7e6b6ffb8
User & Date: js on 2022-05-20 09:36:26
Other Links: manifest | tags
Context
2022-06-05
09:13
Remove +[OFFile fileWithURL:] check-in: e61d7f5eb7 user: js tags: trunk
2022-05-20
09:36
OFHTTPServer: Send 400 on invalid path/query check-in: f67621fa4d user: js tags: trunk
2022-04-25
20:09
Revert "OFOpenItemFailedException: Remove path" check-in: 1185c1cd3d user: js tags: trunk
Changes

Modified src/OFHTTPServer.h from [df6e847201] to [a2fd4b8141].

60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
 *	   connections will still be handled and you can start accepting new
 *	   connections again by calling @ref OFHTTPServer::start again.
 */
-			  (bool)server: (OFHTTPServer *)server
  didReceiveExceptionOnListeningSocket: (id)exception;

/**
 * @brief This method is called when a client socket encountered an exception.

 *
 * This can happen when the OFHTTPServer tries to properly close the
 * connection. If no headers have been sent yet, it will send headers, and if
 * chunked transfer encoding was used, it will send a chunk of size 0. However,
 * if the other end already closed the connection before that, this will raise
 * an exception.
 *







|
>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 *	   connections will still be handled and you can start accepting new
 *	   connections again by calling @ref OFHTTPServer::start again.
 */
-			  (bool)server: (OFHTTPServer *)server
  didReceiveExceptionOnListeningSocket: (id)exception;

/**
 * @brief This method is called when a socket for a client encountered an
 * exception.
 *
 * This can happen when the OFHTTPServer tries to properly close the
 * connection. If no headers have been sent yet, it will send headers, and if
 * chunked transfer encoding was used, it will send a chunk of size 0. However,
 * if the other end already closed the connection before that, this will raise
 * an exception.
 *

Modified src/OFHTTPServer.m from [879c93d87f] to [56dd1ea76e].

534
535
536
537
538
539
540

541

542
543
544
545
546
547
548
549
550





551
552
553
554
555
556
557

	URL = [OFMutableURL URL];
	URL.scheme = @"http";
	URL.host = _host;
	if (_port != 80)
		URL.port = [OFNumber numberWithUnsignedShort: _port];


	if ((pos = [_path rangeOfString: @"?"].location) != OFNotFound) {

		OFString *path, *query;

		path = [_path substringToIndex: pos];
		query = [_path substringFromIndex: pos + 1];

		URL.URLEncodedPath = path;
		URL.URLEncodedQuery = query;
	} else
		URL.URLEncodedPath = _path;






	[URL makeImmutable];

	request = [OFHTTPRequest requestWithURL: URL];
	request.method = _method;
	request.protocolVersion =
	    (OFHTTPRequestProtocolVersion){ 1, _HTTPMinorVersion };







>
|
>
|

|
|

|
|
|
|
>
>
>
>
>







534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564

	URL = [OFMutableURL URL];
	URL.scheme = @"http";
	URL.host = _host;
	if (_port != 80)
		URL.port = [OFNumber numberWithUnsignedShort: _port];

	@try {
		if ((pos = [_path rangeOfString: @"?"].location) !=
		    OFNotFound) {
			OFString *path, *query;

			path = [_path substringToIndex: pos];
			query = [_path substringFromIndex: pos + 1];

			URL.URLEncodedPath = path;
			URL.URLEncodedQuery = query;
		} else
			URL.URLEncodedPath = _path;
	} @catch (OFInvalidFormatException *e) {
		objc_autoreleasePoolPop(pool);
		[self sendErrorAndClose: 400];
		return;
	}

	[URL makeImmutable];

	request = [OFHTTPRequest requestWithURL: URL];
	request.method = _method;
	request.protocolVersion =
	    (OFHTTPRequestProtocolVersion){ 1, _HTTPMinorVersion };