Skip to content

Commit

Permalink
removed remoteHostName from HTTPSession: it can take too long time to…
Browse files Browse the repository at this point in the history
… figure out via DNS
  • Loading branch information
hyunik.na committed Jul 2, 2019
1 parent b04a342 commit cd37235
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 35 deletions.
Expand Up @@ -72,7 +72,7 @@
import org.nanohttpd.protocols.http.tempfiles.ITempFileManager; import org.nanohttpd.protocols.http.tempfiles.ITempFileManager;


public class HTTPSession implements IHTTPSession { public class HTTPSession implements IHTTPSession {

public static final String POST_DATA = "postData"; public static final String POST_DATA = "postData";


private static final int REQUEST_BUFFER_LEN = 512; private static final int REQUEST_BUFFER_LEN = 512;
Expand Down Expand Up @@ -109,8 +109,6 @@ public class HTTPSession implements IHTTPSession {


private String remoteIp; private String remoteIp;


private String remoteHostname;

private String protocolVersion; private String protocolVersion;


public HTTPSession(NanoHTTPD httpd, ITempFileManager tempFileManager, InputStream inputStream, OutputStream outputStream) { public HTTPSession(NanoHTTPD httpd, ITempFileManager tempFileManager, InputStream inputStream, OutputStream outputStream) {
Expand All @@ -126,7 +124,6 @@ public HTTPSession(NanoHTTPD httpd, ITempFileManager tempFileManager, InputStrea
this.inputStream = new BufferedInputStream(inputStream, HTTPSession.BUFSIZE); this.inputStream = new BufferedInputStream(inputStream, HTTPSession.BUFSIZE);
this.outputStream = outputStream; this.outputStream = outputStream;
this.remoteIp = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "127.0.0.1" : inetAddress.getHostAddress().toString(); 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<String, String>(); this.headers = new HashMap<String, String>();
} }


Expand Down Expand Up @@ -698,9 +695,4 @@ private String saveTmpFile(ByteBuffer b, int offset, int len, String filename_hi
public String getRemoteIpAddress() { public String getRemoteIpAddress() {
return this.remoteIp; return this.remoteIp;
} }

@Override
public String getRemoteHostName() {
return this.remoteHostname;
}
} }
Expand Up @@ -90,11 +90,4 @@ public interface IHTTPSession {
* @return the IP address. * @return the IP address.
*/ */
String getRemoteIpAddress(); String getRemoteIpAddress();

/**
* Get the remote hostname of the requester.
*
* @return the hostname.
*/
String getRemoteHostName();
} }
Expand Up @@ -60,7 +60,6 @@ public void testHeadersRemoteIp() throws Exception {
for (String ipAddress : ipAddresses) { for (String ipAddress : ipAddresses) {
InetAddress inetAddress = InetAddress.getByName(ipAddress); InetAddress inetAddress = InetAddress.getByName(ipAddress);
HTTPSession session = this.testServer.createSession(HttpSessionHeadersTest.TEST_TEMP_FILE_MANAGER, inputStream, outputStream, inetAddress); HTTPSession session = this.testServer.createSession(HttpSessionHeadersTest.TEST_TEMP_FILE_MANAGER, inputStream, outputStream, inetAddress);
assertNotNull(ipAddress, session.getRemoteHostName());
assertEquals(ipAddress, session.getRemoteIpAddress()); assertEquals(ipAddress, session.getRemoteIpAddress());
} }
} }
Expand Down
Expand Up @@ -49,24 +49,6 @@ public class HttpSessionTest extends HttpServerTest {


private static final TestTempFileManager TEST_TEMP_FILE_MANAGER = new TestTempFileManager(); 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 @Test
public void testSessionRemoteIPAddress() throws UnknownHostException { public void testSessionRemoteIPAddress() throws UnknownHostException {
ByteArrayInputStream inputStream = new ByteArrayInputStream(HttpSessionTest.DUMMY_REQUEST_CONTENT.getBytes()); ByteArrayInputStream inputStream = new ByteArrayInputStream(HttpSessionTest.DUMMY_REQUEST_CONTENT.getBytes());
Expand Down

0 comments on commit cd37235

Please sign in to comment.