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

WebResourceResponse not support inputstream #2358

Open
1 of 2 tasks
kutear opened this issue Oct 18, 2024 · 0 comments
Open
1 of 2 tasks

WebResourceResponse not support inputstream #2358

kutear opened this issue Oct 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@kutear
Copy link

kutear commented Oct 18, 2024

Is there an existing feature request for this?

  • I have searched the existing feature request

Operating System

all

Pain

in android, if we want override shouldInterceptRequest,we need use mulit-thread,then return a InputStream to WebResourceResponse. just like this code.

@Override
public WebResourceResponse shouldInterceptRequest(WebView view, final String url) {
    Log.i(TAG, String.format("shouldInterceptRequest in thread: %s[%s]  url: %s", Thread.currentThread().getName(), Thread.currentThread().getId() + "", url));
    return new WebResourceResponse("", "utf-8", new InputStream() {
        private InputStream inputStream = null;
        @Override
        public int read() throws IOException {
            Log.i(TAG, String.format("Reading data in thread %s[%s] url  %s ", Thread.currentThread().getName(), Thread.currentThread().getId(), url));
            if (inputStream == null) {
                try {
                    Request request = new Request.Builder()
                            .url(url)
                            .build();
                    Response response = okHttpClient.newCall(request).execute();
                    inputStream = response.body().byteStream();
                } catch (Exception e) {
                    Log.e(TAG, "Fail Reading WebResourceResponse  url: " + url);
                }
            }
            if (inputStream == null) {
                return -1;
            } else {
                return inputStream.read();
            }
        }
        @Override
        public void close() throws IOException {
            super.close();
            if (inputStream != null) {
                inputStream.close();
            }
        }
    });
}

// 作者:QuinnChen
// 链接:https://juejin.cn/post/6844903497494691848
// 来源:稀土掘金
// 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

but in this library,i can't return a stream, only support Uint8List,it'e mean i can't handle request with mulit-thread, if a request cost much time, all request will pending.

Suggested solution

To support stream for WebResourceResponse

Useful resources

No response

Additional information

No response

Self grab

  • I'm ready to work on this issue!
@kutear kutear added the enhancement New feature or request label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant