I’m trying to get the both the client request and IP address from http requests to my HTTP.jl
server (based on the basic server example in the docs).
using HTTP
using Sockets
const APP = HTTP.Router()
# My request handler function can see the request's method
# and target but not the IP address it came from
HTTP.@register(APP,"GET","/",req::HTTP.Request -> begin
println("$(req.method) request to $(req.target)")
"Hello, world!"
end)
HTTP.serve(
APP,
Sockets.localhost,
8081;
# My tcpisvalid function can see the client's
# IP address but not the HTTP request
tcpisvalid=sock::Sockets.TCPSocket -> begin
host, port = Sockets.getpeername(sock)
println("Request from $host:$port")
true
end
)
My best guess would be that there’s a way to parse the TCPSocket.buffer
into an HTTP request but I can’t find any methods to do it.
Can you suggest a way to get an HTTP.Request
from a TCPSocket
or a different way to approach this problem?
Thanks in advance!