redirect_follow.sg is the T14 sprint — following an HTTP redirect chain (301→302→200) with a 5-hop guard. Each hop builds a synthetic HTTP response in resp_buf @0x440000, parses the status code and Location header via byte scan, and updates the current URL in scratch. Final status, hop count, and resolved URL stored at redir_buf @0x480000. REDIRECT-PASS 7/7. 13784 B arm-el0.
Redirect chain model
301/302 chain follower with 5-hop guard
redirect_follow(initial_url, max_hops) follows a redirect chain starting at initial_url. Each iteration proceeds in four steps:
1. Build response
Construct a synthetic HTTP response for the current URL in
resp_buf @0x440000.2. Parse status
Scan for two consecutive spaces after
HTTP/1.1 ; extract the 3-digit decimal status code.3. Follow redirect
If status is 301 or 302, scan for the
Location: header; extract the URL value (from after Location: to the next CR); update current URL in scratch. Increment hop_count.4. Terminate on 200
If status is 200, write final status +
hop_count + resolved URL to redir_buf @0x480000 and return.Hop guard: if hop_count >= max_hops (default 5), abort and write final status = 0 (timeout/loop) to redir_buf @0x480000.
redirect_follow(initial_url, max_hops=5)
loop:
build synthetic HTTP response → resp_buf @0x440000
parse status code (scan after "HTTP/1.1 ")
if status == 301 or 302:
scan for "Location: " → extract URL to CR
update current_url in scratch
hop_count++
if hop_count >= max_hops: write status=0 → redir_buf; return
continue
if status == 200:
write { status=200, hop_count, resolved_url } → redir_buf @0x480000
return
Test: 301→302→200 chain, 7 checks PASS:
| Check | Expected | Result |
|---|---|---|
| initial status | 301 | PASS |
| hop1 Location correct | intermediate URL | PASS |
| hop2 status | 302 | PASS |
| hop2 Location correct | final URL | PASS |
| final status | 200 | PASS |
| hop_count | 2 | PASS |
| final URL correct | resolved destination | PASS |
REDIRECT-PASS 7/7.