︙ | | |
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
-
+
|
/*
* FIXME: Key normalization replaces headers like "DNT" with "Dnt".
* FIXME: Errors are not reported to the user.
*/
@interface OFHTTPServer ()
- (bool)of_socket: (OFTCPSocket *)socket
- (bool)of_socket: (OFTCPSocket *)sock
didAcceptSocket: (OFTCPSocket *)clientSocket
context: (id)context
exception: (id)exception;
@end
static const char *
statusCodeToString(short code)
|
︙ | | |
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
-
+
-
+
-
+
|
{
OFTCPSocket *_socket;
OFHTTPServer *_server;
OFHTTPRequest *_request;
bool _chunked, _headersSent;
}
- (instancetype)initWithSocket: (OFTCPSocket *)socket
- (instancetype)initWithSocket: (OFTCPSocket *)sock
server: (OFHTTPServer *)server
request: (OFHTTPRequest *)request;
@end
@implementation OFHTTPServerResponse
- (instancetype)initWithSocket: (OFTCPSocket *)socket
- (instancetype)initWithSocket: (OFTCPSocket *)sock
server: (OFHTTPServer *)server
request: (OFHTTPRequest *)request
{
self = [super init];
_statusCode = 500;
_socket = [socket retain];
_socket = [sock retain];
_server = [server retain];
_request = [request retain];
return self;
}
- (void)dealloc
|
︙ | | |
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
379
|
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
379
|
-
+
-
+
-
+
-
+
-
+
-
+
|
OFString *_host, *_path;
uint16_t _port;
OFMutableDictionary *_headers;
size_t _contentLength;
OFMutableData *_body;
}
- (instancetype)initWithSocket: (OFTCPSocket *)socket
- (instancetype)initWithSocket: (OFTCPSocket *)sock
server: (OFHTTPServer *)server;
- (bool)socket: (OFTCPSocket *)socket
- (bool)socket: (OFTCPSocket *)sock
didReadLine: (OFString *)line
context: (id)context
exception: (id)exception;
- (bool)parseProlog: (OFString *)line;
- (bool)parseHeaders: (OFString *)line;
- (bool)socket: (OFTCPSocket *)socket
- (bool)socket: (OFTCPSocket *)sock
didReadIntoBuffer: (char *)buffer
length: (size_t)length
context: (id)context
exception: (id)exception;
- (bool)sendErrorAndClose: (short)statusCode;
- (void)createResponse;
@end
@implementation OFHTTPServer_Connection
- (instancetype)initWithSocket: (OFTCPSocket *)socket
- (instancetype)initWithSocket: (OFTCPSocket *)sock
server: (OFHTTPServer *)server
{
self = [super init];
@try {
_socket = [socket retain];
_socket = [sock retain];
_server = [server retain];
_timer = [[OFTimer
scheduledTimerWithTimeInterval: 10
target: socket
target: _socket
selector: @selector(
cancelAsyncRequests)
repeats: false] retain];
_state = AWAITING_PROLOG;
} @catch (id e) {
[self release];
@throw e;
|
︙ | | |
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
-
+
|
[_path release];
[_headers release];
[_body release];
[super dealloc];
}
- (bool)socket: (OFTCPSocket *)socket
- (bool)socket: (OFTCPSocket *)sock
didReadLine: (OFString *)line
context: (id)context
exception: (id)exception
{
if (line == nil || exception != nil)
return false;
|
︙ | | |
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
-
+
-
+
|
_port = 80;
}
}
return true;
}
- (bool)socket: (OFTCPSocket *)socket
- (bool)socket: (OFTCPSocket *)sock
didReadIntoBuffer: (char *)buffer
length: (size_t)length
context: (id)context
exception: (id)exception
{
if ([socket isAtEndOfStream] || exception != nil)
if ([sock isAtEndOfStream] || exception != nil)
return false;
[_body addItems: buffer
count: length];
if ([_body count] >= _contentLength) {
/*
|
︙ | | |
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
|
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
|
-
+
|
- (void)stop
{
[_listeningSocket cancelAsyncRequests];
[_listeningSocket release];
_listeningSocket = nil;
}
- (bool)of_socket: (OFTCPSocket *)socket
- (bool)of_socket: (OFTCPSocket *)sock
didAcceptSocket: (OFTCPSocket *)clientSocket
context: (id)context
exception: (id)exception
{
OFHTTPServer_Connection *connection;
if (exception != nil) {
|
︙ | | |