Skip to content

Commit

Permalink
feat: NetTransporter implements peek method.
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Jan 26, 2023
1 parent 6e66798 commit f112d18
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/bee/api/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpRetryException;
import java.net.URI;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.Builder;
import java.net.http.HttpResponse;
import java.nio.ByteBuffer;
import java.time.LocalDate;
Expand Down Expand Up @@ -924,7 +927,14 @@ public void put(PutTask task) throws Exception {
*/
@Override
public void peek(PeekTask task) throws Exception {
throw new Error("HTTP PEEK is not implemented, please FIX.");
URI uri = URI.create(repository.getUrl() + task.getLocation());
Builder request = HttpRequest.newBuilder(uri).HEAD();
I.http(request, HttpResponse.class).waitForTerminate().to((WiseConsumer<HttpResponse>) res -> {
int code = res.statusCode();
if (400 <= code) {
throw new HttpRetryException("Fail to peek resource [" + uri + "]", code);
}
});
}

/**
Expand Down

0 comments on commit f112d18

Please sign in to comment.