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

gdrive service can't work under wasm target #3810

Closed
Young-Flash opened this issue Dec 23, 2023 · 11 comments · Fixed by #3907
Closed

gdrive service can't work under wasm target #3810

Young-Flash opened this issue Dec 23, 2023 · 11 comments · Fixed by #3907

Comments

@Young-Flash
Copy link
Member

let mut cfg: Gdrive = Gdrive::default();
cfg.access_token("...").root("/tmp");

let op = Operator::new(cfg).unwrap().finish();
op.write(
    "test-gdrive-wasm",
    "Hello, WASM! We are from OpenDAL at rust side!"
        .as_bytes()
        .to_vec(),
)
.await
.unwrap();
let bs = op.read("test-gdrive-wasm").await.unwrap();

I am test gdrive over wasm, when I work with the above code, it failed with

image

but that code works well if I run it in rust side, am I missing something?

originally post at #3808 (comment)

@Zheaoli
Copy link
Member

Zheaoli commented Dec 24, 2023

The root cause is here

When the request happens in the browser, the browser will add a default encoding header accept-encoding: gzip which means that the server needs the compressed data. So It would cause an error. The origin data is 243 long and 188 long after compress

cc @Xuanwo

@Zheaoli
Copy link
Member

Zheaoli commented Dec 24, 2023

image

@Young-Flash
Copy link
Member Author

Young-Flash commented Dec 25, 2023

When the request happens in the browser, the browser will add a default encoding header accept-encoding: gzip which means that the server needs the compressed data. So It would cause an error. The origin data is 243 long and 188 long after compress

nice catch

Is this issue just for gdrive service only? (since it isn't report at s3 example)

@Xuanwo
Copy link
Member

Xuanwo commented Dec 25, 2023

When the request happens in the browser, the browser will add a default encoding header accept-encoding: gzip which means that the server needs the compressed data. So It would cause an error. The origin data is 243 long and 188 long after compress

Nice catch! We did't hit this since we use no_gzip on non-wasm32 target. But reqwest didn't provide this on wasm32 target.

@Xuanwo
Copy link
Member

Xuanwo commented Dec 25, 2023

Hi, @Zheaoli, would you like to try add Accept-Encoding: identity under wasm32?

@Zheaoli
Copy link
Member

Zheaoli commented Dec 25, 2023

Hi, @Zheaoli, would you like to try add Accept-Encoding: identity under wasm32?

Unfortunately, It can't be done in the Brower. The Accept-Encoding field is one of the forbidden header fields in the Brower. Which means that we can not change the field value in the JS or the WASM code

FYI :

  1. https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
  2. https://github.com/chromium/chromium/blob/2898ac290cf80164cee57e7145fe45f858b6ee9f/net/http/http_util.cc#L305-L330

@Zheaoli
Copy link
Member

Zheaoli commented Dec 25, 2023

When the request happens in the browser, the browser will add a default encoding header accept-encoding: gzip which means that the server needs the compressed data. So It would cause an error. The origin data is 243 long and 188 long after compress

nice catch

Is this issue just for gdrive service only? (since it isn't report at s3 example)

It will be reported from S3 user in the future. The S3 can open the gzip setting by manually

@Xuanwo
Copy link
Member

Xuanwo commented Dec 27, 2023

The Accept-Encoding field is one of the forbidden header fields in the Brower.

Would like to provide more details about that? The example in seanmonstar/reqwest#2073 (comment) seems to work fine.

It does not work - -

@Xuanwo
Copy link
Member

Xuanwo commented Dec 30, 2023

A possible way is to implement content-encoding correctly: implement gzip decoding when services return them.

@Zheaoli
Copy link
Member

Zheaoli commented Dec 30, 2023

A possible way is to implement content-encoding correctly: implement gzip decoding when services return them.

The most common algorism used by content encoding

  1. deflate
  2. Brotli
  3. Gzip

Maybe we need to support all three algorithm or raise error when the encoding is not supported yet

@Xuanwo
Copy link
Member

Xuanwo commented Dec 30, 2023

Maybe we need to support all three algorithm or raise error when the encoding is not supported yet

It's better to handle in the http client (a.k.a reqwest). Let's bring the discussion to upstream instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants