From cd37235110d6712204c77e2bdc463e84af6ed4e3 Mon Sep 17 00:00:00 2001 From: "hyunik.na" Date: Tue, 2 Jul 2019 23:40:13 +0900 Subject: [PATCH] removed remoteHostName from HTTPSession: it can take too long time to figure out via DNS --- .../nanohttpd/protocols/http/HTTPSession.java | 10 +--------- .../nanohttpd/protocols/http/IHTTPSession.java | 7 ------- .../protocols/http/HttpSessionHeadersTest.java | 1 - .../junit/protocols/http/HttpSessionTest.java | 18 ------------------ 4 files changed, 1 insertion(+), 35 deletions(-) diff --git a/core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java b/core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java index e8df933..80456b0 100644 --- a/core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java +++ b/core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java @@ -72,7 +72,7 @@ import org.nanohttpd.protocols.http.tempfiles.ITempFile; import org.nanohttpd.protocols.http.tempfiles.ITempFileManager; public class HTTPSession implements IHTTPSession { - + public static final String POST_DATA = "postData"; private static final int REQUEST_BUFFER_LEN = 512; @@ -109,8 +109,6 @@ public class HTTPSession implements IHTTPSession { private String remoteIp; - private String remoteHostname; - private String protocolVersion; public HTTPSession(NanoHTTPD httpd, ITempFileManager tempFileManager, InputStream inputStream, OutputStream outputStream) { @@ -126,7 +124,6 @@ public class HTTPSession implements IHTTPSession { this.inputStream = new BufferedInputStream(inputStream, HTTPSession.BUFSIZE); this.outputStream = outputStream; this.remoteIp = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "127.0.0.1" : inetAddress.getHostAddress().toString(); - this.remoteHostname = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "localhost" : inetAddress.getHostName().toString(); this.headers = new HashMap(); } @@ -698,9 +695,4 @@ public class HTTPSession implements IHTTPSession { public String getRemoteIpAddress() { return this.remoteIp; } - - @Override - public String getRemoteHostName() { - return this.remoteHostname; - } } diff --git a/core/src/main/java/org/nanohttpd/protocols/http/IHTTPSession.java b/core/src/main/java/org/nanohttpd/protocols/http/IHTTPSession.java index 9e974be..5964885 100644 --- a/core/src/main/java/org/nanohttpd/protocols/http/IHTTPSession.java +++ b/core/src/main/java/org/nanohttpd/protocols/http/IHTTPSession.java @@ -90,11 +90,4 @@ public interface IHTTPSession { * @return the IP address. */ String getRemoteIpAddress(); - - /** - * Get the remote hostname of the requester. - * - * @return the hostname. - */ - String getRemoteHostName(); } diff --git a/core/src/test/java/org/nanohttpd/junit/protocols/http/HttpSessionHeadersTest.java b/core/src/test/java/org/nanohttpd/junit/protocols/http/HttpSessionHeadersTest.java index 5d655de..52e6a3f 100644 --- a/core/src/test/java/org/nanohttpd/junit/protocols/http/HttpSessionHeadersTest.java +++ b/core/src/test/java/org/nanohttpd/junit/protocols/http/HttpSessionHeadersTest.java @@ -60,7 +60,6 @@ public class HttpSessionHeadersTest extends HttpServerTest { for (String ipAddress : ipAddresses) { InetAddress inetAddress = InetAddress.getByName(ipAddress); HTTPSession session = this.testServer.createSession(HttpSessionHeadersTest.TEST_TEMP_FILE_MANAGER, inputStream, outputStream, inetAddress); - assertNotNull(ipAddress, session.getRemoteHostName()); assertEquals(ipAddress, session.getRemoteIpAddress()); } } diff --git a/core/src/test/java/org/nanohttpd/junit/protocols/http/HttpSessionTest.java b/core/src/test/java/org/nanohttpd/junit/protocols/http/HttpSessionTest.java index 0b08687..584efcd 100644 --- a/core/src/test/java/org/nanohttpd/junit/protocols/http/HttpSessionTest.java +++ b/core/src/test/java/org/nanohttpd/junit/protocols/http/HttpSessionTest.java @@ -49,24 +49,6 @@ public class HttpSessionTest extends HttpServerTest { private static final TestTempFileManager TEST_TEMP_FILE_MANAGER = new TestTempFileManager(); - @Test - public void testSessionRemoteHostnameLocalhost() throws UnknownHostException { - ByteArrayInputStream inputStream = new ByteArrayInputStream(HttpSessionTest.DUMMY_REQUEST_CONTENT.getBytes()); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - InetAddress inetAddress = InetAddress.getByName("127.0.0.1"); - HTTPSession session = this.testServer.createSession(HttpSessionTest.TEST_TEMP_FILE_MANAGER, inputStream, outputStream, inetAddress); - assertEquals("localhost", session.getRemoteHostName()); - } - - @Test - public void testSessionRemoteHostname() throws UnknownHostException { - ByteArrayInputStream inputStream = new ByteArrayInputStream(HttpSessionTest.DUMMY_REQUEST_CONTENT.getBytes()); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - InetAddress inetAddress = InetAddress.getByName("google.com"); - HTTPSession session = this.testServer.createSession(HttpSessionTest.TEST_TEMP_FILE_MANAGER, inputStream, outputStream, inetAddress); - assertEquals("google.com", session.getRemoteHostName()); - } - @Test public void testSessionRemoteIPAddress() throws UnknownHostException { ByteArrayInputStream inputStream = new ByteArrayInputStream(HttpSessionTest.DUMMY_REQUEST_CONTENT.getBytes());