Files
songsp77 e5bbce4fe2 fix(12306): handle endpoint rotation via 302 redirects (#1999)
* fix(12306): handle endpoint rotation via 302 redirects

Three related bugs caused the trains command to fail with
   "non-JSON body" when 12306 rotated its query endpoint:

   1. Node.js fetch defaulted to redirect: 'follow', silently
      following 12306's HTTP 302 to error.html and returning
      HTML instead of JSON.

   2. The 302 response body contained rotation info
      (e.g. {"c_url":"leftTicket/queryB"}) but was never read
      because resp.status === 302 triggered continue before
      consuming the body.

   3. Mutating QUERY_ENDPOINTS via unshift() during a for...of
      loop caused infinite iteration when the new endpoint was
      skipped by the iterator.

   Changes:
   - Set redirect: 'manual' on fetch to capture 302 responses
   - Parse c_url from 302 body and enqueue the rotated endpoint
   - Replace for...of with a while queue + Set-based dedup to
     safely handle dynamic endpoint discovery

   Fixes the trains command against the current 12306 wire
   protocol (queryG → 302 → queryB rotation).

* fix(12306): bound leftTicket endpoint rotation

---------

Co-authored-by: jackwener <jakevingoo@gmail.com>
2026-06-22 18:00:13 +08:00
..