Skip to content

Commit 2689764

Browse files
bors[bot]bidoubiwa
andauthored
Merge #330
330: Fix wasm panic when trying to change the user-agent r=bidoubiwa a=bidoubiwa Fixes: #308 User-agent can not be changed in chromium. It is considered a security breach. Probably because of that wasm does not accept it either. Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 261fa52 + 19944fa commit 2689764

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Also, the WASM example compilation should be checked:
5959

6060
```bash
6161
rustup target add wasm32-unknown-unknown
62-
cargo check --example web_app --target wasm32-unknown-unknown --features=sync
62+
cargo check -p web_app --target wasm32-unknown-unknown
6363
```
6464

6565
Each PR should pass the tests to be accepted.

examples/web_app/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Rust source files are compiled into WebAssembly and so can be readable by th
1111
If you only want to check if this example compiles, you can run:
1212

1313
```console
14-
cargo build --example web_app
14+
cargo build
1515
```
1616

1717
## Building
@@ -23,7 +23,7 @@ curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
2323
```
2424

2525
```console
26-
wasm-pack build examples/web_app/ --target=web --no-typescript
26+
wasm-pack build . --target=web --no-typescript
2727
```
2828

2929
The compiled files will be stored in the `examples/web_app/pkg` folder.

examples/web_app/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ mod document;
1515
use crate::document::{display, Crate};
1616

1717
lazy_static! {
18-
static ref CLIENT: Client = Client::new(
19-
"https://finding-demos.meilisearch.com",
20-
"2b902cce4f868214987a9f3c7af51a69fa660d74a785bed258178b96e3480bb3",
21-
);
18+
static ref CLIENT: Client = Client::new("http://localhost:7700", "masterKey",);
2219
}
2320

2421
struct Model {

src/request.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ pub(crate) async fn request<Input: Serialize, Output: DeserializeOwned + 'static
109109

110110
const CONTENT_TYPE: &str = "Content-Type";
111111
const JSON: &str = "application/json";
112-
let user_agent = qualified_version();
113112

114113
// The 2 following unwraps should not be able to fail
115114
let mut mut_url = url.clone().to_string();
116115
let headers = Headers::new().unwrap();
117-
headers.append("Authorization: Bearer", apikey).unwrap();
118-
headers.append("User-Agent", &user_agent).unwrap();
116+
headers
117+
.append("Authorization", format!("Bearer {}", apikey).as_str())
118+
.unwrap();
119+
headers
120+
.append("X-Meilisearch-Client", qualified_version().as_str())
121+
.unwrap();
119122

120123
let mut request: RequestInit = RequestInit::new();
121124
request.headers(&headers);
@@ -124,10 +127,8 @@ pub(crate) async fn request<Input: Serialize, Output: DeserializeOwned + 'static
124127
Method::Get(query) => {
125128
let query = yaup::to_string(query)?;
126129

127-
mut_url = if query.is_empty() {
128-
mut_url.to_string()
129-
} else {
130-
format!("{}?{}", mut_url, query)
130+
if !query.is_empty() {
131+
mut_url = format!("{}?{}", mut_url, query);
131132
};
132133

133134
request.method("GET");

0 commit comments

Comments
 (0)