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
2 changes: 2 additions & 0 deletions crates/perry-api-manifest/src/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5344,6 +5344,8 @@ pub static API_MANIFEST: &[ApiEntry] = &[
method("http", "__get_method", true, Some("IncomingMessage")),
method("http", "__get_url", true, Some("IncomingMessage")),
method("http", "__get_httpVersion", true, Some("IncomingMessage")),
method("http", "__get_httpVersionMajor", true, Some("IncomingMessage")),
method("http", "__get_httpVersionMinor", true, Some("IncomingMessage")),
method("http", "__get_complete", true, Some("IncomingMessage")),
method("http", "__get_aborted", true, Some("IncomingMessage")),
method("http", "__get_destroyed", true, Some("IncomingMessage")),
Expand Down
3 changes: 3 additions & 0 deletions crates/perry-codegen/src/ext_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ const FFI_REGISTRY: &[(&str, OwnerKind)] = &[
("js_http_client_request_abort", OwnerKind::WellKnown("http")),
("js_http_client_request_destroy", OwnerKind::WellKnown("http")),
("js_http_client_request_noop_undefined", OwnerKind::WellKnown("http")),
("js_http_client_request_flush_headers", OwnerKind::WellKnown("http")),
("js_http_client_request_method", OwnerKind::WellKnown("http")),
("js_http_client_request_protocol", OwnerKind::WellKnown("http")),
("js_http_client_request_host", OwnerKind::WellKnown("http")),
Expand Down Expand Up @@ -294,6 +295,8 @@ const FFI_REGISTRY: &[(&str, OwnerKind)] = &[
("js_node_http_im_method", OwnerKind::WellKnown("http")),
("js_node_http_im_url", OwnerKind::WellKnown("http")),
("js_node_http_im_http_version", OwnerKind::WellKnown("http")),
("js_node_http_im_http_version_major", OwnerKind::WellKnown("http")),
("js_node_http_im_http_version_minor", OwnerKind::WellKnown("http")),
("js_node_http_im_complete", OwnerKind::WellKnown("http")),
("js_node_http_im_aborted", OwnerKind::WellKnown("http")),
("js_node_http_im_destroyed", OwnerKind::WellKnown("http")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub(super) const HTTP_CLIENT_ROWS: &[NativeModSig] = &[
),
cr(
"flushHeaders",
"js_http_client_request_noop_undefined",
"js_http_client_request_flush_headers",
&[NA_F64, NA_F64],
NR_F64,
),
Expand Down
18 changes: 18 additions & 0 deletions crates/perry-codegen/src/lower_call/native_table/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,24 @@ pub(super) const HTTP_SERVER_ROWS: &[NativeModSig] = &[
args: &[],
ret: NR_STR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_httpVersionMajor",
class_filter: Some("IncomingMessage"),
runtime: "js_node_http_im_http_version_major",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_httpVersionMinor",
class_filter: Some("IncomingMessage"),
runtime: "js_node_http_im_http_version_minor",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
Expand Down
9 changes: 9 additions & 0 deletions crates/perry-codegen/src/runtime_decls/stdlib_ffi_part2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ pub(crate) fn declare_stdlib_ffi_part2(module: &mut LlModule) {
module.declare_function("js_node_http_server_unref", I64, &[I64]);
module.declare_function("js_node_https_server_ref", I64, &[I64]);
module.declare_function("js_node_https_server_unref", I64, &[I64]);
// Streaming-bodies PR — client flushHeaders early dispatch + numeric
// httpVersion halves.
module.declare_function(
"js_http_client_request_flush_headers",
DOUBLE,
&[I64, DOUBLE, DOUBLE],
);
module.declare_function("js_node_http_im_http_version_major", DOUBLE, &[I64]);
module.declare_function("js_node_http_im_http_version_minor", DOUBLE, &[I64]);
}
8 changes: 8 additions & 0 deletions crates/perry-ext-http-server/src/handle_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,12 @@ pub unsafe extern "C" fn js_ext_http_incoming_message_dispatch_method(
"httpVersion" | "__get_httpVersion" => {
string_ptr_value(js_node_http_im_http_version(handle))
}
"httpVersionMajor" | "__get_httpVersionMajor" => {
crate::request::incoming_http_version_part(handle, false)
}
"httpVersionMinor" | "__get_httpVersionMinor" => {
crate::request::incoming_http_version_part(handle, true)
}
"__get_complete" => bool_value(js_node_http_im_complete(handle) != 0),
"__get_aborted" => bool_value(js_node_http_im_aborted(handle) != 0),
"__get_destroyed" => bool_value(js_node_http_im_destroyed(handle) != 0),
Expand Down Expand Up @@ -850,6 +856,8 @@ pub unsafe extern "C" fn js_ext_http_incoming_message_dispatch_property(
"method" => string_ptr_value(js_node_http_im_method(handle)),
"url" => string_ptr_value(js_node_http_im_url(handle)),
"httpVersion" => string_ptr_value(js_node_http_im_http_version(handle)),
"httpVersionMajor" => crate::request::incoming_http_version_part(handle, false),
"httpVersionMinor" => crate::request::incoming_http_version_part(handle, true),
"headers" => json_string_value(js_node_http_im_headers_json(handle)),
"rawHeaders" => json_string_value(js_node_http_im_raw_headers_json(handle)),
"headersDistinct" => json_string_value(js_node_http_im_headers_distinct_json(handle)),
Expand Down
4 changes: 2 additions & 2 deletions crates/perry-ext-http-server/src/http2_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ fn synthesize_default_h2_stream_response(stream_handle: i64) {
status_message: None,
headers,
trailers: Vec::new(),
body: Vec::new(),
body: crate::response::ShapeBody::Full(Vec::new()),
};
if let Some(tx) = stream.response_tx.take() {
let _ = tx.send(shape);
Expand Down Expand Up @@ -1987,7 +1987,7 @@ fn end_server_h2_stream(handle: i64, body: Vec<u8>) {
status_message: None,
headers,
trailers: Vec::new(),
body,
body: crate::response::ShapeBody::Full(body),
};
if let Some(tx) = stream.response_tx.take() {
let _ = tx.send(shape);
Expand Down
34 changes: 34 additions & 0 deletions crates/perry-ext-http-server/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,40 @@ pub extern "C" fn js_node_http_im_http_version(handle: i64) -> *mut StringHeader
alloc_string(&s).as_raw()
}

/// `req.httpVersionMajor` — numeric major half of `httpVersion`.
#[no_mangle]
pub extern "C" fn js_node_http_im_http_version_major(handle: i64) -> f64 {
incoming_http_version_part(handle, false)
}

/// `req.httpVersionMinor` — numeric minor half of `httpVersion`.
#[no_mangle]
pub extern "C" fn js_node_http_im_http_version_minor(handle: i64) -> f64 {
incoming_http_version_part(handle, true)
}

/// `req.httpVersionMajor` / `req.httpVersionMinor` — numeric halves of
/// `httpVersion` ("1.0" → 1 / 0).
pub(crate) fn incoming_http_version_part(handle: i64, minor: bool) -> f64 {
let version = get_handle::<IncomingMessage>(handle)
.map(|im| im.http_version.clone())
.unwrap_or_else(|| "1.1".to_string());
let mut parts = version.split('.');
let major = parts
.next()
.and_then(|p| p.parse::<f64>().ok())
.unwrap_or(1.0);
let minor_v = parts
.next()
.and_then(|p| p.parse::<f64>().ok())
.unwrap_or(1.0);
if minor {
minor_v
} else {
major
}
}

/// `req.headers` — JSON-stringify the lowercase-keyed header map.
/// Returned as a NaN-boxed STRING — TS-side parses with `JSON.parse`
/// at the binding wrapper. (Returning a runtime ObjectHeader directly
Expand Down
Loading