Skip to content

Added Safe Close for InputStream in execute's method finally block. #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -20,6 +20,6 @@ subprojects {
}
}

task wrapper(type: Wrapper) {
wrapper {
gradleVersion = "4.4.1"
}
12 changes: 9 additions & 3 deletions core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java
Original file line number Diff line number Diff line change
@@ -154,9 +154,12 @@ private void decodeHeader(BufferedReader in, Map<String, String> pre, Map<String
// Decode parameters from the URI
int qmi = uri.indexOf('?');
if (qmi >= 0) {
decodeParms(uri.substring(qmi + 1), parms);
// decodeParms(uri.substring(qmi + 1), parms);
queryParameterString = uri.substring(qmi + 1);
decodeParms(queryParameterString, parms);
uri = NanoHTTPD.decodePercent(uri.substring(0, qmi));
} else {
queryParameterString = "";
uri = NanoHTTPD.decodePercent(uri);
}

@@ -305,11 +308,11 @@ private int scipOverNewLine(byte[] partHeaderBuff, int index) {
*/
private void decodeParms(String parms, Map<String, List<String>> p) {
if (parms == null) {
this.queryParameterString = "";
// this.queryParameterString = "";
return;
}

this.queryParameterString = parms;
// this.queryParameterString = parms;
StringTokenizer st = new StringTokenizer(parms, "&");
while (st.hasMoreTokens()) {
String e = st.nextToken();
@@ -456,6 +459,9 @@ public void execute() throws IOException {
NanoHTTPD.safeClose(this.outputStream);
} finally {
NanoHTTPD.safeClose(r);
if(r.getRequestMethod() == Method.POST) {
NanoHTTPD.safeClose(this.inputStream);
}
this.tempFileManager.clear();
}
}
Original file line number Diff line number Diff line change
@@ -349,7 +349,13 @@ private void sendBody(OutputStream outputStream, long pending) throws IOExceptio
long bytesToRead = sendEverything ? BUFFER_SIZE : Math.min(pending, BUFFER_SIZE);
int read = this.data.read(buff, 0, (int) bytesToRead);
if (read <= 0) {
break;
if(this.getRequestMethod() == Method.POST) {
break;
}
else {
Thread.sleep(1000);
continue;
}
}
try {
outputStream.write(buff, 0, read);