Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a hook after connection is established #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ dependencies {
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
archiveClassifier.set("sources")
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
archiveClassifier.set("javadoc")
from javadoc.destinationDir
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/tus/java/client/TusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public TusUploader createUpload(@NotNull TusUpload upload) throws ProtocolExcept
throw new ProtocolException("missing upload URL in response for creating upload", connection);
}

onConnectionOpened(connection);

// The upload URL must be relative to the URL of the request by which is was returned,
// not the upload creation URL. In most cases, there is no difference between those two
// but there may be cases in which the POST request is redirected.
Expand All @@ -168,6 +170,13 @@ public TusUploader createUpload(@NotNull TusUpload upload) throws ProtocolExcept
return new TusUploader(this, uploadURL, upload.getTusInputStream(), 0);
}

/**
* Hook for subclasses to do any post-open tasks
*
* @param urlConnection
*/
protected void onConnectionOpened(HttpURLConnection urlConnection) {}

/**
* Try to resume an already started upload. Before call this function, resuming must be
* enabled using {@link #enableResuming(TusURLStore)}. This method will look up the URL for this
Expand Down Expand Up @@ -212,6 +221,8 @@ public TusUploader resumeUpload(@NotNull TusUpload upload) throws FingerprintNot
}
long offset = Long.parseLong(offsetStr);

onConnectionOpened(connection);

return new TusUploader(this, uploadURL, upload.getTusInputStream(), offset);
}

Expand Down