ObjFW  Check-in [a013a9d577]

Overview
Comment:ofhttp: Allow all request methods
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a013a9d577fbf4984796e00aece1e21ea38bd754b5d91a4b31e880ef3d854f6e
User & Date: js on 2020-03-22 16:15:08
Other Links: manifest | tags
Context
2020-03-22
21:39
ofhttp: Don't try writing a file for HEAD requests check-in: 0e2f8c361e user: js tags: trunk
16:15
ofhttp: Allow all request methods check-in: a013a9d577 user: js tags: trunk
15:51
ofhttp: Print the HTTP status code on error check-in: 9c506fc995 user: js tags: trunk
Changes

Modified src/OFHTTPRequest.h from [4385937a7a] to [c500866337].

152
153
154
155
156
157
158
159
160
161
162
163
164
/*!
 * @brief Returns the request method for the specified string.
 *
 * @param string The string for which the request method should be returned
 * @return The request method for the specified string
 */
extern of_http_request_method_t of_http_request_method_from_string(
    const char *string);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END







|





152
153
154
155
156
157
158
159
160
161
162
163
164
/*!
 * @brief Returns the request method for the specified string.
 *
 * @param string The string for which the request method should be returned
 * @return The request method for the specified string
 */
extern of_http_request_method_t of_http_request_method_from_string(
    OFString *string);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

Modified src/OFHTTPRequest.m from [db732e6dff] to [2d1b69a80f].

22
23
24
25
26
27
28

29
30
31
32
33
34
35
#import "OFHTTPRequest.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFDictionary.h"
#import "OFData.h"
#import "OFArray.h"


#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFUnsupportedVersionException.h"

const char *
of_http_request_method_to_string(of_http_request_method_t method)
{







>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "OFHTTPRequest.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFDictionary.h"
#import "OFData.h"
#import "OFArray.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFUnsupportedVersionException.h"

const char *
of_http_request_method_to_string(of_http_request_method_t method)
{
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
		return "CONNECT";
	}

	return NULL;
}

of_http_request_method_t
of_http_request_method_from_string(const char *string)
{
	if (strcmp(string, "OPTIONS") == 0)
		return OF_HTTP_REQUEST_METHOD_OPTIONS;
	if (strcmp(string, "GET") == 0)
		return OF_HTTP_REQUEST_METHOD_GET;
	if (strcmp(string, "HEAD") == 0)
		return OF_HTTP_REQUEST_METHOD_HEAD;
	if (strcmp(string, "POST") == 0)
		return OF_HTTP_REQUEST_METHOD_POST;
	if (strcmp(string, "PUT") == 0)
		return OF_HTTP_REQUEST_METHOD_PUT;
	if (strcmp(string, "DELETE") == 0)
		return OF_HTTP_REQUEST_METHOD_DELETE;
	if (strcmp(string, "TRACE") == 0)
		return OF_HTTP_REQUEST_METHOD_TRACE;
	if (strcmp(string, "CONNECT") == 0)
		return OF_HTTP_REQUEST_METHOD_CONNECT;

	@throw [OFInvalidFormatException exception];
}

@implementation OFHTTPRequest
@synthesize URL = _URL, method = _method, headers = _headers;

+ (instancetype)request
{







|

|

|

|

|

|

|

|

|


|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
		return "CONNECT";
	}

	return NULL;
}

of_http_request_method_t
of_http_request_method_from_string(OFString *string)
{
	if ([string isEqual: @"OPTIONS"])
		return OF_HTTP_REQUEST_METHOD_OPTIONS;
	if ([string isEqual: @"GET"])
		return OF_HTTP_REQUEST_METHOD_GET;
	if ([string isEqual: @"HEAD"])
		return OF_HTTP_REQUEST_METHOD_HEAD;
	if ([string isEqual: @"POST"])
		return OF_HTTP_REQUEST_METHOD_POST;
	if ([string isEqual: @"PUT"])
		return OF_HTTP_REQUEST_METHOD_PUT;
	if ([string isEqual: @"DELETE"])
		return OF_HTTP_REQUEST_METHOD_DELETE;
	if ([string isEqual: @"TRACE"])
		return OF_HTTP_REQUEST_METHOD_TRACE;
	if ([string isEqual: @"CONNECT"])
		return OF_HTTP_REQUEST_METHOD_CONNECT;

	@throw [OFInvalidArgumentException exception];
}

@implementation OFHTTPRequest
@synthesize URL = _URL, method = _method, headers = _headers;

+ (instancetype)request
{

Modified src/OFHTTPServer.m from [69c85c4501] to [a8548d7f01].

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383

	pos = [line rangeOfString: @" "].location;
	if (pos == OF_NOT_FOUND)
		return [self sendErrorAndClose: 400];

	method = [line substringWithRange: of_range(0, pos)];
	@try {
		_method = of_http_request_method_from_string(method.UTF8String);
	} @catch (OFInvalidFormatException *e) {
		return [self sendErrorAndClose: 405];
	}

	@try {
		of_range_t range = of_range(pos + 1, line.length - pos - 10);

		path = [[[line substringWithRange:







|
|







368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383

	pos = [line rangeOfString: @" "].location;
	if (pos == OF_NOT_FOUND)
		return [self sendErrorAndClose: 400];

	method = [line substringWithRange: of_range(0, pos)];
	@try {
		_method = of_http_request_method_from_string(method);
	} @catch (OFInvalidArgumentException *e) {
		return [self sendErrorAndClose: 405];
	}

	@try {
		of_range_t range = of_range(pos + 1, line.length - pos - 10);

		path = [[[line substringWithRange:

Modified utils/ofhttp/OFHTTP.m from [39d0dcb133] to [a9d2a994f3].

33
34
35
36
37
38
39

40
41
42
43
44
45
46
#import "OFSystemInfo.h"
#import "OFTCPSocket.h"
#import "OFTLSSocket.h"
#import "OFURL.h"

#import "OFConnectionFailedException.h"
#import "OFHTTPRequestFailedException.h"

#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFResolveHostFailedException.h"
#import "OFRetrieveItemAttributesFailedException.h"







>







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#import "OFSystemInfo.h"
#import "OFTCPSocket.h"
#import "OFTLSSocket.h"
#import "OFURL.h"

#import "OFConnectionFailedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFResolveHostFailedException.h"
#import "OFRetrieveItemAttributesFailedException.h"
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

- (void)setMethod: (OFString *)method
{
	void *pool = objc_autoreleasePoolPush();

	method = method.uppercaseString;

	if ([method isEqual: @"GET"])
		_method = OF_HTTP_REQUEST_METHOD_GET;
	else if ([method isEqual: @"HEAD"])
		_method = OF_HTTP_REQUEST_METHOD_HEAD;
	else if ([method isEqual: @"POST"])
		_method = OF_HTTP_REQUEST_METHOD_POST;
	else if ([method isEqual: @"PUT"])
		_method = OF_HTTP_REQUEST_METHOD_PUT;
	else if ([method isEqual: @"DELETE"])
		_method = OF_HTTP_REQUEST_METHOD_DELETE;
	else if ([method isEqual: @"TRACE"])
		_method = OF_HTTP_REQUEST_METHOD_TRACE;
	else {
		[of_stderr writeLine: OF_LOCALIZED(@"invalid_input_method",
		    @"%[prog]: Invalid request method %[method]!",
		    @"prog", [OFApplication programName],
		    @"method", method)];
		[OFApplication terminateWithStatus: 1];
	}








|
|
|
<
<
<
<
<
<
<
<
<
<







334
335
336
337
338
339
340
341
342
343










344
345
346
347
348
349
350

- (void)setMethod: (OFString *)method
{
	void *pool = objc_autoreleasePoolPush();

	method = method.uppercaseString;

	@try {
		_method = of_http_request_method_from_string(method);
	} @catch (OFInvalidArgumentException *e) {










		[of_stderr writeLine: OF_LOCALIZED(@"invalid_input_method",
		    @"%[prog]: Invalid request method %[method]!",
		    @"prog", [OFApplication programName],
		    @"method", method)];
		[OFApplication terminateWithStatus: 1];
	}