Skip to content

Commit

Permalink
chang IRequestClient api
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed Nov 22, 2021
1 parent ef92a80 commit d3aa558
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Object call() throws Exception {
SystemHttpClient client = new SystemHttpClient();

LogUtil.i("== checkHost:" + host);
client.request(request, null, true, null, null, new IRequestClient.RequestClientCompleteHandler() {
client.request(request, new IRequestClient.Options(null, true, null), null, new IRequestClient.RequestClientCompleteHandler() {
@Override
public void complete(ResponseInfo responseInfo, UploadSingleRequestMetrics metrics, JSONObject response) {
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public boolean checkCancel() {
" url:" + StringUtils.toNonnullString(request.urlString) +
" ip:" + StringUtils.toNonnullString(server.getIp()));

client.request(request, server, isAsync, config.proxy, new IRequestClient.RequestClientProgress() {
client.request(request, new IRequestClient.Options(server, isAsync, config.proxy), new IRequestClient.RequestClientProgress() {
@Override
public void progress(long totalBytesWritten, long totalBytesExpectedToWrite) {
if (checkCancelHandler.checkCancel()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public interface RequestClientCompleteHandler {
}

public abstract void request(Request request,
IUploadServer server,
boolean isAsync,
ProxyConfiguration connectionProxy,
Options options,
RequestClientProgress progress,
RequestClientCompleteHandler complete);

Expand All @@ -29,4 +27,16 @@ public abstract void request(Request request,
public String getClientId() {
return "customized";
}

public static class Options {
public final IUploadServer server;
public final boolean isAsync;
public final ProxyConfiguration connectionProxy;

public Options(IUploadServer server, boolean isAsync, ProxyConfiguration connectionProxy) {
this.server = server;
this.isAsync = isAsync;
this.connectionProxy = connectionProxy;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,32 @@ public void request(Request request,
ProxyConfiguration connectionProxy,
RequestClientProgress progress,
RequestClientCompleteHandler complete) {
request(request, null, isAsync, connectionProxy, progress, complete);
request(request, new Options(null, isAsync, connectionProxy), progress, complete);
}

@Override
public void request(Request request,
IUploadServer server,
boolean isAsync,
ProxyConfiguration connectionProxy,
Options options,
RequestClientProgress progress,
RequestClientCompleteHandler complete) {
IUploadServer server = null;
boolean isAsync = true;
ProxyConfiguration connectionProxy = null;
if (options != null) {
server = options.server;
isAsync = options.isAsync;
connectionProxy = options.connectionProxy;
}

metrics = new UploadSingleRequestMetrics();
metrics.start();
metrics.setClientName(getClientId());
metrics.setClientVersion(getOkHttpVersion());
if (server != null) {
currentServer = server;
metrics.setRemoteAddress(server.getIp());
}
metrics.setRequest(request);
currentServer = server;
currentRequest = request;
requestProgress = progress;
completeHandler = complete;
Expand Down

0 comments on commit d3aa558

Please sign in to comment.