<renich>
I am trying to write a "one-liner" for a web server in my GNUMakefile so that crystal serves my html website for previewing. I got this from the docs: crystal eval 'require "http/server"; server = HTTP::Server.new( [HTTP::ErrorHandler.new, HTTP::LogHandler.new, HTTP::CompressHandler.new, HTTP::StaticFileHandler.new("web/")] ); server.bind_tcp "127.0.0.1", 12345; puts; puts "La página está disponible en: http://localhost:12345/ind
<renich>
ex.html"; puts "Presiona Ctrl + c para detenerlo..."; puts; server.listen'
<renich>
The only problem is that it doesn't set the content-type header correctly. I'd like to have: Content-type: text/html; charset: utf8;
<renich>
I tried using the HTTP::Server::Response object, but didn't quite figure it out.
renich has quit [Quit: Leaving.]
<FromGitter>
<HertzDevil> > Because it defined functions, not methods. They don't share a state ⏎ ⏎ not true, it defines methods on the module's metaclass
<FromGitter>
<HertzDevil> every class is an instance of its own metaclass
<FromGitter>
<HertzDevil> this is even more the case in ruby where hooks like `extended` are regular methods and dynamic classes are possible
<FromGitter>
<vinyll> Wow, that's something I would not have expected
<FromGitter>
<vinyll> Thanks for the quick help, it just works 👍
<FromGitter>
<Blacksmoke16> np
<FromGitter>
<asterite> Wow, I can't believe so many people get tripped by this, and why there is such a big resistance to fix it for good
<jhass>
is there? so far I think only brian objected to get rid of body_io, for the rest of us we just can't quite agree on how to fix it :P
<FromGitter>
<vinyll> Funny enough this is my first script in Crystal and I face this trap after 20 lines of code ^^
<FromGitter>
<asterite> Well, resistance to my specific proposal :-P
<FromGitter>
<asterite> (which makes things type safe and obvious)
<FromGitter>
<asterite> I'm also surprised by Brian's rejection. Give his Haskell and functional background, I'm surprised he didn't like the variants approach, which is the most type safe way to model this
teardown has quit [Ping timeout: 240 seconds]
teardown has joined #crystal-lang
<FromGitter>
<j8r> @asterite Sometimes, a discussion which involves lots of small replies is not well suited for text. ⏎ Then, the topic looks more complex as it is. ⏎ I'm pretty sure a call meeting with the core team can settle this rather quickly.
<FromGitter>
<j8r> That's my experience overall 😉
<raz>
i think i like the "always IO" option best. no surprises.
<raz>
otoh i also like the idea of having a smarter method that raises on bad http code, perhaps smartly switches to a tempfile for huge replies, handles timeouts (connection vs fifst-byte vs transfer vs duration) etc.
<raz>
these are the types of things that otherwise everyone rolls themselves poorly until some defacto standard 3rd party library emerges
<FromGitter>
<j8r> I'd be fore having only the block variant
<raz>
j8r: yea, i kinda like that idea, too. just wonder how it might interfere when you really just want to grab the IO and pass it around to be handled elsewhere
<FromGitter>
<j8r> IMHO there are too much methods in `HTTP::Client`, to basically do the same thing
<FromGitter>
<j8r> because the block variant close at the end...
<FromGitter>
<j8r> good point
<raz>
yep, not sure if it's a realistic scenario, but i imagine it could make it a bit more tricky when you want to juggle long-lived connections (spawn a few, hand off to worker fibers etc.)
<raz>
then again... can't really think of an actual use-case where i'd want to do that
<FromGitter>
<j8r> raz: in fact; not
<raz>
(and where i couldn't just run the whole block in the worker fiber)
<FromGitter>
<j8r> if one want something specific: `HTTP::Client.new`
<raz>
indeed
<FromGitter>
<j8r> `HTTP::Client.get` I think close the connection, and puts the body in a string
<FromGitter>
<j8r> that's why there are IO errors
<raz>
hm hm, yea i haven't really used it enough to truly judge. i went straight to https://github.com/mamantoha/crest for my http client dabblings
<FromGitter>
<j8r> I don't like this rubyism `{:lang => "en"}` :(
<raz>
but perhaps there's a case to be made for keeping HTTP::Client "raw" anyway (as in "always IO") and leave those fancy pants to a 3rd party shard
<FromGitter>
<j8r> the only, main pros is for following redirections
<raz>
ya well i haven't used crest for super-fancy stuff, but for the basics it felt alright. i was in particular glad it has timeout handling so i didn't have to think about it