mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(ext/http): preserve authority and scheme from absolute URLs (#4)
This commit is contained in:
parent
2f179e4dfd
commit
f14ae37686
3 changed files with 39 additions and 35 deletions
|
@ -264,32 +264,19 @@ class InnerRequest {
|
||||||
this.#methodAndUri = op_http_get_request_method_and_url(this.#external);
|
this.#methodAndUri = op_http_get_request_method_and_url(this.#external);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const method = this.#methodAndUri[0];
|
||||||
|
const scheme = this.#methodAndUri[5] !== undefined
|
||||||
|
? `${this.#methodAndUri[5]}://`
|
||||||
|
: this.#context.scheme;
|
||||||
|
const authority = this.#methodAndUri[1] ?? this.#context.fallbackHost;
|
||||||
const path = this.#methodAndUri[2];
|
const path = this.#methodAndUri[2];
|
||||||
|
|
||||||
// * is valid for OPTIONS
|
|
||||||
if (path === "*") {
|
|
||||||
return this.#urlValue = "*";
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the path is empty, return the authority (valid for CONNECT)
|
// If the path is empty, return the authority (valid for CONNECT)
|
||||||
if (path == "") {
|
if (method == "CONNECT") {
|
||||||
return this.#urlValue = this.#methodAndUri[1];
|
return this.#urlValue = this.#methodAndUri[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// CONNECT requires an authority
|
return this.#urlValue = scheme + authority + path;
|
||||||
if (this.#methodAndUri[0] == "CONNECT") {
|
|
||||||
return this.#urlValue = this.#methodAndUri[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
const hostname = this.#methodAndUri[1];
|
|
||||||
if (hostname) {
|
|
||||||
// Construct a URL from the scheme, the hostname, and the path
|
|
||||||
return this.#urlValue = this.#context.scheme + hostname + path;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct a URL from the scheme, the fallback hostname, and the path
|
|
||||||
return this.#urlValue = this.#context.scheme + this.#context.fallbackHost +
|
|
||||||
path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get completed() {
|
get completed() {
|
||||||
|
@ -595,11 +582,13 @@ function serve(arg1, arg2) {
|
||||||
options = { __proto__: null };
|
options = { __proto__: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
const canOverrideOptions = !ObjectHasOwn(options, "path")
|
const canOverrideOptions = !ObjectHasOwn(options, "path") &&
|
||||||
&& !ObjectHasOwn(options, "hostname")
|
!ObjectHasOwn(options, "hostname") &&
|
||||||
&& !ObjectHasOwn(options, "port");
|
!ObjectHasOwn(options, "port");
|
||||||
const env = Deno.permissions.querySync({ name: "env", variable: "DENO_SERVE_ADDRESS" }).state === "granted"
|
const env =
|
||||||
&& Deno.env.get("DENO_SERVE_ADDRESS");
|
Deno.permissions.querySync({ name: "env", variable: "DENO_SERVE_ADDRESS" })
|
||||||
|
.state === "granted" &&
|
||||||
|
Deno.env.get("DENO_SERVE_ADDRESS");
|
||||||
|
|
||||||
if (canOverrideOptions && env) {
|
if (canOverrideOptions && env) {
|
||||||
const delim = env.indexOf("/");
|
const delim = env.indexOf("/");
|
||||||
|
|
|
@ -300,10 +300,10 @@ where
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
let authority: v8::Local<v8::Value> = match request_properties.authority {
|
let scheme: v8::Local<v8::Value> = match request_parts.uri.scheme_str() {
|
||||||
Some(authority) => v8::String::new_from_utf8(
|
Some(scheme) => v8::String::new_from_utf8(
|
||||||
scope,
|
scope,
|
||||||
authority.as_ref(),
|
scheme.as_bytes(),
|
||||||
v8::NewStringType::Normal,
|
v8::NewStringType::Normal,
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -311,6 +311,27 @@ where
|
||||||
None => v8::undefined(scope).into(),
|
None => v8::undefined(scope).into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let authority: v8::Local<v8::Value> =
|
||||||
|
if let Some(authority) = request_parts.uri.authority() {
|
||||||
|
v8::String::new_from_utf8(
|
||||||
|
scope,
|
||||||
|
authority.as_str().as_ref(),
|
||||||
|
v8::NewStringType::Normal,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.into()
|
||||||
|
} else if let Some(authority) = request_properties.authority {
|
||||||
|
v8::String::new_from_utf8(
|
||||||
|
scope,
|
||||||
|
authority.as_ref(),
|
||||||
|
v8::NewStringType::Normal,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
v8::undefined(scope).into()
|
||||||
|
};
|
||||||
|
|
||||||
// Only extract the path part - we handle authority elsewhere
|
// Only extract the path part - we handle authority elsewhere
|
||||||
let path = match &request_parts.uri.path_and_query() {
|
let path = match &request_parts.uri.path_and_query() {
|
||||||
Some(path_and_query) => path_and_query.to_string(),
|
Some(path_and_query) => path_and_query.to_string(),
|
||||||
|
@ -335,7 +356,7 @@ where
|
||||||
None => v8::undefined(scope).into(),
|
None => v8::undefined(scope).into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let vec = [method, authority, path, peer_address, port];
|
let vec = [method, authority, path, peer_address, port, scheme];
|
||||||
v8::Array::new_with_elements(scope, vec.as_slice())
|
v8::Array::new_with_elements(scope, vec.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -269,12 +269,6 @@ fn req_host<'a>(
|
||||||
addr_type: NetworkStreamType,
|
addr_type: NetworkStreamType,
|
||||||
port: u16,
|
port: u16,
|
||||||
) -> Option<Cow<'a, str>> {
|
) -> Option<Cow<'a, str>> {
|
||||||
// Unix sockets always use the socket address
|
|
||||||
#[cfg(unix)]
|
|
||||||
if addr_type == NetworkStreamType::Unix {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
// It is rare that an authority will be passed, but if it does, it takes priority
|
// It is rare that an authority will be passed, but if it does, it takes priority
|
||||||
if let Some(auth) = uri.authority() {
|
if let Some(auth) = uri.authority() {
|
||||||
match addr_type {
|
match addr_type {
|
||||||
|
|
Loading…
Reference in a new issue