Progress, publish and close an HTTP session
ASPL 0.7.0 · Current release
Native only. Progress, publish and close an HTTP session, with exact supplied sources, requirements, commands and outcomes.
On this page
Prepare the native host
Reserve 127.0.0.1:8081. No external requests, source modules or TLS assets are needed. The program copies state, publishes 11 conditionally, refuses stale publication with successful false, drains and closes shared aliases.
Follow the deployment guide for certificates, CA selection, working directories and the complete upstream workflow.
Follow the HTTP guide and API reference. Keep the original filenames and the modules of the selected source variant. Save Arabic and English variants in separate directories. TLS inputs are supplied by the reader, with no bundled certificates or keys. No other data assets are required.
Arabic source
Execution: Native only · ASPL 0.7.0
- Native only. Published ASPL 0.7.0 on x86-64 Linux with glibc 2.34 or later. No input lines. Reserve 127.0.0.1:8081. No external requests, source modules or TLS assets are needed. The program copies state, publishes 11 conditionally, refuses stale publication with successful false, drains and closes shared aliases.
Input: No input lines are required.
استورد أساسي::ويب.
سجل حالة { عدد: ص64 }
دالة عالج(الطلب: ويب::طلب_وارد, سياق: ويب::سياق<منطقي,حالة>) -> ويب::استجابة_خادم {
دع محفوظ = ويب::التقط_الحالة(سياق).
دع منشور = ويب::استبدل_الحالة_إن_كانت_حالية(سياق, محفوظ, حالة { عدد: محفوظ::قيمة::عدد + 1 }).
إذا ليس منشور::نجاح أو ليس منشور::قيمة { أرجع ويب::أنشئ_استجابة(409, [])::قيمة. }
أرجع ويب::أنشئ_استجابة(200, [])::قيمة.
}
دالة ابدأ_الرئيسية() -> ص64 {
دع وجهات = ويب::أنشئ_موجه([ويب::أنشئ_وجهة("GET", "/", عالج)::قيمة])::قيمة.
متغير خادم = ويب::إعدادات_خدمة().
خادم::مستمعون = [ويب::أنشئ_مستمع("127.0.0.1", 8081)::قيمة].
دع مبدوء = ويب::ابدأ(خادم, وجهات, خطأ, حالة { عدد: 10 }).
إذا ليس مبدوء::نجاح { اطبع(مبدوء::الخطأ::الرمز). أرجع 1. }
دع مالك = مبدوء::قيمة.
دع مرادف = مالك.
دع محفوظ = ويب::التقط_حالة_الجلسة(مالك)::قيمة.
متغير منسوخ = ويب::حالة_الجلسة(مالك)::قيمة.
منسوخ::عدد = 99.
إذا ويب::حالة_الجلسة(مالك)::قيمة::عدد لا يطابق 10 { أرجع 2. }
دع منشور = ويب::استبدل_حالة_الجلسة_إن_كانت_حالية(مالك, محفوظ, حالة { عدد: 11 }).
إذا ليس منشور::نجاح أو ليس منشور::قيمة { أرجع 3. }
دع متقادم = ويب::استبدل_حالة_الجلسة_إن_كانت_حالية(مرادف, محفوظ, حالة { عدد: 12 }).
إذا ليس متقادم::نجاح أو متقادم::قيمة { أرجع 4. }
إذا ويب::حالة_الجلسة(مالك)::قيمة::عدد لا يطابق 11 { أرجع 5. }
إذا ليس ويب::أوقف_الجلسة(مالك)::نجاح { أرجع 6. }
متغير ميزانية = ويب::ميزانية_التقدم().
ميزانية::زمن_الانتظار_مللي = 1.
متغير مغلق = خطأ.
طالما ليس مغلق {
دع متقدم = ويب::تقدم(مالك, ميزانية).
إذا ليس متقدم::نجاح { اطبع(متقدم::الخطأ::الرمز). أرجع 7. }
مغلق = متقدم::قيمة يطابق ويب::جلسة_مغلقة.
}
إذا ليس ويب::أغلق_الجلسة(مرادف)::نجاح أو ليس ويب::أغلق_الجلسة(مالك)::نجاح { أرجع 8. }
إذا ويب::حالة_الجلسة(مرادف)::الخطأ::الرمز لا يطابق "http.closed_session" { أرجع 9. }
إذا محفوظ::قيمة::عدد لا يطابق 10 { أرجع 10. }
أرجع 0.
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download جلسة.لباتExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"output": ""
}
}English source
Execution: Native only · ASPL 0.7.0
- Native only. Published ASPL 0.7.0 on x86-64 Linux with glibc 2.34 or later. No input lines. Reserve 127.0.0.1:8081. No external requests, source modules or TLS assets are needed. The program copies state, publishes 11 conditionally, refuses stale publication with successful false, drains and closes shared aliases.
Input: No input lines are required.
import core::http;
record State { count: i64 }
fn handle(req: http::IncomingRequest, ctx: http::Context<bool,State>) -> http::ServerResponse {
let saved = http::snapshot_state(ctx);
let published = http::replace_state_if_current(ctx, saved, State { count: saved::value::count + 1 });
if not published::ok or not published::value { return http::response(409, [])::value; }
return http::response(200, [])::value;
}
fn start_main() -> i64 {
let routes = http::router([http::route("GET", "/", handle)::value])::value;
var server = http::server_config();
server::listeners = [http::listener("127.0.0.1", 8081)::value];
let started = http::start(server, routes, false, State { count: 10 });
if not started::ok { print(started::error::code); return 1; }
let owner = started::value;
let alias = owner;
let saved = http::snapshot_session_state(owner)::value;
var copied = http::session_state(owner)::value;
copied::count = 99;
if http::session_state(owner)::value::count not matches 10 { return 2; }
let published = http::replace_session_state_if_current(owner, saved, State { count: 11 });
if not published::ok or not published::value { return 3; }
let stale = http::replace_session_state_if_current(alias, saved, State { count: 12 });
if not stale::ok or stale::value { return 4; }
if http::session_state(owner)::value::count not matches 11 { return 5; }
if not http::stop_session(owner)::ok { return 6; }
var budget = http::progress_budget();
budget::wait_ms = 1;
var closed = false;
while not closed {
let advanced = http::progress(owner, budget);
if not advanced::ok { print(advanced::error::code); return 7; }
closed = advanced::value matches http::SESSION_CLOSED;
}
if not http::close_session(alias)::ok or not http::close_session(owner)::ok { return 8; }
if http::session_state(alias)::error::code not matches "http.closed_session" { return 9; }
if saved::value::count not matches 10 { return 10; }
return 0;
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download session.asplExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"output": ""
}
}Commands and outcomes
ar:
aspl check ar/session.aspl
aspl run ar/session.aspl
aspl build -o http-session-ar-program ar/session.aspl
./http-session-ar-programen:
aspl check en/session.aspl
aspl run en/session.aspl
aspl build -o http-session-en-program en/session.aspl
./http-session-en-programRun these commands from the parent of the separate ar/en source directories. The program opens its listener, checks copied/current/stale state, drains through progress and closes automatically. No external request or POST /stop is needed. Success has no output and status 0. Expected outcome details above come from the catalog. See the HTTP collection.