提交 2b96c634 编写于 作者: Q qiang

feat(App): request with ArrayBuffer

上级 470056cd
...@@ -7543,11 +7543,15 @@ var serviceContext = (function () { ...@@ -7543,11 +7543,15 @@ var serviceContext = (function () {
firstIpv4: firstIpv4, firstIpv4: firstIpv4,
tls tls
}; };
let withArrayBuffer;
if (method !== 'GET') { if (method !== 'GET') {
if (toString.call(data) === '[object ArrayBuffer]') {
withArrayBuffer = true;
} else {
options.body = typeof data === 'string' ? data : JSON.stringify(data); options.body = typeof data === 'string' ? data : JSON.stringify(data);
} }
try { }
stream.fetch(options, ({ const callback = ({
ok, ok,
status, status,
data, data,
...@@ -7582,7 +7586,16 @@ var serviceContext = (function () { ...@@ -7582,7 +7586,16 @@ var serviceContext = (function () {
errMsg errMsg
}); });
} }
}); };
try {
if (withArrayBuffer) {
stream.fetchWithArrayBuffer({
'@type': 'binary',
base64: arrayBufferToBase64$2(data)
}, options, callback);
} else {
stream.fetch(options, callback);
}
requestTasks[requestTaskId] = { requestTasks[requestTaskId] = {
abort () { abort () {
aborted = true; aborted = true;
...@@ -15794,7 +15807,7 @@ var serviceContext = (function () { ...@@ -15794,7 +15807,7 @@ var serviceContext = (function () {
var zstream = ZStream; var zstream = ZStream;
var toString = Object.prototype.toString; var toString$1 = Object.prototype.toString;
/* Public constants ==========================================================*/ /* Public constants ==========================================================*/
/* ===========================================================================*/ /* ===========================================================================*/
...@@ -15958,7 +15971,7 @@ var serviceContext = (function () { ...@@ -15958,7 +15971,7 @@ var serviceContext = (function () {
if (typeof opt.dictionary === 'string') { if (typeof opt.dictionary === 'string') {
// If we need to compress text, change encoding to utf8. // If we need to compress text, change encoding to utf8.
dict = strings.string2buf(opt.dictionary); dict = strings.string2buf(opt.dictionary);
} else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') { } else if (toString$1.call(opt.dictionary) === '[object ArrayBuffer]') {
dict = new Uint8Array(opt.dictionary); dict = new Uint8Array(opt.dictionary);
} else { } else {
dict = opt.dictionary; dict = opt.dictionary;
...@@ -16016,7 +16029,7 @@ var serviceContext = (function () { ...@@ -16016,7 +16029,7 @@ var serviceContext = (function () {
if (typeof data === 'string') { if (typeof data === 'string') {
// If we need to compress text, change encoding to utf8. // If we need to compress text, change encoding to utf8.
strm.input = strings.string2buf(data); strm.input = strings.string2buf(data);
} else if (toString.call(data) === '[object ArrayBuffer]') { } else if (toString$1.call(data) === '[object ArrayBuffer]') {
strm.input = new Uint8Array(data); strm.input = new Uint8Array(data);
} else { } else {
strm.input = data; strm.input = data;
...@@ -18568,7 +18581,7 @@ var serviceContext = (function () { ...@@ -18568,7 +18581,7 @@ var serviceContext = (function () {
var gzheader = GZheader; var gzheader = GZheader;
var toString$1 = Object.prototype.toString; var toString$2 = Object.prototype.toString;
/** /**
* class Inflate * class Inflate
...@@ -18709,7 +18722,7 @@ var serviceContext = (function () { ...@@ -18709,7 +18722,7 @@ var serviceContext = (function () {
// Convert data if needed // Convert data if needed
if (typeof opt.dictionary === 'string') { if (typeof opt.dictionary === 'string') {
opt.dictionary = strings.string2buf(opt.dictionary); opt.dictionary = strings.string2buf(opt.dictionary);
} else if (toString$1.call(opt.dictionary) === '[object ArrayBuffer]') { } else if (toString$2.call(opt.dictionary) === '[object ArrayBuffer]') {
opt.dictionary = new Uint8Array(opt.dictionary); opt.dictionary = new Uint8Array(opt.dictionary);
} }
if (opt.raw) { //In raw mode we need to set the dictionary early if (opt.raw) { //In raw mode we need to set the dictionary early
...@@ -18767,7 +18780,7 @@ var serviceContext = (function () { ...@@ -18767,7 +18780,7 @@ var serviceContext = (function () {
if (typeof data === 'string') { if (typeof data === 'string') {
// Only binary strings can be decompressed on practice // Only binary strings can be decompressed on practice
strm.input = strings.binstring2buf(data); strm.input = strings.binstring2buf(data);
} else if (toString$1.call(data) === '[object ArrayBuffer]') { } else if (toString$2.call(data) === '[object ArrayBuffer]') {
strm.input = new Uint8Array(data); strm.input = new Uint8Array(data);
} else { } else {
strm.input = data; strm.input = data;
......
...@@ -5,7 +5,8 @@ import { ...@@ -5,7 +5,8 @@ import {
import { import {
publish, publish,
requireNativePlugin, requireNativePlugin,
base64ToArrayBuffer base64ToArrayBuffer,
arrayBufferToBase64
} from '../../bridge' } from '../../bridge'
import { import {
...@@ -107,11 +108,15 @@ export function createRequestTaskById (requestTaskId, { ...@@ -107,11 +108,15 @@ export function createRequestTaskById (requestTaskId, {
firstIpv4: firstIpv4, firstIpv4: firstIpv4,
tls tls
} }
let withArrayBuffer
if (method !== 'GET') { if (method !== 'GET') {
if (toString.call(data) === '[object ArrayBuffer]') {
withArrayBuffer = true
} else {
options.body = typeof data === 'string' ? data : JSON.stringify(data) options.body = typeof data === 'string' ? data : JSON.stringify(data)
} }
try { }
stream.fetch(options, ({ const callback = ({
ok, ok,
status, status,
data, data,
...@@ -146,7 +151,16 @@ export function createRequestTaskById (requestTaskId, { ...@@ -146,7 +151,16 @@ export function createRequestTaskById (requestTaskId, {
errMsg errMsg
}) })
} }
}) }
try {
if (withArrayBuffer) {
stream.fetchWithArrayBuffer({
'@type': 'binary',
base64: arrayBufferToBase64(data)
}, options, callback)
} else {
stream.fetch(options, callback)
}
requestTasks[requestTaskId] = { requestTasks[requestTaskId] = {
abort () { abort () {
aborted = true aborted = true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册