Closed
Description
Is your feature request related to a problem? Please describe.
Scripting logins or complex HTTP sequences is problematic with sendHttpRequest
due to:
Connection: close
Header: This header seems to be added by default and cannot be overridden tokeep-alive
, which can affect session handling on some servers.- Forced Automatic Redirects:
sendHttpRequest
automatically follows HTTP redirects (e.g., 302). This prevents the script from:- Accessing the headers of the intermediate redirect response (like
Location
and cruciallySet-Cookie
which often establishes the authenticated session). - Manually controlling the headers of the request to the redirected
Location
. If the automatically followed GET request has unsuitable headers (e.g., a non-browserUser-Agent
), the server might reject the (now authenticated) session, breaking the login flow.
- Accessing the headers of the intermediate redirect response (like
Describe the solution you'd like
Enhance sendHttpRequest
with options for:
followRedirects: false
(boolean, defaults totrue
): Iffalse
, the function should return the301/302/etc.
response itself, allowing the script to inspect its headers (especiallyLocation
,Set-Cookie
) and then manually make a new, fully controlled request to the target URL using the new session information.Connection
Header Control: Allow aConnection
header specified in theheaders
option (e.g.,Connection: keep-alive
) to override the client's default behavior.
Describe alternatives you've considered
- Forcing JSON responses (via
Accept
/X-Requested-With
headers) to avoid server-side302
redirects: This is server-dependent and not always honored. - Relying on current automatic redirect handling: Fails if the automatically generated request to the redirect target is not accepted by the server (due to its headers or session handling), even if the initial response setting up the session was successful.
- Raw TCP (
sendTCPPacket
): Not viable for HTTPS due to lack of SSL/TLS handling.
Additional context
A common failure scenario:
- POST to
/login_check.php
(with correct credentials). - Server responds
302 Found
,Location: /dashboard.php
, andSet-Cookie: PHPSESSID=authenticated_id
. sendHttpRequest
automatically follows the redirect. The script cannot access theauthenticated_id
from the302
'sSet-Cookie
header to ensure it's used correctly for the next manual request or to verify the session.- If the automatic GET to
/dashboard.php
(made bysendHttpRequest
itself) has headers the server dislikes (e.g., a default appUser-Agent
),/dashboard.php
may reject the session, leading to a failed login from the script's perspective.
The ability to capture the 302
response (especially Set-Cookie
) and then manually issue the subsequent GET with full header control is essential for robustly scripting these login flows. The default Connection: close
might also contribute to issues with some server-side session mechanisms.