Differences From Artifact [3efdaebeee]:
- File
src/OFHTTPServer.m
— part of check-in
[d2487bc7e1]
at
2014-07-07 00:50:01
on branch trunk
— OFURL: Don't include the leading "/" in path
While Cocoa includes it, RFC 1738 explicitly states that the "/" between
host / port and path is not part of the path. (user: js, size: 15501) [annotate] [blame] [check-ins using]
To Artifact [36dd983976]:
- File
src/OFHTTPServer.m
— part of check-in
[b87a5d3b46]
at
2014-08-21 19:00:28
on branch trunk
— OFHTTPServer: Don't close the socket manually
Closing it manually causes the fd to become invalid before it is removed
from the OFKernelEventObserver. (user: js, size: 15772) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #import "OFHTTPResponse.h" #import "OFTCPSocket.h" #import "OFTimer.h" #import "OFAlreadyConnectedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFWriteFailedException.h" #define BUFFER_SIZE 1024 /* * FIXME: Key normalization replaces headers like "DNT" with "Dnt". * FIXME: Errors are not reported to the user. */ | > > > | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #import "OFHTTPResponse.h" #import "OFTCPSocket.h" #import "OFTimer.h" #import "OFAlreadyConnectedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotConnectedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFWriteFailedException.h" #import "socket_helpers.h" #define BUFFER_SIZE 1024 /* * FIXME: Key normalization replaces headers like "DNT" with "Dnt". * FIXME: Errors are not reported to the user. */ |
︙ | ︙ | |||
167 168 169 170 171 172 173 | freeWhenDone: true]; } @interface OFHTTPServerResponse: OFHTTPResponse { OFTCPSocket *_socket; OFHTTPServer *_server; | | | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | freeWhenDone: true]; } @interface OFHTTPServerResponse: OFHTTPResponse { OFTCPSocket *_socket; OFHTTPServer *_server; bool _chunked, _headersSent; } - initWithSocket: (OFTCPSocket*)socket server: (OFHTTPServer*)server; @end @implementation OFHTTPServerResponse |
︙ | ︙ | |||
189 190 191 192 193 194 195 | _server = [server retain]; return self; } - (void)dealloc { | | | < | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | _server = [server retain]; return self; } - (void)dealloc { if (_socket != nil) [self close]; /* includes [_socket release] */ [_server release]; [super dealloc]; } - (void)OF_sendHeaders { |
︙ | ︙ | |||
234 235 236 237 238 239 240 241 242 243 244 245 246 247 | } - (void)lowlevelWriteBuffer: (const void*)buffer length: (size_t)length { void *pool; if (!_headersSent) [self OF_sendHeaders]; if (!_chunked) { [_socket writeBuffer: buffer length: length]; return; | > > > | 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | } - (void)lowlevelWriteBuffer: (const void*)buffer length: (size_t)length { void *pool; if (_socket == nil) @throw [OFNotConnectedException exceptionWithSocket: self]; if (!_headersSent) [self OF_sendHeaders]; if (!_chunked) { [_socket writeBuffer: buffer length: length]; return; |
︙ | ︙ | |||
255 256 257 258 259 260 261 262 263 264 265 266 267 268 | length: length]; [_socket writeBuffer: "\r\n" length: 2]; } - (void)close { if (!_headersSent) [self OF_sendHeaders]; if (_chunked) [_socket writeBuffer: "0\r\n\r\n" length: 5]; | > > > | | < > > > | 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | length: length]; [_socket writeBuffer: "\r\n" length: 2]; } - (void)close { if (_socket == nil) @throw [OFNotConnectedException exceptionWithSocket: self]; if (!_headersSent) [self OF_sendHeaders]; if (_chunked) [_socket writeBuffer: "0\r\n\r\n" length: 5]; [_socket release]; _socket = nil; } - (int)fileDescriptorForWriting { if (_socket == nil) return INVALID_SOCKET; return [_socket fileDescriptorForWriting]; } @end @interface OFHTTPServer_Connection: OFObject { OFTCPSocket *_socket; |
︙ | ︙ | |||
558 559 560 561 562 563 564 | [_socket writeFormat: @"HTTP/1.1 %d %s\r\n" @"Date: %@\r\n" @"Server: %@\r\n" @"\r\n", statusCode, statusCodeToString(statusCode), date, [_server name]]; | < | 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | [_socket writeFormat: @"HTTP/1.1 %d %s\r\n" @"Date: %@\r\n" @"Server: %@\r\n" @"\r\n", statusCode, statusCodeToString(statusCode), date, [_server name]]; return false; } - (void)createResponse { OFURL *URL; |
︙ | ︙ |