Overview
Comment: | OFHTTPServer: Make the server name configurable. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
eea79730f4c7476d4afde6c40549a8ae |
User & Date: | js on 2012-12-11 14:40:56 |
Other Links: | manifest | tags |
Context
2012-12-11
| ||
16:38 | OFHTTPRequest: Add the current date if necessary. check-in: d330801ded user: js tags: trunk | |
14:40 | OFHTTPServer: Make the server name configurable. check-in: eea79730f4 user: js tags: trunk | |
12:44 | Update Xcode project. check-in: 7ef87b5ee2 user: js tags: trunk | |
Changes
Modified src/OFHTTPServer.h from [551f28751a] to [d43ccf4c58].
︙ | ︙ | |||
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | * @brief A class for creating a simple HTTP server inside of applications. */ @interface OFHTTPServer: OFObject { OFString *host; uint16_t port; id <OFHTTPServerDelegate> delegate; OFTCPSocket *listeningSocket; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFString *host; @property uint16_t port; @property (assign) id <OFHTTPServerDelegate> delegate; #endif /*! * @brief Creates a new HTTP server. * * @return A new HTTP server */ | > > | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | * @brief A class for creating a simple HTTP server inside of applications. */ @interface OFHTTPServer: OFObject { OFString *host; uint16_t port; id <OFHTTPServerDelegate> delegate; OFString *name; OFTCPSocket *listeningSocket; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFString *host; @property uint16_t port; @property (assign) id <OFHTTPServerDelegate> delegate; @property (copy) OFString *name; #endif /*! * @brief Creates a new HTTP server. * * @return A new HTTP server */ |
︙ | ︙ | |||
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | /*! * @brief Returns the delegate for the HTTP server. * * @return The delegate for the HTTP server */ - (id <OFHTTPServerDelegate>)delegate; /*! * @brief Starts the HTTP server in the current thread's runloop. */ - (void)start; - (BOOL)OF_socket: (OFTCPSocket*)socket didAcceptSocket: (OFTCPSocket*)clientSocket exception: (OFException*)exception; @end @interface OFObject (OFHTTPServerDelegate) <OFHTTPServerDelegate> @end | > > > > > > > > > > > > > > | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | /*! * @brief Returns the delegate for the HTTP server. * * @return The delegate for the HTTP server */ - (id <OFHTTPServerDelegate>)delegate; /*! * @brief Sets the server name the server presents to clients. * * @param name The server name to present to clients */ - (void)setName: (OFString*)name; /*! * @brief Returns the server name the server presents to clients. * * @return The server name the server presents to clients */ - (OFString*)name; /*! * @brief Starts the HTTP server in the current thread's runloop. */ - (void)start; - (BOOL)OF_socket: (OFTCPSocket*)socket didAcceptSocket: (OFTCPSocket*)clientSocket exception: (OFException*)exception; @end @interface OFObject (OFHTTPServerDelegate) <OFHTTPServerDelegate> @end |
Modified src/OFHTTPServer.m from [bee61430ab] to [f2e30645b9].
︙ | ︙ | |||
418 419 420 421 422 423 424 | - (BOOL)sendErrorAndClose: (short)statusCode { OFString *date = [[OFDate date] dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; [sock writeFormat: @"HTTP/1.1 %d %s\r\n" @"Date: %@\r\n" | | | | > | 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | - (BOOL)sendErrorAndClose: (short)statusCode { OFString *date = [[OFDate date] dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; [sock writeFormat: @"HTTP/1.1 %d %s\r\n" @"Date: %@\r\n" @"Server: %@\r\n" @"\r\n", statusCode, status_code_to_string(statusCode), date, [server name]]; [sock close]; return NO; } - (void)sendReply { |
︙ | ︙ | |||
471 472 473 474 475 476 477 | selector: @selector(server:didReceiveRequest:)]; } replyHeaders = [reply headers]; replyData = [reply data]; [sock writeFormat: @"HTTP/1.1 %d %s\r\n" | | < | > | 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | selector: @selector(server:didReceiveRequest:)]; } replyHeaders = [reply headers]; replyData = [reply data]; [sock writeFormat: @"HTTP/1.1 %d %s\r\n" @"Server: %@\r\n", [reply statusCode], status_code_to_string([reply statusCode]), [server name]]; if (requestType != OF_HTTP_REQUEST_TYPE_HEAD) [sock writeFormat: @"Content-Length: %zu\r\n", [replyData count] * [replyData itemSize]]; keyEnumerator = [replyHeaders keyEnumerator]; valueEnumerator = [replyHeaders objectEnumerator]; |
︙ | ︙ | |||
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | @end @implementation OFHTTPServer + (instancetype)server { return [[[self alloc] init] autorelease]; } - (void)dealloc { [host release]; [listeningSocket release]; [super dealloc]; } - (void)setHost: (OFString*)host_ { OF_SETTER(host, host_, YES, 1) | > > > > > > > > > > > | 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | @end @implementation OFHTTPServer + (instancetype)server { return [[[self alloc] init] autorelease]; } - init { self = [super init]; name = @"OFHTTPServer (ObjFW's HTTP server class " @"<https://webkeks.org/objfw/>)"; return self; } - (void)dealloc { [host release]; [listeningSocket release]; [name release]; [super dealloc]; } - (void)setHost: (OFString*)host_ { OF_SETTER(host, host_, YES, 1) |
︙ | ︙ | |||
537 538 539 540 541 542 543 544 545 546 547 548 549 550 | delegate = delegate_; } - (id <OFHTTPServerDelegate>)delegate { return delegate; } - (void)start { if (host == nil || port == 0) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; | > > > > > > > > > > | 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | delegate = delegate_; } - (id <OFHTTPServerDelegate>)delegate { return delegate; } - (void)setName: (OFString*)name_ { OF_SETTER(name, name_, YES, 1) } - (OFString*)name { OF_GETTER(name, YES) } - (void)start { if (host == nil || port == 0) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; |
︙ | ︙ |