Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/http-allow-skip-origin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"http": "patch"
"http-js": "patch"
---

Allow skipping sending `Origin` header in HTTP requests by setting `Origin` header to an empty string when calling `fetch`.
8 changes: 8 additions & 0 deletions plugins/http/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ pub async fn fetch<R: Runtime>(
}
}

// In case empty origin is passed, remove it. Some services do not like Origin header
// so this way we can remove it in explicit way. The default behaviour is still to set it
if cfg!(feature = "unsafe-headers")
&& headers.get(header::ORIGIN) == Some(&HeaderValue::from_static(""))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should match on an empty string, because there might be some users who want to send empty string for Origin. I'd rather add a new option when making the request, for example:

fetch(url, {
  sendOriginHeader: false
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I was thinking a lot. Like I'd like to avoid adding extra parameters to the fetch and try to keep the fetch as close to global fetch. And in case of patching global fetch with tauri-http (example to get control what fetches actually can be made) the consumers assume standard fetch. Different libraries support some pre/post hooks for different operations that allow example inject headers and such like for custom auth and they operate with the RequestInit object.

And the syntax of Origin header is:

Origin: null
Origin: <scheme>://<hostname>
Origin: <scheme>://<hostname>:<port>

MDN origin header
RFC 6454

Sending an empty string is invalid format. In case user wants to hide the origin for example privacy reasons they should set it to null string literal.

For these reasons I ended up with sending empty string in the origin header as the mechanism.

I hope my reasoning makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was comparing with how node and deno runtimes behave and both allow setting Origin to an empty string. However your reasoning is quite valid and I think we should go with your approach until someone else asks for this specific behavior.

{
headers.remove(header::ORIGIN);
};

if let Some(data) = data {
request = request.body(data);
}
Expand Down
Loading