Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: sdk/lib/io/http_impl.dart

Issue 11299228: Add HttpsServer class and test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comments. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/http.dart ('k') | tests/standalone/io/https_server_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // The close queue handles graceful closing of HTTP connections. When 5 // The close queue handles graceful closing of HTTP connections. When
6 // a connection is added to the queue it will enter a wait state 6 // a connection is added to the queue it will enter a wait state
7 // waiting for all data written and possibly socket shutdown from 7 // waiting for all data written and possibly socket shutdown from
8 // peer. 8 // peer.
9 class _CloseQueue { 9 class _CloseQueue {
10 _CloseQueue() : _q = new Set<_HttpConnectionBase>(); 10 _CloseQueue() : _q = new Set<_HttpConnectionBase>();
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 918
919 919
920 class _RequestHandlerRegistration { 920 class _RequestHandlerRegistration {
921 _RequestHandlerRegistration(Function this._matcher, Function this._handler); 921 _RequestHandlerRegistration(Function this._matcher, Function this._handler);
922 Function _matcher; 922 Function _matcher;
923 Function _handler; 923 Function _handler;
924 } 924 }
925 925
926 // HTTP server waiting for socket connections. The connections are 926 // HTTP server waiting for socket connections. The connections are
927 // managed by the server and as requests are received the request. 927 // managed by the server and as requests are received the request.
928 class _HttpServer implements HttpServer { 928 // HTTPS connections are also supported, if the _HttpServer.httpsServer
929 _HttpServer() : _connections = new Set<_HttpConnection>(), 929 // constructor is used and a certificate name is provided in listen,
930 _handlers = new List<_RequestHandlerRegistration>(), 930 // or a SecureServerSocket is provided to listenOn.
931 _closeQueue = new _CloseQueue(); 931 class _HttpServer implements HttpServer, HttpsServer {
932 _HttpServer() : this._internal(isSecure: false);
932 933
933 void listen(String host, int port, {int backlog: 128}) { 934 _HttpServer.httpsServer() : this._internal(isSecure: true);
934 listenOn(new ServerSocket(host, port, backlog)); 935
936 _HttpServer._internal({ bool isSecure: false })
937 : _secure = isSecure,
938 _connections = new Set<_HttpConnection>(),
939 _handlers = new List<_RequestHandlerRegistration>(),
940 _closeQueue = new _CloseQueue();
941
942 void listen(String host,
943 int port,
944 {int backlog: 128,
945 String certificate_name}) {
946 if (_secure) {
947 listenOn(new SecureServerSocket(host, port, backlog, certificate_name));
948 } else {
949 listenOn(new ServerSocket(host, port, backlog));
950 }
935 _closeServer = true; 951 _closeServer = true;
936 } 952 }
937 953
938 void listenOn(ServerSocket serverSocket) { 954 void listenOn(ServerSocket serverSocket) {
Søren Gjesse 2012/11/28 15:21:49 We should check that the type of the ServerSocket
Bill Hesse 2012/11/28 15:39:40 Done.
939 void onConnection(Socket socket) { 955 void onConnection(Socket socket) {
940 // Accept the client connection. 956 // Accept the client connection.
941 _HttpConnection connection = new _HttpConnection(this); 957 _HttpConnection connection = new _HttpConnection(this);
942 connection._connectionEstablished(socket); 958 connection._connectionEstablished(socket);
943 _connections.add(connection); 959 _connections.add(connection);
944 connection.onRequestReceived = _handleRequest; 960 connection.onRequestReceived = _handleRequest;
945 connection.onClosed = () => _connections.remove(connection); 961 connection.onClosed = () => _connections.remove(connection);
946 connection.onDetach = () => _connections.remove(connection); 962 connection.onDetach = () => _connections.remove(connection);
947 connection.onError = (e) { 963 connection.onError = (e) {
948 _connections.remove(connection); 964 _connections.remove(connection);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 } else { 1060 } else {
1045 assert(result._isClosing); 1061 assert(result._isClosing);
1046 result.closing++; 1062 result.closing++;
1047 } 1063 }
1048 }); 1064 });
1049 return result; 1065 return result;
1050 } 1066 }
1051 1067
1052 ServerSocket _server; // The server listen socket. 1068 ServerSocket _server; // The server listen socket.
1053 bool _closeServer = false; 1069 bool _closeServer = false;
1070 bool _secure;
1054 Set<_HttpConnection> _connections; // Set of currently connected clients. 1071 Set<_HttpConnection> _connections; // Set of currently connected clients.
1055 List<_RequestHandlerRegistration> _handlers; 1072 List<_RequestHandlerRegistration> _handlers;
1056 Object _defaultHandler; 1073 Object _defaultHandler;
1057 Function _onError; 1074 Function _onError;
1058 _CloseQueue _closeQueue; 1075 _CloseQueue _closeQueue;
1059 _HttpSessionManager _sessionManagerInstance; 1076 _HttpSessionManager _sessionManagerInstance;
1060 } 1077 }
1061 1078
1062 1079
1063 class _HttpClientRequest 1080 class _HttpClientRequest
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 2122
2106 2123
2107 class _RedirectInfo implements RedirectInfo { 2124 class _RedirectInfo implements RedirectInfo {
2108 const _RedirectInfo(int this.statusCode, 2125 const _RedirectInfo(int this.statusCode,
2109 String this.method, 2126 String this.method,
2110 Uri this.location); 2127 Uri this.location);
2111 final int statusCode; 2128 final int statusCode;
2112 final String method; 2129 final String method;
2113 final Uri location; 2130 final Uri location;
2114 } 2131 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http.dart ('k') | tests/standalone/io/https_server_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698