# How can I parse a \`Socket.TCPSocket\` into an \`HTTP.Request\` in Julia?

**URL:** <https://discourse.julialang.org/t/how-can-i-parse-a-socket-tcpsocket-into-an-http-request-in-julia/59017>\
**Category:** General Usage\
**Tags:** question, package, mux, http, tcp\
**Created:** [April 11, 2021, 2:56am UTC](https://discourse.julialang.org/t/how-can-i-parse-a-socket-tcpsocket-into-an-http-request-in-julia/59017 "2021-04-11T02:56:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![apoor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/apoor/32/21367_2.png) [@apoor](https://discourse.julialang.org/u/apoor)\
**Post date:** [April 11, 2021, 2:56am UTC](https://discourse.julialang.org/t/how-can-i-parse-a-socket-tcpsocket-into-an-http-request-in-julia/59017/1 "2021-04-11T02:56:43Z")

</div>

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](https://juliaweb.github.io/HTTP.jl/stable/examples/#Simple-Server)).

```julia
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!
