Skip to content

Commit b7a2345

Browse files
authored
feat(core): add raw headers to HTTP API, closes #2695 (#3053)
1 parent 0a857f8 commit b7a2345

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

.changes/api-raw-headers.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Added `rawHeaders` to `http > Response`.

.changes/raw-headers.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Add `raw_headers` to `tauri::api::http::ResponseData`.

core/tauri/scripts/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/src/api/http.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,22 @@ impl Response {
351351
let url = self.2;
352352

353353
let mut headers = HashMap::new();
354+
let mut raw_headers = HashMap::new();
354355
for (name, value) in self.1.headers() {
355356
headers.insert(
356357
name.as_str().to_string(),
357358
String::from_utf8(value.as_bytes().to_vec())?,
358359
);
360+
raw_headers.insert(
361+
name.as_str().to_string(),
362+
self
363+
.1
364+
.headers()
365+
.get_all(name)
366+
.into_iter()
367+
.map(|v| String::from_utf8(v.as_bytes().to_vec()).map_err(Into::into))
368+
.collect::<crate::api::Result<Vec<String>>>()?,
369+
);
359370
}
360371
let status = self.1.status().as_u16();
361372

@@ -377,6 +388,7 @@ impl Response {
377388
url,
378389
status,
379390
headers,
391+
raw_headers,
380392
data,
381393
})
382394
}
@@ -403,6 +415,8 @@ pub struct ResponseData {
403415
pub status: u16,
404416
/// Response headers.
405417
pub headers: HashMap<String, String>,
418+
/// Response raw headers.
419+
pub raw_headers: HashMap<String, Vec<String>>,
406420
/// Response data.
407421
pub data: Value,
408422
}

tooling/api/src/http.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ interface IResponse<T> {
128128
url: string
129129
status: number
130130
headers: Record<string, string>
131+
rawHeaders: Record<string, string[]>
131132
data: T
132133
}
133134

@@ -141,6 +142,8 @@ class Response<T> {
141142
ok: boolean
142143
/** The response headers. */
143144
headers: Record<string, string>
145+
/** The response raw headers. */
146+
rawHeaders: Record<string, string[]>
144147
/** The response data. */
145148
data: T
146149

@@ -150,6 +153,7 @@ class Response<T> {
150153
this.status = response.status
151154
this.ok = this.status >= 200 && this.status < 300
152155
this.headers = response.headers
156+
this.rawHeaders = response.rawHeaders
153157
this.data = response.data
154158
}
155159
}

0 commit comments

Comments
 (0)