Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
Shots at the dark
Browse files Browse the repository at this point in the history
  • Loading branch information
becast committed Mar 17, 2017
1 parent 2ac8057 commit d048af3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/at/becast/youploader/youtube/upload/SimpleHTTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> 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));
}
Expand Down Expand Up @@ -74,6 +80,7 @@ public String[] post(String url, Map<String, String> headers, String body) throw

public void postPL(String url, Map<String, String> 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));
Expand Down Expand Up @@ -126,6 +133,7 @@ public boolean accept(File file) {
public void put(String url, Map<String, String> 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));
}
Expand Down Expand Up @@ -154,6 +162,7 @@ public void put(String url, Map<String, String> headers, BufferedInputStream str
public void put(String url, Map<String, String> 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));
}
Expand All @@ -171,6 +180,7 @@ public void put(String url, Map<String, String> headers, String body) throws IOE
public void post(String url, Map<String, String> 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));
}
Expand All @@ -187,7 +197,8 @@ public void post(String url, Map<String, String> headers, File body) throws IOEx

public long put(String url, Map<String, String> 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));
}
Expand Down

0 comments on commit d048af3

Please sign in to comment.