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

web-sys: Unable to add body to a Request #817

Closed
Bobo1239 opened this issue Sep 12, 2018 · 6 comments
Closed

web-sys: Unable to add body to a Request #817

Bobo1239 opened this issue Sep 12, 2018 · 6 comments
Labels
bug web-sys Issues related to the `web-sys` crate

Comments

@Bobo1239
Copy link

I'm trying to create a Request with a body but I can't figure out how (or it isn't possible yet). Neither Request nor RequestInit offer a way to add a body. Ultimately I'd like to do something like this.

@fitzgen
Copy link
Member

fitzgen commented Sep 12, 2018

RequestInit has a body member:

dictionary RequestInit {
  // ...
  BodyInit? body;
  // ...
};

and BodyInit is defined as

typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) BodyInit;

I wonder if we support that kind of union yet... time to dig into the logs.

@afdw
Copy link
Contributor

afdw commented Sep 12, 2018

No, it is not yet supported. Only non-nullable unions with only interfaces in them are supported in dictionaries.

@fitzgen
Copy link
Member

fitzgen commented Sep 12, 2018

@afdw can you point me to where we identify and skip these members right now? I think we need better logging

@afdw
Copy link
Contributor

afdw commented Sep 12, 2018

IdlType::Union(idl_types) => {
// Handles union types in all places except operation argument types.
// Currently treats them as object type, if possible.
// TODO: add better support for union types here?
// Approaches for it:
// 1. Use strategy of finding the nearest common subclass (finding the best type
// that is suitable for all values of this union)
// 2. Generate enum with payload in Rust for each union type
if idl_types
.iter()
.all(|idl_type|
match idl_type {
IdlType::Interface(..) => true,
_ => false,
}
) {
IdlType::Object.to_syn_type(pos)
} else {
None
}
},

@fitzgen
Copy link
Member

fitzgen commented Sep 12, 2018

Thanks!

@fitzgen fitzgen added web-sys Issues related to the `web-sys` crate bug Blocking Rust 2018 labels Sep 12, 2018
@fitzgen
Copy link
Member

fitzgen commented Sep 13, 2018

I think it is OK to fall back to JsValue for nullable unions

@fitzgen fitzgen mentioned this issue Sep 13, 2018
19 tasks
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Sep 21, 2018
Bind them all as `JsValue` as that's the "least common ancestor" we can
work with. Fixes up one location in WebIDL where `Option<JsValue>`
arose as we haven't implemented that.

Closes rustwasm#817
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Sep 24, 2018
Bind them all as `JsValue` as that's the "least common ancestor" we can
work with. Fixes up one location in WebIDL where `Option<JsValue>`
arose as we haven't implemented that.

Closes rustwasm#817
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug web-sys Issues related to the `web-sys` crate
Projects
None yet
Development

No branches or pull requests

3 participants