Skip to content

Commit

Permalink
feat: send better Accept header (#42)
Browse files Browse the repository at this point in the history
Fixes #41.
  • Loading branch information
bnoordhuis committed Jan 7, 2022
1 parent 61e09f0 commit 2df5a64
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/reqwest_loader.rs
Expand Up @@ -5,6 +5,7 @@ use crate::loader::ModuleLoadFuture;
use crate::loader::ModuleLoader;
use crate::loader::ModuleStream;
use crate::resolve_import::resolve_import;
use reqwest::header::ACCEPT;
use reqwest::header::CONTENT_TYPE;
use reqwest::header::LOCATION;
use reqwest::RequestBuilder;
Expand All @@ -25,8 +26,14 @@ impl<T: Fn(&Url, RequestBuilder) -> RequestBuilder + Send + Sync + Unpin>
ReqwestLoader<T>
{
pub fn new(client_builder: reqwest::ClientBuilder, middleware: T) -> Self {
// reqwest::ClientBuilder adds "Accept: */*" as its sole default header
// but we override that here to encourage content negotiation.
let accept_header = reqwest::header::HeaderValue::from_static("application/javascript, application/typescript, text/javascript, text/typescript, text/jsx, text/tsx, application/json;q=0.9, text/plain;q=0.8, application/octet-stream;q=0.8, */*;q=0.7");
let mut default_headers = reqwest::header::HeaderMap::new();
default_headers.insert(ACCEPT, accept_header);
let client = client_builder
.redirect(reqwest::redirect::Policy::none())
.default_headers(default_headers)
.build()
.unwrap();
Self { client, middleware }
Expand Down

0 comments on commit 2df5a64

Please sign in to comment.