Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http server with mount, client POST json file, how to read content? #3056

Open
AlojzyB opened this issue Jan 30, 2024 · 1 comment
Open

http server with mount, client POST json file, how to read content? #3056

AlojzyB opened this issue Jan 30, 2024 · 1 comment

Comments

@AlojzyB
Copy link

AlojzyB commented Jan 30, 2024

Dear folks,
have use 4.3.3 revision, configured as http server using mount and basic auth. Origin and default target are set to json file.

static const struct lws_http_mount mount_vas = {
	/* .mount_next */				NULL,		/* linked-list "next" */
	/* .mountpoint */				"/vas",	/* mountpoint URL */
	/* .origin */					"dev/shm",
	/* .def */						"test.json",
	/* .protocol */					NULL,
	/* .cgienv */					NULL,
	/* .extra_mimetypes */			NULL,
	/* .interpret */				NULL,
	/* .cgi_timeout */				0,
	/* .cache_max_age */			0,
	/* .auth_mask */				0,
	/* .cache_reusable */			0,
	/* .cache_revalidate */			0,
	/* .cache_intermediaries */		0,
	/* .origin_protocol */			LWSMPRO_FILE, /* dynamic */
	/* .mountpoint_len */			4,		/* char count */
	/* .basic_auth_login_file */	".pass-file",
};

Works fine with POST request from client - test.json file is send correctly:

http --verbose -a admin:admin -f POST localhost:80/vas/ seq=0 VIN=4Y1SL65848Z411439 --json

HTTP/1.1 200 OK
cache-control: no-store
content-length: 51
content-security-policy: default-src 'none'; img-src 'self' data: ; script-src 'self'; font-src 'self'; style-src 'self'; connect-src 'self' ws: wss:; frame-ancestors 'none'; base-uri 'none';form-action 'self';
content-type: application/json
etag: 00000033386D4403
referrer-policy: no-referrer
x-content-type-options: nosniff
x-frame-options: deny
x-xss-protection: 1; mode=block

{
"seq": 0,
"vin": "aslkdhfkdsjhgfjhkjdhfgkjfdg"
}

The problem is that have no idea how to read POST request content (json file as on this example) since there is no LWS_CALLBACK_HTTP_BODY nor LWS_CALLBACK_HTTP_BODY_COMPLETION callbacks.

Have read header tokens WSI_TOKEN_HTTP_CONTENT_TYPE and WSI_TOKEN_HTTP_CONTENT_LENGTH which gives correct data: "application/json" and 40 bytes respectively. So, lws have complete POST frame.
Please advice me how to read POST content.

@ffreality
Copy link

I figured it out that if I use lws_callback_http_dummy as return value of protocol callback, LWS_CALLBACK_HTTP_BODY won't trigger. So, I used return 0 and char* body = (char*)in; gives Body. But I for my use case, I am trying to integrate library to unreal engine. So, I need to create a proper response logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants