Skip to content

Field client of type net.Endpoint on http.Request struct is never initalized in route handlers #95

@sachahjkl

Description

@sachahjkl

When running on Windows 11 or latest Arch linux (probably also on other platforms), the value of req.client is systematically nil/0

Here's a minimal example for reproduction:

package main

import http "./odin-http/"
import "core:fmt"
import "core:log"
import "core:net"


main :: proc() {
	context.logger = log.create_console_logger(.Info)

	s: http.Server
	http.server_shutdown_on_interrupt(&s)

	router: http.Router
	http.router_init(&router)
	defer http.router_destroy(&router)

	http.route_get(&router, "/", http.handler(ip_echo))


	routed := http.router_handler(&router)

	endpoint := net.Endpoint {
		address = net.IP4_Loopback,
		port    = 6969,
	}

	log.infof("listening on http://%v", net.endpoint_to_string(endpoint))
	err := http.listen_and_serve(&s, routed, endpoint)

	fmt.assertf(err == nil, "server stopped with error: %v", err)
}


ip_echo :: proc(req: ^http.Request, res: ^http.Response) {
	log.infof("IP: %v:%v", req.client.address, req.client.port)
	ip := net.endpoint_to_string(req.client)
	http.respond_plain(res, fmt.tprintf("Your IP is: %v", ip))
}

Running this program and hitting the http://localhost:6969/ endpoint returns a response with the body Your IP is: and logs out

[INFO ] --- [2025-10-16 09:59:35] [main.odin:37:ip_echo()] IP: nil:0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions