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

pass original url with content source data #4818

Merged
merged 1 commit into from
May 4, 2023
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
10 changes: 10 additions & 0 deletions crates/turbopack-dev-server/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ pub struct ContentSourceData {
pub method: Option<String>,
/// The full url (including query string), if requested.
pub url: Option<String>,
/// The full url (including query string) before rewrites where applied, if
/// requested.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to explain why this might be useful to a consumer.

pub original_url: Option<String>,
/// Query string items, if requested.
pub query: Option<Query>,
/// raw query string, if requested. Does not include the `?`.
Expand Down Expand Up @@ -368,6 +371,7 @@ impl ContentSourceDataFilter {
pub struct ContentSourceDataVary {
pub method: bool,
pub url: bool,
pub original_url: bool,
pub query: Option<ContentSourceDataFilter>,
pub raw_query: bool,
pub headers: Option<ContentSourceDataFilter>,
Expand All @@ -387,6 +391,7 @@ impl ContentSourceDataVary {
let ContentSourceDataVary {
method,
url,
original_url,
query,
raw_query,
headers,
Expand All @@ -397,6 +402,7 @@ impl ContentSourceDataVary {
} = self;
*method = *method || other.method;
*url = *url || other.url;
*original_url = *original_url || other.original_url;
*body = *body || other.body;
*cache_buster = *cache_buster || other.cache_buster;
*raw_query = *raw_query || other.raw_query;
Expand All @@ -412,6 +418,7 @@ impl ContentSourceDataVary {
let ContentSourceDataVary {
method,
url,
original_url,
query,
raw_query,
headers,
Expand All @@ -426,6 +433,9 @@ impl ContentSourceDataVary {
if other.url && !url {
return false;
}
if other.original_url && !original_url {
return false;
}
if other.body && !body {
return false;
}
Expand Down
9 changes: 7 additions & 2 deletions crates/turbopack-dev-server/src/source/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ pub async fn resolve_source_request(
ContentSourceResult::NeedData(needed) => {
current_source = needed.source.resolve().await?;
current_asset_path = needed.path.clone();
data = request_to_data(&request_overwrites, &needed.vary).await?;
data = request_to_data(&request_overwrites, &request, &needed.vary).await?;
}
ContentSourceResult::Result { get_content, .. } => {
let content_vary = get_content.vary().await?;
let content_data = request_to_data(&request_overwrites, &content_vary).await?;
let content_data =
request_to_data(&request_overwrites, &request, &content_vary).await?;
let content = get_content.get(Value::new(content_data));
match &*content.await? {
ContentSourceContent::Rewrite(rewrite) => {
Expand Down Expand Up @@ -96,6 +97,7 @@ static CACHE_BUSTER: AtomicU64 = AtomicU64::new(0);

async fn request_to_data(
request: &SourceRequest,
original_request: &SourceRequest,
vary: &ContentSourceDataVary,
) -> Result<ContentSourceData> {
let mut data = ContentSourceData::default();
Expand All @@ -105,6 +107,9 @@ async fn request_to_data(
if vary.url {
data.url = Some(request.uri.to_string());
}
if vary.original_url {
data.original_url = Some(original_request.uri.to_string());
}
if vary.body {
data.body = Some(request.body.clone().into());
}
Expand Down
1 change: 1 addition & 0 deletions crates/turbopack-node/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct RenderData {
params: IndexMap<String, Param>,
method: String,
url: String,
original_url: String,
raw_query: String,
raw_headers: Vec<(String, String)>,
path: String,
Expand Down
3 changes: 3 additions & 0 deletions crates/turbopack-node/src/render/node_api_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl GetContentSourceContent for NodeApiGetContentResult {
ContentSourceDataVary {
method: true,
url: true,
original_url: true,
raw_headers: true,
raw_query: true,
body: true,
Expand All @@ -131,6 +132,7 @@ impl GetContentSourceContent for NodeApiGetContentResult {
let ContentSourceData {
method: Some(method),
url: Some(url),
original_url: Some(original_url),
raw_headers: Some(raw_headers),
raw_query: Some(raw_query),
body: Some(body),
Expand All @@ -153,6 +155,7 @@ impl GetContentSourceContent for NodeApiGetContentResult {
params: params.clone(),
method: method.clone(),
url: url.clone(),
original_url: original_url.clone(),
raw_query: raw_query.clone(),
raw_headers: raw_headers.clone(),
path: format!("/{}", self.path),
Expand Down
3 changes: 3 additions & 0 deletions crates/turbopack-node/src/render/rendered_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl GetContentSourceContent for NodeRenderGetContentResult {
ContentSourceDataVary {
method: true,
url: true,
original_url: true,
raw_headers: true,
raw_query: true,
..Default::default()
Expand All @@ -202,6 +203,7 @@ impl GetContentSourceContent for NodeRenderGetContentResult {
let ContentSourceData {
method: Some(method),
url: Some(url),
original_url: Some(original_url),
raw_headers: Some(raw_headers),
raw_query: Some(raw_query),
..
Expand All @@ -224,6 +226,7 @@ impl GetContentSourceContent for NodeRenderGetContentResult {
params: params.clone(),
method: method.clone(),
url: url.clone(),
original_url: original_url.clone(),
raw_query: raw_query.clone(),
raw_headers: raw_headers.clone(),
path: source.pathname.await?.clone_value(),
Expand Down