From d048af3b4452f3dd363f56ac1445610401ac960c Mon Sep 17 00:00:00 2001 From: genuineparts Date: Fri, 17 Mar 2017 22:22:44 +0100 Subject: [PATCH] Shots at the dark --- .../youploader/youtube/upload/SimpleHTTP.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/becast/youploader/youtube/upload/SimpleHTTP.java b/src/main/java/at/becast/youploader/youtube/upload/SimpleHTTP.java index ac2b6a7..a29f525 100644 --- a/src/main/java/at/becast/youploader/youtube/upload/SimpleHTTP.java +++ b/src/main/java/at/becast/youploader/youtube/upload/SimpleHTTP.java @@ -5,6 +5,7 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpVersion; import org.apache.http.StatusLine; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; @@ -34,14 +35,19 @@ public class SimpleHTTP { private CloseableHttpResponse response; private boolean aborted = false; private static final Logger LOG = LoggerFactory.getLogger(SimpleHTTP.class); - + private RequestConfig config; + public SimpleHTTP() { this.chc = HttpClients.createDefault(); + config = RequestConfig.custom() + .setExpectContinueEnabled(true) + .build(); } public String[] post(String url, Map headers, String body) throws IOException, UploadException { HttpPost post = new HttpPost(url); post.setProtocolVersion(HttpVersion.HTTP_1_1); + post.setConfig(config); for (String key : headers.keySet()) { post.setHeader(key, headers.get(key)); } @@ -74,6 +80,7 @@ public String[] post(String url, Map headers, String body) throw public void postPL(String url, Map headers, String body) throws IOException, UploadException { HttpPost post = new HttpPost(url); + post.setConfig(config); post.setProtocolVersion(HttpVersion.HTTP_1_1); for (String key : headers.keySet()) { post.setHeader(key, headers.get(key)); @@ -126,6 +133,7 @@ public boolean accept(File file) { public void put(String url, Map headers, BufferedInputStream stream, UploadEvent callback) throws IOException { this.put = new HttpPut(url); this.put.setProtocolVersion(HttpVersion.HTTP_1_1); + this.put.setConfig(config); for (String key : headers.keySet()) { this.put.setHeader(key, headers.get(key)); } @@ -154,6 +162,7 @@ public void put(String url, Map headers, BufferedInputStream str public void put(String url, Map headers, String body) throws IOException { this.put = new HttpPut(url); this.put.setProtocolVersion(HttpVersion.HTTP_1_1); + this.put.setConfig(config); for (String key : headers.keySet()) { this.put.setHeader(key, headers.get(key)); } @@ -171,6 +180,7 @@ public void put(String url, Map headers, String body) throws IOE public void post(String url, Map headers, File body) throws IOException { HttpPost post = new HttpPost(url); post.setProtocolVersion(HttpVersion.HTTP_1_1); + post.setConfig(config); for (String key : headers.keySet()) { post.setHeader(key, headers.get(key)); } @@ -187,7 +197,8 @@ public void post(String url, Map headers, File body) throws IOEx public long put(String url, Map headers) throws IOException { this.put = new HttpPut(url); - + this.put.setProtocolVersion(HttpVersion.HTTP_1_1); + this.put.setConfig(config); for (String key : headers.keySet()) { this.put.setHeader(key, headers.get(key)); }