← Blog
0.7.0 · APPS · BROWSER

Redirect Follower — HTTP 301/302 Chain + Hop Guard (sigil-apps a17790d)

June 23, 2026 · sigil-apps a17790d · Sigil-Docs
apps browser net 0.7.0

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:

CheckExpectedResult
initial status301PASS
hop1 Location correctintermediate URLPASS
hop2 status302PASS
hop2 Location correctfinal URLPASS
final status200PASS
hop_count2PASS
final URL correctresolved destinationPASS

REDIRECT-PASS 7/7.