Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: 添加SenderFactory,并支持为每一个Sender添加Proxy设置
- Loading branch information
Showing
3 changed files
with
98 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.nutz.http; | ||
|
||
public interface SenderFactory { | ||
|
||
Sender create(Request request); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.nutz.http.sender; | ||
|
||
import java.io.File; | ||
|
||
import org.nutz.http.Request; | ||
import org.nutz.http.Sender; | ||
import org.nutz.http.SenderFactory; | ||
|
||
public class DefaultSenderFactory implements SenderFactory { | ||
|
||
public Sender create(Request request) { | ||
if (request.isGet() || request.isDelete()) | ||
return new GetSender(request); | ||
if ((request.isPost() || request.isPut()) && request.getParams() != null) { | ||
for (Object val : request.getParams().values()) { | ||
if (val instanceof File || val instanceof File[]) { | ||
return new FilePostSender(request); | ||
} | ||
} | ||
} | ||
return new PostSender(request); | ||
} | ||
} |