Skip to content
Merged
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
25 changes: 23 additions & 2 deletions Library/src/main/java/boxresin/library/javahttp/HttpRequester.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package boxresin.library.javahttp;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -217,8 +218,7 @@ public void clearHeaders()
* Send HTTP request to a web server.
*
* @throws SocketTimeoutException Occurs when timeout.
* @return An HTML response from the web server. It will return null if 'cancel' method is
* called during request.
* @return An HTML response from the web server.
*/
@NotNull
public HttpResponse request() throws SocketTimeoutException, IOException
Expand Down Expand Up @@ -277,4 +277,25 @@ public HttpResponse request() throws SocketTimeoutException, IOException
connection.disconnect();
return new HttpResponse(statusCode, statusMessage, bufferStream, connection);
}

/**
* Send HTTP request to a web server.
*
* @param autoRedirection If it set to true, detect and re-request new URL automatically.
* @throws SocketTimeoutException Occurs when timeout.
* @return An HTML response from the web server.
*/
@NotNull
public HttpResponse request(boolean autoRedirection) throws SocketTimeoutException, IOException
{
HttpResponse response = request();
@Nullable String newUrl = response.getHeader("Location");

if (autoRedirection && newUrl != null)
{
setUrl(newUrl);
return request(true);
}
else return response;
}
}