Overview
Context
Changes
Modified src/OFHTTPClient.h
from [baab318aa5]
to [488f1f88e1].
︙ | | |
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
-
+
+
-
-
-
-
+
+
+
+
|
context: (nullable id)context;
/*!
* @brief A callback which is called when an OFHTTPClient wants to send the
* body for a request.
*
* @param client The OFHTTPClient that wants to send the body
* @param body A stream into which the body should be written
* @param requestBody A stream into which the body of the request should be
* written
* @param request The request for which the OFHTTPClient wants to send the body
* @param context The context object that was passed to
* @ref asyncPerformRequest:context:
*/
- (void)client: (OFHTTPClient *)client
requestsBody: (OFStream *)body
request: (OFHTTPRequest *)request
context: (nullable id)context;
- (void)client: (OFHTTPClient *)client
wantsRequestBody: (OFStream *)requestBody
request: (OFHTTPRequest *)request
context: (nullable id)context;
/*!
* @brief A callback which is called when an OFHTTPClient received headers.
*
* @param client The OFHTTPClient which received the headers
* @param headers The headers received
* @param statusCode The status code received
|
︙ | | |
Modified src/OFHTTPClient.m
from [b418796944]
to [325ef4384d].
︙ | | |
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
-
+
-
+
-
+
|
[self raiseException: exception];
return 0;
}
_firstLine = true;
if ([[_request headers] objectForKey: @"Content-Length"] != nil) {
OFStream *stream = [[[OFHTTPClientRequestBodyStream alloc]
OFStream *requestBody = [[[OFHTTPClientRequestBodyStream alloc]
initWithHandler: self
socket: sock] autorelease];
if ([_client->_delegate respondsToSelector:
@selector(client:requestsBody:request:context:)])
@selector(client:wantsRequestBody:request:context:)])
[_client->_delegate client: _client
requestsBody: stream
wantsRequestBody: requestBody
request: _request
context: _context];
} else
[sock asyncReadLineWithTarget: self
selector: @selector(socket:didReadLine:
context:exception:)
|
︙ | | |
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
|
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
|
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
|
@selector(client:didCreateSocket:request:context:)])
[_delegate client: client
didCreateSocket: sock
request: request
context: context];
}
- (void)client: (OFHTTPClient *)client
requestsBody: (OFStream *)body
request: (OFHTTPRequest *)request
context: (id)context
- (void)client: (OFHTTPClient *)client
wantsRequestBody: (OFStream *)body
request: (OFHTTPRequest *)request
context: (id)context
{
if ([_delegate respondsToSelector:
@selector(client:requestsBody:request:context:)])
[_delegate client: client
requestsBody: body
request: request
context: context];
@selector(client:wantsRequestBody:request:context:)])
[_delegate client: client
wantsRequestBody: body
request: request
context: context];
}
- (void)client: (OFHTTPClient *)client
didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers
statusCode: (int)statusCode
request: (OFHTTPRequest *)request
context: (id)context
|
︙ | | |
Modified src/OFHTTPServer.h
from [d45b5ef4ed]
to [108c0e95d0].
︙ | | |
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
-
+
-
+
|
@protocol OFHTTPServerDelegate <OFObject>
/*!
* @brief This method is called when the HTTP server received a request from a
* client.
*
* @param server The HTTP server which received the request
* @param request The request the HTTP server received
* @param body A stream to read the body of the request from, if any
* @param requestBody A stream to read the body of the request from, if any
* @param response The response the server will send to the client
*/
- (void)server: (OFHTTPServer *)server
didReceiveRequest: (OFHTTPRequest *)request
body: (nullable OFStream *)body
requestBody: (nullable OFStream *)requestBody
response: (OFHTTPResponse *)response;
@optional
/*!
* @brief This method is called when the HTTP server's listening socket
* encountered an exception.
*
|
︙ | | |
Modified src/OFHTTPServer.m
from [b47d8bb3a2]
to [d2c22eea59].
︙ | | |
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
-
+
|
} _state;
uint8_t _HTTPMinorVersion;
of_http_request_method_t _method;
OFString *_host, *_path;
uint16_t _port;
OFMutableDictionary *_headers;
size_t _contentLength;
OFStream *_body;
OFStream *_requestBody;
}
- (instancetype)initWithSocket: (OFTCPSocket *)sock
server: (OFHTTPServer *)server;
- (bool)socket: (OFTCPSocket *)sock
didReadLine: (OFString *)line
context: (id)context
|
︙ | | |
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
-
+
|
[_timer invalidate];
[_timer release];
[_host release];
[_path release];
[_headers release];
[_body release];
[_requestBody release];
[super dealloc];
}
- (bool)socket: (OFTCPSocket *)sock
didReadLine: (OFString *)line
context: (id)context
|
︙ | | |
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
-
-
-
+
+
+
|
} @catch (OFInvalidFormatException *e) {
return [self sendErrorAndClose: 400];
}
if (contentLength < 0)
return [self sendErrorAndClose: 400];
[_body release];
_body = nil;
_body = [[OFHTTPServerRequestBodyStream alloc]
[_requestBody release];
_requestBody = nil;
_requestBody = [[OFHTTPServerRequestBodyStream alloc]
initWithSocket: _socket
contentLength: contentLength];
[_timer invalidate];
[_timer release];
_timer = nil;
}
|
︙ | | |
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
|
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
|
-
+
|
response = [[[OFHTTPServerResponse alloc]
initWithSocket: _socket
server: _server
request: request] autorelease];
[[_server delegate] server: _server
didReceiveRequest: request
body: _body
requestBody: _requestBody
response: response];
objc_autoreleasePoolPop(pool);
}
@end
@implementation OFHTTPServerRequestBodyStream
|
︙ | | |
Modified tests/OFHTTPClientTests.m
from [ca69cf61a6]
to [7a04e238a8].
︙ | | |
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
-
-
-
-
+
+
+
+
|
[client close];
return nil;
}
@end
@implementation TestsAppDelegate (OFHTTPClientTests)
- (void)client: (OFHTTPClient *)client
requestsBody: (OFStream *)body
request: (OFHTTPRequest *)request
context: (id)context
- (void)client: (OFHTTPClient *)client
wantsRequestBody: (OFStream *)body
request: (OFHTTPRequest *)request
context: (id)context
{
[body writeString: @"Hello"];
}
- (void)client: (OFHTTPClient *)client
didPerformRequest: (OFHTTPRequest *)request
response: (OFHTTPResponse *)response_
|
︙ | | |
Modified utils/ofhttp/OFHTTP.m
from [cdc79122cb]
to [20b438d92f].
︙ | | |
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
-
-
-
-
+
+
+
+
|
context: (id)context
{
if (_insecure && [sock respondsToSelector:
@selector(setCertificateVerificationEnabled:)])
[sock setCertificateVerificationEnabled: false];
}
- (void)client: (OFHTTPClient *)client
requestsBody: (OFStream *)body
request: (OFHTTPRequest *)request
context: (id)context
- (void)client: (OFHTTPClient *)client
wantsRequestBody: (OFStream *)body
request: (OFHTTPRequest *)request
context: (id)context
{
/* TODO: Do asynchronously and print status */
while (![_body isAtEndOfStream]) {
char buffer[4096];
size_t length;
length = [_body readIntoBuffer: buffer
|
︙ | | |