@@ -289,11 +289,11 @@ AWAITING_PROLOG, PARSING_HEADERS, SEND_RESPONSE } _state; uint8_t _HTTPMinorVersion; - of_http_request_type_t _requestType; + of_http_request_method_t _method; OFString *_host, *_path; uint16_t _port; OFMutableDictionary *_headers; size_t _contentLength; OFDataArray *_POSTData; @@ -385,11 +385,11 @@ abort(); } - (bool)parseProlog: (OFString*)line { - OFString *type; + OFString *method; size_t pos; @try { OFString *version = [line substringWithRange: of_range([line length] - 9, 9)]; @@ -409,19 +409,21 @@ pos = [line rangeOfString: @" "].location; if (pos == OF_NOT_FOUND) return [self sendErrorAndClose: 400]; - type = [line substringWithRange: of_range(0, pos)]; - if ([type isEqual: @"GET"]) - _requestType = OF_HTTP_REQUEST_TYPE_GET; - else if ([type isEqual: @"POST"]) - _requestType = OF_HTTP_REQUEST_TYPE_POST; - else if ([type isEqual: @"HEAD"]) - _requestType = OF_HTTP_REQUEST_TYPE_HEAD; - else - return [self sendErrorAndClose: 501]; + method = [line substringWithRange: of_range(0, pos)]; + @try { + _method = of_http_request_method_from_string( + [method UTF8String]); + } @catch (OFInvalidFormatException *e) { + return [self sendErrorAndClose: 405]; + } + if (_method != OF_HTTP_REQUEST_METHOD_GET && + _method != OF_HTTP_REQUEST_METHOD_HEAD && + _method != OF_HTTP_REQUEST_METHOD_POST) + return [self sendErrorAndClose: 405]; @try { _path = [line substringWithRange: of_range(pos + 1, [line length] - pos - 10)]; } @catch (OFOutOfRangeException *e) { @@ -442,16 +444,12 @@ { OFString *key, *value; size_t pos; if ([line length] == 0) { - switch (_requestType) { - case OF_HTTP_REQUEST_TYPE_GET: - case OF_HTTP_REQUEST_TYPE_HEAD: - _state = SEND_RESPONSE; - break; - case OF_HTTP_REQUEST_TYPE_POST:; + switch (_method) { + case OF_HTTP_REQUEST_METHOD_POST:; OFString *tmp; char *buffer; tmp = [_headers objectForKey: @"Content-Length"]; if (tmp == nil) @@ -474,10 +472,13 @@ length:exception:)]; [_timer setFireDate: [OFDate dateWithTimeIntervalSinceNow: 5]]; return false; + default: + _state = SEND_RESPONSE; + break; } return true; } @@ -608,11 +609,11 @@ [URL setQuery: query]; } else [URL setPath: _path]; request = [OFHTTPRequest requestWithURL: URL]; - [request setRequestType: _requestType]; + [request setMethod: _method]; [request setProtocolVersion: (of_http_request_protocol_version_t){ 1, _HTTPMinorVersion }]; [request setHeaders: _headers]; [request setPOSTData: _POSTData]; [request setRemoteAddress: [_socket remoteAddress]];