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

Head requests for server discovery #943

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion jellyfin-api-ktor/api/jellyfin-api-ktor.api
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class org/jellyfin/sdk/api/ktor/KtorClient : org/jellyfin/sdk/api/client/
public fun getDeviceInfo ()Lorg/jellyfin/sdk/model/DeviceInfo;
public fun getHttpClientOptions ()Lorg/jellyfin/sdk/api/client/HttpClientOptions;
public fun getWebSocket ()Lorg/jellyfin/sdk/api/sockets/SocketApi;
public fun request (Lorg/jellyfin/sdk/api/client/HttpMethod;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun request (Lorg/jellyfin/sdk/api/client/HttpMethod;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/lang/Object;Lkotlin/ranges/IntRange;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun setAccessToken (Ljava/lang/String;)V
public fun setBaseUrl (Ljava/lang/String;)V
public fun setClientInfo (Lorg/jellyfin/sdk/model/ClientInfo;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public expect open class KtorClient(
pathParameters: Map<String, Any?>,
queryParameters: Map<String, Any?>,
requestBody: Any?,
expectedResponse: IntRange,
): RawResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import io.ktor.content.ByteArrayContent
import io.ktor.content.TextContent
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.isSuccess
import io.ktor.util.toMap
import kotlinx.serialization.SerializationException
import mu.KotlinLogging
Expand Down Expand Up @@ -84,6 +83,7 @@ public actual open class KtorClient actual constructor(
pathParameters: Map<String, Any?>,
queryParameters: Map<String, Any?>,
requestBody: Any?,
expectedResponse: IntRange,
): RawResponse {
val url = createUrl(pathTemplate, pathParameters, queryParameters)

Expand Down Expand Up @@ -129,7 +129,7 @@ public actual open class KtorClient actual constructor(
}

// Check HTTP status
if (!response.status.isSuccess()) throw InvalidStatusException(response.status.value)
if (response.status.value !in expectedResponse) throw InvalidStatusException(response.status.value)
// Return custom response instance
return RawResponse(response.bodyAsChannel(), response.status.value, response.headers.toMap())
} catch (err: UnknownHostException) {
Expand Down Expand Up @@ -168,5 +168,6 @@ public actual open class KtorClient actual constructor(
HttpMethod.GET -> KtorHttpMethod.Get
HttpMethod.POST -> KtorHttpMethod.Post
HttpMethod.DELETE -> KtorHttpMethod.Delete
HttpMethod.HEAD -> KtorHttpMethod.Head
}
}
5 changes: 3 additions & 2 deletions jellyfin-api/api/jellyfin-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public abstract class org/jellyfin/sdk/api/client/ApiClient {
public abstract fun getHttpClientOptions ()Lorg/jellyfin/sdk/api/client/HttpClientOptions;
public final fun getOrCreateApi (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)Lorg/jellyfin/sdk/api/operations/Api;
public abstract fun getWebSocket ()Lorg/jellyfin/sdk/api/sockets/SocketApi;
public abstract fun request (Lorg/jellyfin/sdk/api/client/HttpMethod;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun request$default (Lorg/jellyfin/sdk/api/client/ApiClient;Lorg/jellyfin/sdk/api/client/HttpMethod;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/lang/Object;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public abstract fun request (Lorg/jellyfin/sdk/api/client/HttpMethod;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/lang/Object;Lkotlin/ranges/IntRange;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun request$default (Lorg/jellyfin/sdk/api/client/ApiClient;Lorg/jellyfin/sdk/api/client/HttpMethod;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/lang/Object;Lkotlin/ranges/IntRange;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public abstract fun setAccessToken (Ljava/lang/String;)V
public abstract fun setBaseUrl (Ljava/lang/String;)V
public abstract fun setClientInfo (Lorg/jellyfin/sdk/model/ClientInfo;)V
Expand Down Expand Up @@ -48,6 +48,7 @@ public final class org/jellyfin/sdk/api/client/HttpClientOptions {
public final class org/jellyfin/sdk/api/client/HttpMethod : java/lang/Enum {
public static final field DELETE Lorg/jellyfin/sdk/api/client/HttpMethod;
public static final field GET Lorg/jellyfin/sdk/api/client/HttpMethod;
public static final field HEAD Lorg/jellyfin/sdk/api/client/HttpMethod;
public static final field POST Lorg/jellyfin/sdk/api/client/HttpMethod;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lorg/jellyfin/sdk/api/client/HttpMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public abstract class ApiClient {
pathParameters: Map<String, Any?> = emptyMap(),
queryParameters: Map<String, Any?> = emptyMap(),
requestBody: Any? = null,
expectedResponse: IntRange = 200 until 300,
): RawResponse

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public enum class HttpMethod {
GET,
POST,
DELETE,
HEAD,
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,17 @@ public suspend inline fun <reified T : Any> ApiClient.delete(
queryParameters = queryParameters,
requestBody = requestBody
).createResponse()

public suspend inline fun <reified T : Any> ApiClient.head(
pathTemplate: String,
pathParameters: Map<String, Any?> = emptyMap(),
queryParameters: Map<String, Any?> = emptyMap(),
requestBody: Any? = null,
): Response<T> = request(
method = HttpMethod.HEAD,
pathTemplate = pathTemplate,
pathParameters = pathParameters,
queryParameters = queryParameters,
requestBody = requestBody,
expectedResponse = 300 until 400
).createResponse()
30 changes: 24 additions & 6 deletions jellyfin-core/api/android/jellyfin-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public final class org/jellyfin/sdk/discovery/DiscoveryService {
public static synthetic fun discoverLocalServers$default (Lorg/jellyfin/sdk/discovery/DiscoveryService;IIILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow;
public final fun getAddressCandidates (Ljava/lang/String;)Ljava/util/Collection;
public final fun getRecommendedServers (Ljava/lang/String;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getRecommendedServers (Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getRecommendedServers (Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun getRecommendedServers$default (Lorg/jellyfin/sdk/discovery/DiscoveryService;Ljava/lang/String;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun getRecommendedServers$default (Lorg/jellyfin/sdk/discovery/DiscoveryService;Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun getRecommendedServers$default (Lorg/jellyfin/sdk/discovery/DiscoveryService;Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class org/jellyfin/sdk/discovery/LocalServerDiscovery {
Expand All @@ -152,26 +152,31 @@ public final class org/jellyfin/sdk/discovery/LocalServerDiscovery$Companion {

public final class org/jellyfin/sdk/discovery/RecommendedServerDiscovery {
public fun <init> (Lorg/jellyfin/sdk/Jellyfin;)V
public final fun discover (Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun discover (Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun discover$default (Lorg/jellyfin/sdk/discovery/RecommendedServerDiscovery;Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class org/jellyfin/sdk/discovery/RecommendedServerInfo {
public fun <init> (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;)V
public fun <init> (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()J
public final fun component3 ()Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;
public final fun component4 ()Ljava/util/Collection;
public final fun component5-d1pmJ48 ()Ljava/lang/Object;
public final fun copy (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;)Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;
public static synthetic fun copy$default (Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Lkotlin/Result;ILjava/lang/Object;)Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;
public final fun component6 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;Ljava/lang/String;)Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;
public static synthetic fun copy$default (Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Lkotlin/Result;Ljava/lang/String;ILjava/lang/Object;)Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;
public fun equals (Ljava/lang/Object;)Z
public final fun firstIssueOrNull ()Lorg/jellyfin/sdk/discovery/RecommendedServerIssue;
public final fun getAddress ()Ljava/lang/String;
public final fun getIssues ()Ljava/util/Collection;
public final fun getOriginalAddress ()Ljava/lang/String;
public final fun getResponseTime ()J
public final fun getScore ()Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;
public final fun getSystemInfo-d1pmJ48 ()Ljava/lang/Object;
public fun hashCode ()I
public final fun isRedirect ()Z
public fun toString ()Ljava/lang/String;
}

Expand Down Expand Up @@ -228,6 +233,19 @@ public final class org/jellyfin/sdk/discovery/RecommendedServerIssue$OutdatedSer
public fun toString ()Ljava/lang/String;
}

public final class org/jellyfin/sdk/discovery/RecommendedServerIssue$RedirectedResponse : org/jellyfin/sdk/discovery/RecommendedServerIssue {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;)Lorg/jellyfin/sdk/discovery/RecommendedServerIssue$RedirectedResponse;
public static synthetic fun copy$default (Lorg/jellyfin/sdk/discovery/RecommendedServerIssue$RedirectedResponse;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lorg/jellyfin/sdk/discovery/RecommendedServerIssue$RedirectedResponse;
public fun equals (Ljava/lang/Object;)Z
public final fun getFinalAddress ()Ljava/lang/String;
public final fun getOriginalAddress ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class org/jellyfin/sdk/discovery/RecommendedServerIssue$SecureConnectionFailed : org/jellyfin/sdk/discovery/RecommendedServerIssue {
public fun <init> (Lorg/jellyfin/sdk/api/client/exception/SecureConnectionException;)V
public final fun component1 ()Lorg/jellyfin/sdk/api/client/exception/SecureConnectionException;
Expand Down
30 changes: 24 additions & 6 deletions jellyfin-core/api/jvm/jellyfin-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public final class org/jellyfin/sdk/discovery/DiscoveryService {
public static synthetic fun discoverLocalServers$default (Lorg/jellyfin/sdk/discovery/DiscoveryService;IIILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow;
public final fun getAddressCandidates (Ljava/lang/String;)Ljava/util/Collection;
public final fun getRecommendedServers (Ljava/lang/String;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getRecommendedServers (Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getRecommendedServers (Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun getRecommendedServers$default (Lorg/jellyfin/sdk/discovery/DiscoveryService;Ljava/lang/String;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun getRecommendedServers$default (Lorg/jellyfin/sdk/discovery/DiscoveryService;Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun getRecommendedServers$default (Lorg/jellyfin/sdk/discovery/DiscoveryService;Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class org/jellyfin/sdk/discovery/LocalServerDiscovery {
Expand All @@ -144,26 +144,31 @@ public final class org/jellyfin/sdk/discovery/LocalServerDiscovery$Companion {

public final class org/jellyfin/sdk/discovery/RecommendedServerDiscovery {
public fun <init> (Lorg/jellyfin/sdk/Jellyfin;)V
public final fun discover (Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun discover (Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun discover$default (Lorg/jellyfin/sdk/discovery/RecommendedServerDiscovery;Ljava/util/Collection;Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class org/jellyfin/sdk/discovery/RecommendedServerInfo {
public fun <init> (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;)V
public fun <init> (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()J
public final fun component3 ()Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;
public final fun component4 ()Ljava/util/Collection;
public final fun component5-d1pmJ48 ()Ljava/lang/Object;
public final fun copy (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;)Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;
public static synthetic fun copy$default (Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Lkotlin/Result;ILjava/lang/Object;)Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;
public final fun component6 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Ljava/lang/Object;Ljava/lang/String;)Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;
public static synthetic fun copy$default (Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;Ljava/lang/String;JLorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;Ljava/util/Collection;Lkotlin/Result;Ljava/lang/String;ILjava/lang/Object;)Lorg/jellyfin/sdk/discovery/RecommendedServerInfo;
public fun equals (Ljava/lang/Object;)Z
public final fun firstIssueOrNull ()Lorg/jellyfin/sdk/discovery/RecommendedServerIssue;
public final fun getAddress ()Ljava/lang/String;
public final fun getIssues ()Ljava/util/Collection;
public final fun getOriginalAddress ()Ljava/lang/String;
public final fun getResponseTime ()J
public final fun getScore ()Lorg/jellyfin/sdk/discovery/RecommendedServerInfoScore;
public final fun getSystemInfo-d1pmJ48 ()Ljava/lang/Object;
public fun hashCode ()I
public final fun isRedirect ()Z
public fun toString ()Ljava/lang/String;
}

Expand Down Expand Up @@ -220,6 +225,19 @@ public final class org/jellyfin/sdk/discovery/RecommendedServerIssue$OutdatedSer
public fun toString ()Ljava/lang/String;
}

public final class org/jellyfin/sdk/discovery/RecommendedServerIssue$RedirectedResponse : org/jellyfin/sdk/discovery/RecommendedServerIssue {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;)Lorg/jellyfin/sdk/discovery/RecommendedServerIssue$RedirectedResponse;
public static synthetic fun copy$default (Lorg/jellyfin/sdk/discovery/RecommendedServerIssue$RedirectedResponse;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lorg/jellyfin/sdk/discovery/RecommendedServerIssue$RedirectedResponse;
public fun equals (Ljava/lang/Object;)Z
public final fun getFinalAddress ()Ljava/lang/String;
public final fun getOriginalAddress ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class org/jellyfin/sdk/discovery/RecommendedServerIssue$SecureConnectionFailed : org/jellyfin/sdk/discovery/RecommendedServerIssue {
public fun <init> (Lorg/jellyfin/sdk/api/client/exception/SecureConnectionException;)V
public final fun component1 ()Lorg/jellyfin/sdk/api/client/exception/SecureConnectionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public class DiscoveryService(
public suspend fun getRecommendedServers(
servers: Collection<String>,
minimumScore: RecommendedServerInfoScore = RecommendedServerInfoScore.BAD,
followRedirects: Boolean = false,
): Collection<RecommendedServerInfo> = recommendedServerDiscovery.discover(
servers = servers,
minimumScore = minimumScore
minimumScore = minimumScore,
followRedirects = followRedirects
)

/**
Expand Down
Loading
Loading