< prev index next >

src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 534                         rawin = sslStreams.getInputStream();
 535                         rawout = sslStreams.getOutputStream();
 536                         engine = sslStreams.getSSLEngine();
 537                         connection.sslStreams = sslStreams;
 538                     } else {
 539                         rawin = new BufferedInputStream(
 540                             new Request.ReadStream (
 541                                 ServerImpl.this, chan
 542                         ));
 543                         rawout = new Request.WriteStream (
 544                             ServerImpl.this, chan
 545                         );
 546                     }
 547                     connection.raw = rawin;
 548                     connection.rawout = rawout;
 549                 }
 550                 Request req = new Request (rawin, rawout);
 551                 requestLine = req.requestLine();
 552                 if (requestLine == null) {
 553                     /* connection closed */

 554                     closeConnection(connection);
 555                     return;
 556                 }

 557                 int space = requestLine.indexOf (' ');
 558                 if (space == -1) {
 559                     reject (Code.HTTP_BAD_REQUEST,
 560                             requestLine, "Bad request line");
 561                     return;
 562                 }
 563                 String method = requestLine.substring (0, space);
 564                 int start = space+1;
 565                 space = requestLine.indexOf(' ', start);
 566                 if (space == -1) {
 567                     reject (Code.HTTP_BAD_REQUEST,
 568                             requestLine, "Bad request line");
 569                     return;
 570                 }
 571                 String uriStr = requestLine.substring (start, space);
 572                 URI uri = new URI (uriStr);
 573                 start = space+1;
 574                 String version = requestLine.substring (start);
 575                 Headers headers = req.headers();
 576                 String s = headers.getFirst ("Transfer-encoding");


 780     }
 781 
 782     HttpServer getWrapper () {
 783         return wrapper;
 784     }
 785 
 786     void requestStarted (HttpConnection c) {
 787         c.creationTime = getTime();
 788         c.setState (State.REQUEST);
 789         reqConnections.add (c);
 790     }
 791 
 792     // called after a request has been completely read
 793     // by the server. This stops the timer which would
 794     // close the connection if the request doesn't arrive
 795     // quickly enough. It then starts the timer
 796     // that ensures the client reads the response in a timely
 797     // fashion.
 798 
 799     void requestCompleted (HttpConnection c) {
 800         assert c.getState() == State.REQUEST;

 801         reqConnections.remove (c);
 802         c.rspStartedTime = getTime();
 803         rspConnections.add (c);
 804         c.setState (State.RESPONSE);
 805     }
 806 
 807     // called after response has been sent
 808     void responseCompleted (HttpConnection c) {
 809         assert c.getState() == State.RESPONSE;

 810         rspConnections.remove (c);
 811         c.setState (State.IDLE);
 812     }
 813 
 814     /**
 815      * TimerTask run every CLOCK_TICK ms
 816      */
 817     class ServerTimerTask extends TimerTask {
 818         public void run () {
 819             LinkedList<HttpConnection> toClose = new LinkedList<HttpConnection>();
 820             time = System.currentTimeMillis();
 821             ticks ++;
 822             synchronized (idleConnections) {
 823                 for (HttpConnection c : idleConnections) {
 824                     if (c.time <= time) {
 825                         toClose.add (c);
 826                     }
 827                 }
 828                 for (HttpConnection c : toClose) {
 829                     idleConnections.remove (c);


   1 /*
   2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 534                         rawin = sslStreams.getInputStream();
 535                         rawout = sslStreams.getOutputStream();
 536                         engine = sslStreams.getSSLEngine();
 537                         connection.sslStreams = sslStreams;
 538                     } else {
 539                         rawin = new BufferedInputStream(
 540                             new Request.ReadStream (
 541                                 ServerImpl.this, chan
 542                         ));
 543                         rawout = new Request.WriteStream (
 544                             ServerImpl.this, chan
 545                         );
 546                     }
 547                     connection.raw = rawin;
 548                     connection.rawout = rawout;
 549                 }
 550                 Request req = new Request (rawin, rawout);
 551                 requestLine = req.requestLine();
 552                 if (requestLine == null) {
 553                     /* connection closed */
 554                     logger.log(Level.DEBUG, "no request line: closing");
 555                     closeConnection(connection);
 556                     return;
 557                 }
 558                 logger.log(Level.DEBUG, "Exchange request line: {0}", requestLine);
 559                 int space = requestLine.indexOf (' ');
 560                 if (space == -1) {
 561                     reject (Code.HTTP_BAD_REQUEST,
 562                             requestLine, "Bad request line");
 563                     return;
 564                 }
 565                 String method = requestLine.substring (0, space);
 566                 int start = space+1;
 567                 space = requestLine.indexOf(' ', start);
 568                 if (space == -1) {
 569                     reject (Code.HTTP_BAD_REQUEST,
 570                             requestLine, "Bad request line");
 571                     return;
 572                 }
 573                 String uriStr = requestLine.substring (start, space);
 574                 URI uri = new URI (uriStr);
 575                 start = space+1;
 576                 String version = requestLine.substring (start);
 577                 Headers headers = req.headers();
 578                 String s = headers.getFirst ("Transfer-encoding");


 782     }
 783 
 784     HttpServer getWrapper () {
 785         return wrapper;
 786     }
 787 
 788     void requestStarted (HttpConnection c) {
 789         c.creationTime = getTime();
 790         c.setState (State.REQUEST);
 791         reqConnections.add (c);
 792     }
 793 
 794     // called after a request has been completely read
 795     // by the server. This stops the timer which would
 796     // close the connection if the request doesn't arrive
 797     // quickly enough. It then starts the timer
 798     // that ensures the client reads the response in a timely
 799     // fashion.
 800 
 801     void requestCompleted (HttpConnection c) {
 802         State s = c.getState();
 803         assert s == State.REQUEST : "State is not REQUEST ("+s+")";
 804         reqConnections.remove (c);
 805         c.rspStartedTime = getTime();
 806         rspConnections.add (c);
 807         c.setState (State.RESPONSE);
 808     }
 809 
 810     // called after response has been sent
 811     void responseCompleted (HttpConnection c) {
 812         State s = c.getState();
 813         assert s == State.RESPONSE : "State is not RESPONSE ("+s+")";
 814         rspConnections.remove (c);
 815         c.setState (State.IDLE);
 816     }
 817 
 818     /**
 819      * TimerTask run every CLOCK_TICK ms
 820      */
 821     class ServerTimerTask extends TimerTask {
 822         public void run () {
 823             LinkedList<HttpConnection> toClose = new LinkedList<HttpConnection>();
 824             time = System.currentTimeMillis();
 825             ticks ++;
 826             synchronized (idleConnections) {
 827                 for (HttpConnection c : idleConnections) {
 828                     if (c.time <= time) {
 829                         toClose.add (c);
 830                     }
 831                 }
 832                 for (HttpConnection c : toClose) {
 833                     idleConnections.remove (c);


< prev index next >