summaryrefslogtreecommitdiff
path: root/ext/flash
diff options
context:
space:
mode:
Diffstat (limited to 'ext/flash')
-rw-r--r--ext/flash/01_http.js11
-rw-r--r--ext/flash/lib.rs24
-rw-r--r--ext/flash/socket.rs1
3 files changed, 34 insertions, 2 deletions
diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js
index 5152fd9e5..ff2eab63c 100644
--- a/ext/flash/01_http.js
+++ b/ext/flash/01_http.js
@@ -570,7 +570,16 @@ function createServe(opFn) {
let resp;
try {
- resp = handler(req);
+ resp = handler(req, () => {
+ const { 0: hostname, 1: port } = core.ops.op_flash_addr(
+ serverId,
+ i,
+ );
+ return {
+ hostname,
+ port,
+ };
+ });
if (ObjectPrototypeIsPrototypeOf(PromisePrototype, resp)) {
PromisePrototypeCatch(
PromisePrototypeThen(
diff --git a/ext/flash/lib.rs b/ext/flash/lib.rs
index f92aa3ea3..4ae064173 100644
--- a/ext/flash/lib.rs
+++ b/ext/flash/lib.rs
@@ -665,6 +665,26 @@ fn op_flash_headers(
)
}
+#[op]
+fn op_flash_addr(
+ state: Rc<RefCell<OpState>>,
+ server_id: u32,
+ token: u32,
+) -> Result<(String, u16), AnyError> {
+ let mut op_state = state.borrow_mut();
+ let flash_ctx = op_state.borrow_mut::<FlashContext>();
+ let ctx = flash_ctx
+ .servers
+ .get_mut(&server_id)
+ .ok_or_else(|| type_error("server closed"))?;
+ let req = &ctx
+ .requests
+ .get(&token)
+ .ok_or_else(|| type_error("request closed"))?;
+ let socket = req.socket();
+ Ok((socket.addr.ip().to_string(), socket.addr.port()))
+}
+
// Remember the first packet we read? It probably also has some body data. This op quickly copies it into
// a buffer and sets up channels for streaming the rest.
#[op]
@@ -934,7 +954,7 @@ fn run_server(
match token {
Token(0) => loop {
match listener.accept() {
- Ok((mut socket, _)) => {
+ Ok((mut socket, addr)) => {
counter += 1;
let token = Token(counter);
poll
@@ -960,6 +980,7 @@ fn run_server(
read_lock: Arc::new(Mutex::new(())),
parse_done: ParseStatus::None,
buffer: UnsafeCell::new(vec![0_u8; 1024]),
+ addr,
});
trace!("New connection: {}", token.0);
@@ -1524,6 +1545,7 @@ pub fn init<P: FlashPermissions + 'static>(unstable: bool) -> Extension {
op_flash_method::decl(),
op_flash_path::decl(),
op_flash_headers::decl(),
+ op_flash_addr::decl(),
op_flash_next::decl(),
op_flash_next_server::decl(),
op_flash_next_async::decl(),
diff --git a/ext/flash/socket.rs b/ext/flash/socket.rs
index 27906e74e..cf9501634 100644
--- a/ext/flash/socket.rs
+++ b/ext/flash/socket.rs
@@ -29,6 +29,7 @@ pub struct Stream {
pub parse_done: ParseStatus,
pub buffer: UnsafeCell<Vec<u8>>,
pub read_lock: Arc<Mutex<()>>,
+ pub addr: std::net::SocketAddr,
}
impl Stream {