︙ | | | ︙ | |
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
OFTimer *_timer;
enum {
AWAITING_PROLOG,
PARSING_HEADERS,
SEND_RESPONSE
} _state;
uint8_t _HTTPMinorVersion;
of_http_request_type_t _requestType;
OFString *_host, *_path;
uint16_t _port;
OFMutableDictionary *_headers;
size_t _contentLength;
OFDataArray *_POSTData;
}
|
|
|
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
OFTimer *_timer;
enum {
AWAITING_PROLOG,
PARSING_HEADERS,
SEND_RESPONSE
} _state;
uint8_t _HTTPMinorVersion;
of_http_request_method_t _method;
OFString *_host, *_path;
uint16_t _port;
OFMutableDictionary *_headers;
size_t _contentLength;
OFDataArray *_POSTData;
}
|
︙ | | | ︙ | |
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
}
abort();
}
- (bool)parseProlog: (OFString*)line
{
OFString *type;
size_t pos;
@try {
OFString *version = [line
substringWithRange: of_range([line length] - 9, 9)];
of_unichar_t tmp;
|
|
|
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
}
abort();
}
- (bool)parseProlog: (OFString*)line
{
OFString *method;
size_t pos;
@try {
OFString *version = [line
substringWithRange: of_range([line length] - 9, 9)];
of_unichar_t tmp;
|
︙ | | | ︙ | |
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
return [self sendErrorAndClose: 400];
}
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];
@try {
_path = [line substringWithRange:
of_range(pos + 1, [line length] - pos - 10)];
} @catch (OFOutOfRangeException *e) {
return [self sendErrorAndClose: 400];
}
|
|
|
>
>
>
>
>
|
<
|
<
|
<
|
|
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
return [self sendErrorAndClose: 400];
}
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];
}
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) {
return [self sendErrorAndClose: 400];
}
|
︙ | | | ︙ | |
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
- (bool)parseHeaders: (OFString*)line
{
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:;
OFString *tmp;
char *buffer;
tmp = [_headers objectForKey: @"Content-Length"];
if (tmp == nil)
return [self sendErrorAndClose: 411];
|
|
|
<
<
<
<
|
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
- (bool)parseHeaders: (OFString*)line
{
OFString *key, *value;
size_t pos;
if ([line length] == 0) {
switch (_method) {
case OF_HTTP_REQUEST_METHOD_POST:;
OFString *tmp;
char *buffer;
tmp = [_headers objectForKey: @"Content-Length"];
if (tmp == nil)
return [self sendErrorAndClose: 411];
|
︙ | | | ︙ | |
472
473
474
475
476
477
478
479
480
481
482
483
484
485
|
selector: @selector(socket:
didReadIntoBuffer:
length:exception:)];
[_timer setFireDate:
[OFDate dateWithTimeIntervalSinceNow: 5]];
return false;
}
return true;
}
pos = [line rangeOfString: @":"].location;
if (pos == OF_NOT_FOUND)
|
>
>
>
|
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
selector: @selector(socket:
didReadIntoBuffer:
length:exception:)];
[_timer setFireDate:
[OFDate dateWithTimeIntervalSinceNow: 5]];
return false;
default:
_state = SEND_RESPONSE;
break;
}
return true;
}
pos = [line rangeOfString: @":"].location;
if (pos == OF_NOT_FOUND)
|
︙ | | | ︙ | |
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
[URL setPath: path];
[URL setQuery: query];
} else
[URL setPath: _path];
request = [OFHTTPRequest requestWithURL: URL];
[request setRequestType: _requestType];
[request setProtocolVersion:
(of_http_request_protocol_version_t){ 1, _HTTPMinorVersion }];
[request setHeaders: _headers];
[request setPOSTData: _POSTData];
[request setRemoteAddress: [_socket remoteAddress]];
response = [[[OFHTTPServerResponse alloc]
|
|
|
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
|
[URL setPath: path];
[URL setQuery: query];
} else
[URL setPath: _path];
request = [OFHTTPRequest requestWithURL: URL];
[request setMethod: _method];
[request setProtocolVersion:
(of_http_request_protocol_version_t){ 1, _HTTPMinorVersion }];
[request setHeaders: _headers];
[request setPOSTData: _POSTData];
[request setRemoteAddress: [_socket remoteAddress]];
response = [[[OFHTTPServerResponse alloc]
|
︙ | | | ︙ | |