mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-20 03:24:50 +00:00
Merge branch 'method-body-modifier-support' into 'master'
Method body modifier support See merge request videostreaming/grayjay!15
This commit is contained in:
commit
363cdd616d
5 changed files with 40 additions and 8 deletions
4
app/src/main/assets/devportal/plugin.d.ts
vendored
4
app/src/main/assets/devportal/plugin.d.ts
vendored
|
@ -243,7 +243,9 @@ declare class DashSource implements IVideoSource {
|
|||
|
||||
declare interface IRequest {
|
||||
url: string,
|
||||
headers: Map<string, string>
|
||||
headers: Map<string, string>?,
|
||||
method: string?,
|
||||
body: string?
|
||||
}
|
||||
declare interface IRequestModifierDef {
|
||||
allowByteSkip: boolean
|
||||
|
|
|
@ -2,5 +2,7 @@ package com.futo.platformplayer.api.media.models.modifier
|
|||
|
||||
interface IRequest {
|
||||
val url: String?;
|
||||
val headers: Map<String, String>;
|
||||
val headers: Map<String, String>?;
|
||||
val method: String?;
|
||||
val body: String?;
|
||||
}
|
|
@ -13,14 +13,20 @@ class JSRequest : IRequest {
|
|||
private val _v8Url: String?;
|
||||
private val _v8Headers: Map<String, String>?;
|
||||
private val _v8Options: Options?;
|
||||
private val _v8Method: String?;
|
||||
private val _v8Body: String?;
|
||||
|
||||
override var url: String? = null;
|
||||
override lateinit var headers: Map<String, String>;
|
||||
override var method: String? = null;
|
||||
override var body: String? = null;
|
||||
|
||||
constructor(plugin: JSClient, url: String?, headers: Map<String, String>?, options: Options?, originalUrl: String?, originalHeaders: Map<String, String>?) {
|
||||
constructor(plugin: JSClient, url: String?, headers: Map<String, String>?, method: String?, body: String? = null, options: Options?, originalUrl: String?, originalHeaders: Map<String, String>?) {
|
||||
_v8Url = url;
|
||||
_v8Headers = headers;
|
||||
_v8Options = options;
|
||||
_v8Method = method;
|
||||
_v8Body = body;
|
||||
initialize(plugin, originalUrl, originalHeaders);
|
||||
}
|
||||
constructor(plugin: JSClient, obj: V8ValueObject, originalUrl: String?, originalHeaders: Map<String, String>?, applyOtherHeadersByDefault: Boolean = false) {
|
||||
|
@ -31,12 +37,17 @@ class JSRequest : IRequest {
|
|||
_v8Options = obj.getOrDefault<V8ValueObject>(config, "options", "JSRequestModifier.options", null)?.let {
|
||||
Options(config, it, applyOtherHeadersByDefault);
|
||||
} ?: Options(null, null, applyOtherHeadersByDefault);
|
||||
_v8Method = obj.getOrDefault<String>(config, "method", contextName, null);
|
||||
_v8Body = obj.getOrDefault<String>(config, "body", contextName, null);
|
||||
|
||||
initialize(plugin, originalUrl, originalHeaders);
|
||||
}
|
||||
|
||||
private fun initialize(plugin: JSClient, originalUrl: String?, originalHeaders: Map<String, String>?) {
|
||||
val config = plugin.config;
|
||||
url = _v8Url ?: originalUrl;
|
||||
method = _v8Method;
|
||||
body = _v8Body;
|
||||
|
||||
if(_v8Options?.applyOtherHeaders ?: false) {
|
||||
val headersToSet = _v8Headers?.toMutableMap() ?: mutableMapOf();
|
||||
|
@ -70,7 +81,7 @@ class JSRequest : IRequest {
|
|||
}
|
||||
|
||||
fun modify(plugin: JSClient, originalUrl: String?, originalHeaders: Map<String, String>?): JSRequest {
|
||||
return JSRequest(plugin, _v8Url, _v8Headers, _v8Options, originalUrl, originalHeaders);
|
||||
return JSRequest(plugin, _v8Url, _v8Headers, _v8Method, _v8Body, _v8Options, originalUrl, originalHeaders);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,5 +45,8 @@ class JSRequestModifier: IRequestModifier {
|
|||
}
|
||||
|
||||
|
||||
data class Request(override val url: String, override val headers: Map<String, String>) : IRequest;
|
||||
data class Request(override val url: String,
|
||||
override val headers: Map<String, String>,
|
||||
override val method: String? = null,
|
||||
override val body: String? = null) : IRequest;
|
||||
}
|
|
@ -47,6 +47,7 @@ import java.net.HttpURLConnection;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -649,12 +650,25 @@ public class JSHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||
|
||||
requestHeaders.put(HttpHeaders.ACCEPT_ENCODING, allowGzip ? "gzip" : "identity");
|
||||
|
||||
String requestMethod = DataSpec.getStringForHttpMethod(httpMethod);
|
||||
String requestUrl = url.toString();
|
||||
if (requestModifier != null) {
|
||||
IRequest result = requestModifier.modifyRequest(requestUrl, requestHeaders);
|
||||
String modifiedUrl = result.getUrl();
|
||||
requestUrl = (modifiedUrl != null) ? modifiedUrl : requestUrl;
|
||||
requestHeaders = result.getHeaders();
|
||||
if (modifiedUrl != null)
|
||||
requestUrl = modifiedUrl;
|
||||
|
||||
Map<String, String> modifiedHeaders = result.getHeaders();
|
||||
if (modifiedHeaders != null)
|
||||
requestHeaders = modifiedHeaders;
|
||||
|
||||
String modifiedMethod = result.getMethod();
|
||||
if (modifiedMethod != null)
|
||||
requestMethod = modifiedMethod;
|
||||
|
||||
String modifiedBody = result.getBody();
|
||||
if (modifiedBody != null)
|
||||
httpBody = modifiedBody.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
Logger.Companion.v("JSHttpDataSource", "DataSource REQ: " + requestUrl + "\nHEADERS: [" + V8RemoteObject.Companion.getGsonStandard().toJson(requestHeaders)+ "]", null);
|
||||
|
@ -669,7 +683,7 @@ public class JSHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||
|
||||
connection.setInstanceFollowRedirects(followRedirects);
|
||||
connection.setDoOutput(httpBody != null);
|
||||
connection.setRequestMethod(DataSpec.getStringForHttpMethod(httpMethod));
|
||||
connection.setRequestMethod(requestMethod);
|
||||
|
||||
if (httpBody != null) {
|
||||
connection.setFixedLengthStreamingMode(httpBody.length);
|
||||
|
|
Loading…
Add table
Reference in a new issue