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

veb: add ctx.no_content() + prevent content-type being set if empty #23425

Merged
merged 2 commits into from
Jan 11, 2025

Conversation

louis77
Copy link
Contributor

@louis77 louis77 commented Jan 10, 2025

veb currently lacks a convenient way to return a 204 No Content response without a body and no content-type header.

This PR adds such a method and prevents ctx.send_response_to_client to always set a content-type header, even if it is set to an empty string.

// send a 204 No Content response without body and content-type
pub fn (mut ctx Context) no_content() Result {
	ctx.res.set_status(.no_content)
	return ctx.send_response_to_client('', '')
}

Using curl, the response looks like this:

> GET / HTTP/1.1
> Host: localhost:8888
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 204 No Content
< Server: veb

@spytheman spytheman merged commit c92a21f into vlang:master Jan 11, 2025
62 checks passed
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

Successfully merging this pull request may close these issues.

2 participants