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

vlib: http.Server: different behavior between prod and non-prod for *invalid* Response object #20899

Open
hholst80 opened this issue Feb 24, 2024 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs. Unit: vlib Bugs/feature requests, that are related to the vlib.

Comments

@hholst80
Copy link
Contributor

hholst80 commented Feb 24, 2024

Describe the bug

In production the http_version can be unset and it will repond with an HTTP/0.0 response. However, compiling with tcc and w/o -prod will respond with an HTTP/1 response.

I am not sure how we would like to handle this I think the HTTP version really should be specified at the server level and not in the response, but a server should be able to handle also different HTTP versions.

Reproduction Steps

module main

import net.http { CommonHeader, Request, Response, Server }

struct BlobHandler {
}

fn (mut h BlobHandler) handle(req Request) Response {
	eprintln("Handling request")
	//mut res := http.new_response(http.ResponseConfig{
		//header: http.new_header_from_map({
		//	CommonHeader.content_type: "text/plain"
		//}),
	//})
	mut res := Response{
		header: http.new_header_from_map({
			CommonHeader.content_type: "text/plain"
		}),
	}
        eprintln(res)
        return res
}



fn main() {
	mut server := Server{
		handler: BlobHandler{},
	}
	server.listen_and_serve()
}

Expected Behavior

This is a framework problem. The error handling is unavailable to the handler and the Server needs to act reasonable when the handler gives invalid response. What is that? Error 500 something invalid Response from handler, with http_version = v1_1? (which is the default)?

Current Behavior

In production the code returns HTTP/0.0 and the client won't accept.

Possible Solution

  1. Create proper Requests
  2. Add validation code to Server to guard against invalid Requests from Handler.

Additional Information/Context

No response

V version

V 0.4.4 cf7dcfe

Environment details (OS name and version, etc.)

NAME="Artix Linux"
PRETTY_NAME="Artix Linux"
ID=artix
BUILD_ID=rolling
ANSI_COLOR="0;36"
HOME_URL="https://www.artixlinux.org/"
DOCUMENTATION_URL="https://wiki.artixlinux.org/"
SUPPORT_URL="https://forum.artixlinux.org/"
BUG_REPORT_URL="https://bugs.artixlinux.org/"
PRIVACY_POLICY_URL="https://terms.artixlinux.org/docs/privacy-policy/"
LOGO=artixlinux-logo

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@hholst80 hholst80 added the Bug This tag is applied to issues which reports bugs. label Feb 24, 2024
@felipensp felipensp added the Unit: vlib Bugs/feature requests, that are related to the vlib. label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Unit: vlib Bugs/feature requests, that are related to the vlib.
Projects
None yet
Development

No branches or pull requests

2 participants