Web server.I can't figure out how to do it

the server makes a post request with type application/x-www-form-urlencoded

(https://v.hopto.org:8083/courier?DOMAIN=v.ru&PROTOCOL=1&LANG=ru&APP_SID=63a14505f147b126)
form
AUTH_ID=bb3d6765066cdebfe32f6402c1f3a5e19846b&AUTH_EXPIRES=3600&REFRESH_ID=abbc8e650068f160b223e053178f8c8d05424f7c8ca&member_id=bf761deb0c0&status=L&PLACEMENT=MENU&PLACEMENT_OPTIONS=%7B%22ID%22%3A%221015699%22%7D
PLACEMENT_OPTIONS: {"ID":"1015699"}

here is the end of the form. I wrote my handler for

:- http_handler(root(.), http_reply_from_files(static_dir(.), [cache(true)]), [prefix]). 

otherwise the contents of the form are sent to Request as is further

http_read_data(Request, Data, []),
http_reply_from_files(static_dir(.), [cache(true)], []).

And there seems to be something wrong with that. Somehow the AUTH_ID=.. seems to get prepended before the HTTP request. While you claim you do a POST request, the debug message says

which suggests this is a GET request (with something in front of it that should not be there). To me (but I could be wrong), the thing to debug is the thing making the request rather than the Prolog server. It is only helpful that it shows the actual request.

The other option could be that the request before was supposed to be a POST request using the AUTH_ID=.. as body, but was in fact a GET request. In that case the server will not read the body and the body will be seen as the next request. If you get a POST request, you must read the body using either http_parameters/2 (for www-form-encoded) or http_read_data/3 (for any content type). AFAIK, the server does not protect against not reading the POST data. Note that on failure or error of the HTTP handler, the server will close this connection to avoid such issues.

1 Like

detailed investigation required.

:- http_handler(root(courier), http_reply_from_files(static_dir(.), [cache(true)]), [prefix]).

in this version, the post request will forward the form application/x-www-form-urlencoded
I send an html page to a post request and it does a get, but the request receives a form.
I need to read the form and pass the request further without the form, can I do this? now Iā€™m passing an empty list, but thatā€™s probably wrong

Iā€™m afraid I canā€™t parse this. Please create a minimal reproducing example. I start thinking you are doing something wrong and that this not replying the static files. The rest remains guessing and I tried that enough :frowning:

I donā€™t quite understand what other example you want.

:- http_handler(root(courier), http_reply_from_files(static_dir(.), [cache(true)]), [prefix]).

this is the only thing I have.Iā€™m making an embedded application for https://www.bitrix24.com/
Embedding locations general info
I need to give the html page, I donā€™t do anything else

<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<link rel="icon" href="/favicon.png" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		
		<link rel="modulepreload" href="/_app/immutable/entry/start.2113177d.js">
		<link rel="modulepreload" href="/_app/immutable/chunks/scheduler.e108d1fd.js">
		<link rel="modulepreload" href="/_app/immutable/chunks/singletons.e8747018.js">
		<link rel="modulepreload" href="/_app/immutable/entry/app.18e7a831.js">
		<link rel="modulepreload" href="/_app/immutable/chunks/index.a21d6cee.js">
	</head>
	<body data-sveltekit-preload-data="hover">
		<div style="display: contents">
			<script>
				{
					__sveltekit_bkwbhb = {
						base: "",
						env: {}
					};

					const element = document.currentScript.parentElement;

					Promise.all([
						import("/_app/immutable/entry/start.2113177d.js"),
						import("/_app/immutable/entry/app.18e7a831.js")
					]).then(([kit, app]) => {
						kit.start(app, element);
					});
				}
			</script>
		</div>
	</body>
</html>

it is partially reproduced like this.

curl -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost/courier

the problem is solved if for a post request with content_type(ā€˜application/x-www-form-urlencodedā€™) make http_read_data(Request, Data, ),
http_reply_from_files(static_dir(.), [cache(true)], Request).

Good. As I said, a handler dealing with a POST request should always read the data. The predicates that reply a file donā€™t. Probably the handler should add the option method(get). http_reply_from_files/3 canā€™t check that as it may be called directly in a handler, but as you now do, also as part of a correct POST request. Anyway, please mark as ā€œsolutionā€.

My http_handler_redirect/3 simply outputs some debug information and then calls http_redirect/3. Iā€™ll edit my answer accordingly.

This is in library(clib/uri).