Stream: beginners

Topic: Sending Http requests with basic-webserver


view this post on Zulip Adrian (Dec 06 2024 at 01:59):

I was attempting to send a http request and got some weird bugs...
This is the minimal example of the buggy behavior
I build and run with roc dev --linker=legacy

app [Model, server] { pf: platform "https://github.com/roc-lang/basic-webserver/releases/download/0.10.0/BgDDIykwcg51W8HA58FE_BjdzgXVk--ucv6pVb_Adik.tar.br" }

import pf.Http

Model : {}

server = { init: Task.ok {}, respond }

respond = \_, _ ->
    dbg "req"
    { Http.defaultRequest & url: "https://z.4a.si/spam/objave/" }
    |> Http.send
    # |> Task.map .body
    |> Task.attempt
        \x ->
            aa = Inspect.toStr x
            dbg x
            dbg aa
            Task.ok { body: "Womp womp" |> Str.toUtf8, headers: [], status: 500 }

Thanks in advance for informing me of my mistakes :)

view this post on Zulip Adrian (Dec 06 2024 at 02:00):

This sample seems to be working when i replace the domain with google.com ?

view this post on Zulip Anton (Dec 06 2024 at 11:28):

Does your request to "https://z.4a.si/spam/objave/" work if you use curl?

view this post on Zulip Adrian (Dec 06 2024 at 12:05):

Anton said:

Does your request to "https://z.4a.si/spam/objave/" work if you use curl?

Yes, and even if it didn't that should not cause a segfault?

view this post on Zulip Anthony Bullard (Dec 06 2024 at 12:06):

I wonder if it is something about the result returned from that endpoint

view this post on Zulip Anthony Bullard (Dec 06 2024 at 12:06):

Can you post the result from curl here?

view this post on Zulip Adrian (Dec 06 2024 at 12:07):

image.png

view this post on Zulip Anthony Bullard (Dec 06 2024 at 12:09):

I'm going to assume this fails on the Inspect.toStr x

view this post on Zulip Adrian (Dec 06 2024 at 12:10):

Might be just too big of a http response?

view this post on Zulip Anthony Bullard (Dec 06 2024 at 12:10):

If you place your dbg before that

view this post on Zulip Anthony Bullard (Dec 06 2024 at 12:10):

Well curl says it's empty....

view this post on Zulip Adrian (Dec 06 2024 at 12:10):

image.png

view this post on Zulip Adrian (Dec 06 2024 at 12:11):

Anthony Bullard said:

Well curl says it's empty....

I get 26K of data

view this post on Zulip Adrian (Dec 06 2024 at 12:11):

I guess my friend must be blocking non slovenian IPs

view this post on Zulip Adrian (Dec 06 2024 at 12:11):

:/

view this post on Zulip Adrian (Dec 06 2024 at 12:11):

am workin on uploading the curls

view this post on Zulip Adrian (Dec 06 2024 at 12:13):

Curl -vvvvv URL
STDOUT: https://ass.si/f/ixaf8
STDERR: https://ass.si/f/4-3s4

view this post on Zulip Anthony Bullard (Dec 06 2024 at 12:15):

Sorry, could you post to a GH gist? I am not in the habit of clicking links to random servers I don't know :-)

view this post on Zulip Adrian (Dec 06 2024 at 12:18):

Anthony Bullard said:

Sorry, could you post to a GH gist? I am not in the habit of clicking links to random servers I don't know :-)

Fair enough, here's a paste bin: https://pastebin.com/TvUz9i08 (STDOUT)
https://pastebin.com/EdhedARE (STDERR)

view this post on Zulip Anthony Bullard (Dec 06 2024 at 12:23):

Thanks! Interesting.....There is nothing that is obviously wrong there. Hopefully we don't segfault on handling multiple packets :rofl:

view this post on Zulip Anthony Bullard (Dec 06 2024 at 12:24):

I have a lot on my plate right now, so can't dig in deep. But hopefully that information is helpful for someone with better knowledge of the HTTP module implementationn

view this post on Zulip Adrian (Dec 06 2024 at 12:47):

I think there was a regression somewhere, because i have already produced a binary, that works with this code :/

view this post on Zulip Anthony Bullard (Dec 06 2024 at 13:16):

Can you let us know when was the last time the Roc compiler produced a working binary with this code?

view this post on Zulip Adrian (Dec 06 2024 at 13:39):

I think my build was on 2024-06-25 but i didn't exactly build this project every day, so some versions could still be working after this date

view this post on Zulip Adrian (Dec 06 2024 at 14:01):

image.png
image.png
The definition orders don't match, im surprised that they aren't important :shrug:

view this post on Zulip Anthony Bullard (Dec 06 2024 at 14:01):

Sure but that helps limit a bisect

view this post on Zulip Anthony Bullard (Dec 06 2024 at 14:02):

That is curious

view this post on Zulip Anthony Bullard (Dec 06 2024 at 14:02):

Have you updated the platform version?

view this post on Zulip Adrian (Dec 06 2024 at 14:02):

Im looking this up on github

view this post on Zulip Adrian (Dec 06 2024 at 14:02):

both on master branch

view this post on Zulip Anthony Bullard (Dec 06 2024 at 14:02):

Yeah, sorry, I lost my mind there for a sec

view this post on Zulip Adrian (Dec 06 2024 at 14:03):

as for my project, i think i have the latest release
Dw, happens to the best of us

view this post on Zulip Anthony Bullard (Dec 06 2024 at 14:11):

But they are named fields so I don't think that order would matter until we get to Mono

view this post on Zulip Adrian (Dec 06 2024 at 14:12):

Maybe i missed the translating code from one to another, i just assumed it was a ptr cast. Even if this was problematic, it would cause the same problem for google.com as for z.4a.si

view this post on Zulip Anthony Bullard (Dec 06 2024 at 14:45):

Yep

view this post on Zulip Adrian (Dec 09 2024 at 10:13):

This is what roc's request looks like.

view this post on Zulip Adrian (Dec 09 2024 at 10:16):

GET /spam/objave/ HTTP/1.1
content-type:
content-length: 0
accept: */*
host: z.4a.si:80

and the nginx response:

read(net): Connection reset by peer

view this post on Zulip Adrian (Dec 09 2024 at 10:32):

It seems that the problem is the space after : on line content-type:

view this post on Zulip Notification Bot (Dec 09 2024 at 10:32):

Adrian has marked this topic as resolved.

view this post on Zulip Anthony Bullard (Dec 09 2024 at 10:47):

So default request doesn’t set a content-type?

view this post on Zulip Notification Bot (Dec 09 2024 at 11:39):

Adrian has marked this topic as unresolved.

view this post on Zulip Adrian (Dec 09 2024 at 11:40):

Anthony Bullard said:

So default request doesn’t set a content-type?

It doesn't, but I found out my testing method was flawed

view this post on Zulip Adrian (Dec 09 2024 at 11:40):

The problem is on roc-s side

view this post on Zulip Adrian (Dec 09 2024 at 11:41):

I have wireshark packet caps, that show receiving a "valid response", and then roc segfaults

view this post on Zulip Adrian (Dec 09 2024 at 11:54):

https://pastebin.com/Yg1vqkk7

view this post on Zulip Adrian (Dec 15 2024 at 19:48):

It seems to also break while requesting "http://www.gstatic.com/generate_204"

view this post on Zulip Adrian (Dec 15 2024 at 19:48):

Will open a bug report

view this post on Zulip Luke Boswell (Dec 15 2024 at 20:12):

Thank you for the repro, I'll check this with the new purity inference upgrade I've been working on.

Haven't got hello world working yet, also suffering a segfault somewhere. But hopefully we can figure that out.


Last updated: Jul 06 2025 at 12:14 UTC