Differences From Artifact [561ec71175]:
- File
src/OFHTTPClient.m
— part of check-in
[25c985fec1]
at
2020-08-25 00:11:24
on branch trunk
— OFNumber: Remove (u)int{8,16,32,64} methods
Since C guarantees minimum sizes for char, short, int, long and long
long, these can be used instead. (user: js, size: 30364) [annotate] [blame] [check-ins using] [more...]
To Artifact [72f7071464]:
- File
src/OFHTTPClient.m
— part of check-in
[0ddaac3f5b]
at
2020-11-05 00:24:29
on branch trunk
— Avoid -[allocMemoryWithSize:] for temporary memory
-[allocMemoryWithSize:] has book keeping overhead that is unnecessary
for temporary memory. (user: js, size: 30272) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
58 59 60 61 62 63 64 | { @public OFHTTPClient *_client; OFHTTPRequest *_request; unsigned int _redirects; bool _firstLine; OFString *_version; | | | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | { @public OFHTTPClient *_client; OFHTTPRequest *_request; unsigned int _redirects; bool _firstLine; OFString *_version; short _status; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_serverHeaders; } - (instancetype)initWithClient: (OFHTTPClient *)client request: (OFHTTPRequest *)request redirects: (unsigned int)redirects; - (void)start; |
︙ | ︙ | |||
237 238 239 240 241 242 243 | firstLetter = false; str++; } } static bool | | | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | firstLetter = false; str++; } } static bool defaultShouldFollow(of_http_request_method_t method, short statusCode) { bool follow; /* * 301, 302 and 307 should only redirect with user confirmation if the * request method is not GET or HEAD. Asking the delegate and getting * true returned is considered user confirmation. |
︙ | ︙ | |||
294 295 296 297 298 299 300 | - (void)raiseException: (id)exception { [_client close]; _client->_inProgress = false; [_client->_delegate client: _client | > > | < > | 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | - (void)raiseException: (id)exception { [_client close]; _client->_inProgress = false; [_client->_delegate client: _client didPerformRequest: _request response: nil exception: exception]; } - (void)createResponseWithSocketOrThrow: (OFTCPSocket *)sock { OFURL *URL = _request.URL; OFHTTPClientResponse *response; OFString *connectionHeader; bool keepAlive; OFString *location; id exception; response = [[[OFHTTPClientResponse alloc] initWithSocket: sock] autorelease]; response.protocolVersionString = _version; response.statusCode = _status; response.headers = _serverHeaders; |
︙ | ︙ | |||
418 419 420 421 422 423 424 | return; } } _client->_inProgress = false; if (_status / 100 != 2) | | > > | > | 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | return; } } _client->_inProgress = false; if (_status / 100 != 2) exception = [OFHTTPRequestFailedException exceptionWithRequest: _request response: response]; else exception = nil; [_client->_delegate performSelector: @selector(client:didPerformRequest: response:exception:) withObject: _client withObject: _request withObject: response withObject: exception afterDelay: 0]; } - (void)createResponseWithSocket: (OFTCPSocket *)sock { @try { [self createResponseWithSocketOrThrow: sock]; |
︙ | ︙ | |||
467 468 469 470 471 472 473 | exceptionWithVersion: _version]; status = [line substringWithRange: of_range(9, 3)].longLongValue; if (status < 0 || status > 599) @throw [OFInvalidServerReplyException exception]; | | | 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | exceptionWithVersion: _version]; status = [line substringWithRange: of_range(9, 3)].longLongValue; if (status < 0 || status > 599) @throw [OFInvalidServerReplyException exception]; _status = (short)status; return true; } - (bool)handleServerHeader: (OFString *)line socket: (OFTCPSocket *)sock { |
︙ | ︙ | |||
506 507 508 509 510 511 512 | } lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; | | < < < | 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | } lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; keyC = of_malloc(tmp - lineC + 1, 1); memcpy(keyC, lineC, tmp - lineC); keyC[tmp - lineC] = '\0'; normalizeKey(keyC); @try { key = [OFString stringWithUTF8StringNoCopy: keyC freeWhenDone: true]; |
︙ | ︙ | |||
996 997 998 999 1000 1001 1002 | if (_toRead == 0) _toRead = -2; return length; } else { void *pool = objc_autoreleasePoolPush(); OFString *line; | | | | | < | < | 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | if (_toRead == 0) _toRead = -2; return length; } else { void *pool = objc_autoreleasePoolPush(); OFString *line; size_t pos; @try { line = [_socket tryReadLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exception]; } if (line == nil) return 0; pos = [line rangeOfString: @";"].location; if (pos != OF_NOT_FOUND) line = [line substringToIndex: pos]; if (line.length < 1) { /* * We have read the empty string because the socket is * at end of stream. */ if (_socket.atEndOfStream && pos == OF_NOT_FOUND) @throw [OFTruncatedDataException exception]; else @throw [OFInvalidServerReplyException exception]; } @try { |
︙ | ︙ | |||
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 | return _response; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { [[OFRunLoop currentRunLoop] stop]; [_response release]; _response = [response retain]; [_delegate client: client didPerformRequest: request | > > > > > > > > > > > > | < < < < < < < < < < < < < | | 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 | return _response; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response exception: (id)exception { if (exception != nil) { /* * Restore the delegate - we're giving up, but not reaching the * release of the autorelease pool that contains us, so * resetting it via -[dealloc] might be too late. */ _client.delegate = _delegate; @throw exception; } [[OFRunLoop currentRunLoop] stop]; [_response release]; _response = [response retain]; [_delegate client: client didPerformRequest: request response: response exception: nil]; } - (void)client: (OFHTTPClient *)client didCreateSocket: (OFTCPSocket *)sock request: (OFHTTPRequest *)request { if ([_delegate respondsToSelector: |
︙ | ︙ | |||
1178 1179 1180 1181 1182 1183 1184 | [_delegate client: client wantsRequestBody: body request: request]; } - (void)client: (OFHTTPClient *)client didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers | | | | 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 | [_delegate client: client wantsRequestBody: body request: request]; } - (void)client: (OFHTTPClient *)client didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers statusCode: (short)statusCode request: (OFHTTPRequest *)request { if ([_delegate respondsToSelector: @selector(client:didReceiveHeaders:statusCode:request:)]) [_delegate client: client didReceiveHeaders: headers statusCode: statusCode request: request]; } - (bool)client: (OFHTTPClient *)client shouldFollowRedirect: (OFURL *)URL statusCode: (short)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { if ([_delegate respondsToSelector: @selector(client: shouldFollowRedirect:statusCode:request:response:)]) return [_delegate client: client shouldFollowRedirect: URL |
︙ | ︙ |