test/jdk/java/net/httpclient/DigestEchoServer.java
changeset 53350 a47b8125b7cc
parent 52387 8c0b1894d524
child 54579 270557b396eb
equal deleted inserted replaced
53349:d3aa93570779 53350:a47b8125b7cc
     1 /*
     1 /*
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    39 import java.net.InetSocketAddress;
    39 import java.net.InetSocketAddress;
    40 import java.net.MalformedURLException;
    40 import java.net.MalformedURLException;
    41 import java.net.PasswordAuthentication;
    41 import java.net.PasswordAuthentication;
    42 import java.net.ServerSocket;
    42 import java.net.ServerSocket;
    43 import java.net.Socket;
    43 import java.net.Socket;
       
    44 import java.net.StandardSocketOptions;
    44 import java.net.URI;
    45 import java.net.URI;
    45 import java.net.URISyntaxException;
    46 import java.net.URISyntaxException;
    46 import java.net.URL;
    47 import java.net.URL;
    47 import java.nio.charset.StandardCharsets;
    48 import java.nio.charset.StandardCharsets;
    48 import java.security.MessageDigest;
    49 import java.security.MessageDigest;
    75  */
    76  */
    76 public abstract class DigestEchoServer implements HttpServerAdapters {
    77 public abstract class DigestEchoServer implements HttpServerAdapters {
    77 
    78 
    78     public static final boolean DEBUG =
    79     public static final boolean DEBUG =
    79             Boolean.parseBoolean(System.getProperty("test.debug", "false"));
    80             Boolean.parseBoolean(System.getProperty("test.debug", "false"));
       
    81     public static final boolean NO_LINGER =
       
    82             Boolean.parseBoolean(System.getProperty("test.nolinger", "false"));
    80     public enum HttpAuthType {
    83     public enum HttpAuthType {
    81         SERVER, PROXY, SERVER307, PROXY305
    84         SERVER, PROXY, SERVER307, PROXY305
    82         /* add PROXY_AND_SERVER and SERVER_PROXY_NONE */
    85         /* add PROXY_AND_SERVER and SERVER_PROXY_NONE */
    83     };
    86     };
    84     public enum HttpAuthSchemeType { NONE, BASICSERVER, BASIC, DIGEST };
    87     public enum HttpAuthSchemeType { NONE, BASICSERVER, BASIC, DIGEST };
  1601                 while (!stopped) {
  1604                 while (!stopped) {
  1602                     System.out.println(now() + "Tunnel: Waiting for client");
  1605                     System.out.println(now() + "Tunnel: Waiting for client");
  1603                     Socket toClose;
  1606                     Socket toClose;
  1604                     try {
  1607                     try {
  1605                         toClose = clientConnection = ss.accept();
  1608                         toClose = clientConnection = ss.accept();
       
  1609                         if (NO_LINGER) {
       
  1610                             // can be useful to trigger "Connection reset by peer"
       
  1611                             // errors on the client side.
       
  1612                             clientConnection.setOption(StandardSocketOptions.SO_LINGER, 0);
       
  1613                         }
  1606                     } catch (IOException io) {
  1614                     } catch (IOException io) {
  1607                         if (DEBUG || !stopped) io.printStackTrace(System.out);
  1615                         if (DEBUG || !stopped) io.printStackTrace(System.out);
  1608                         break;
  1616                         break;
  1609                     }
  1617                     }
  1610                     System.out.println(now() + "Tunnel: Client accepted");
  1618                     System.out.println(now() + "Tunnel: Client accepted");