forked from MirrorHub/authlib-injector
nanohttpd: refactor: replace remoteIpAddress & remoteHostName with remoteAddress
This commit is contained in:
parent
665a400f04
commit
5ca213f5cc
2 changed files with 9 additions and 29 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2019 Haowei Wen <yushijinhun@gmail.com> and contributors
|
* Copyright (C) 2020 Haowei Wen <yushijinhun@gmail.com> and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -48,6 +48,7 @@ package moe.yushi.authlibinjector.internal.fi.iki.elonen;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -74,17 +75,5 @@ public interface IHTTPSession {
|
||||||
*/
|
*/
|
||||||
String getUri();
|
String getUri();
|
||||||
|
|
||||||
/**
|
InetSocketAddress getRemoteAddress();
|
||||||
* Get the remote ip address of the requester.
|
|
||||||
*
|
|
||||||
* @return the IP address.
|
|
||||||
*/
|
|
||||||
String getRemoteIpAddress();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the remote hostname of the requester.
|
|
||||||
*
|
|
||||||
* @return the hostname.
|
|
||||||
*/
|
|
||||||
String getRemoteHostName();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
@ -110,7 +109,7 @@ public abstract class NanoHTTPD {
|
||||||
OutputStream outputStream = null;
|
OutputStream outputStream = null;
|
||||||
try {
|
try {
|
||||||
outputStream = this.acceptSocket.getOutputStream();
|
outputStream = this.acceptSocket.getOutputStream();
|
||||||
HTTPSession session = new HTTPSession(this.inputStream, outputStream, this.acceptSocket.getInetAddress());
|
HTTPSession session = new HTTPSession(this.inputStream, outputStream, (InetSocketAddress) this.acceptSocket.getRemoteSocketAddress());
|
||||||
while (!this.acceptSocket.isClosed()) {
|
while (!this.acceptSocket.isClosed()) {
|
||||||
session.execute();
|
session.execute();
|
||||||
}
|
}
|
||||||
|
@ -176,6 +175,7 @@ public abstract class NanoHTTPD {
|
||||||
|
|
||||||
private final OutputStream outputStream;
|
private final OutputStream outputStream;
|
||||||
private final BufferedInputStream inputStream;
|
private final BufferedInputStream inputStream;
|
||||||
|
private final InetSocketAddress remoteAddr;
|
||||||
|
|
||||||
private String uri;
|
private String uri;
|
||||||
private String method;
|
private String method;
|
||||||
|
@ -186,19 +186,15 @@ public abstract class NanoHTTPD {
|
||||||
|
|
||||||
private InputStream parsedInputStream;
|
private InputStream parsedInputStream;
|
||||||
|
|
||||||
private final String remoteIp;
|
|
||||||
private final String remoteHostname;
|
|
||||||
|
|
||||||
private boolean expect100Continue;
|
private boolean expect100Continue;
|
||||||
private boolean continueSent;
|
private boolean continueSent;
|
||||||
private boolean isServing;
|
private boolean isServing;
|
||||||
private final Object servingLock = new Object();
|
private final Object servingLock = new Object();
|
||||||
|
|
||||||
public HTTPSession(InputStream inputStream, OutputStream outputStream, InetAddress inetAddress) {
|
public HTTPSession(InputStream inputStream, OutputStream outputStream, InetSocketAddress remoteAddr) {
|
||||||
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();
|
this.remoteAddr = remoteAddr;
|
||||||
this.remoteHostname = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "localhost" : inetAddress.getHostName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseHeader(BufferedReader in) throws ResponseException {
|
private void parseHeader(BufferedReader in) throws ResponseException {
|
||||||
|
@ -450,13 +446,8 @@ public abstract class NanoHTTPD {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRemoteIpAddress() {
|
public InetSocketAddress getRemoteAddress() {
|
||||||
return this.remoteIp;
|
return this.remoteAddr;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRemoteHostName() {
|
|
||||||
return this.remoteHostname;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue