Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's done in unicorn here <a href="https://github.com/defunkt/unicorn/blob/master/lib/unicorn/http_request.rb#L69-L71" rel="noreferrer">https://github.com/defunkt/unicorn/blob/master/lib/unicorn/http_request.rb#L69-L71</a></p> <p>There is <code>add_parse</code> method(read the comments above methods) <a href="https://github.com/defunkt/unicorn/blob/master/ext/unicorn_http/unicorn_http.rl#L760-L778" rel="noreferrer">https://github.com/defunkt/unicorn/blob/master/ext/unicorn_http/unicorn_http.rl#L760-L778</a></p> <p>Also take a look at some explanations here <a href="http://www.ruby-forum.com/topic/2267632#1014288" rel="noreferrer">http://www.ruby-forum.com/topic/2267632#1014288</a></p> <p>Here is your working code using http_parser.rb <a href="https://gist.github.com/4136962" rel="noreferrer">https://gist.github.com/4136962</a></p> <p><code>gem install http_parser.rb</code> </p> <pre><code>require 'socket' require "http/parser" READ_CHUNK = 1024 * 4 socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM) addr = Socket.pack_sockaddr_in(9799, '127.0.0.1') socket.bind(addr) socket.listen(Socket::SOMAXCONN) socket.setsockopt(:SOCKET, :REUSEADDR, true) puts "Server is listening on port = 9799" loop do connection, addr_info = socket.accept parser = Http::Parser.new begin data = connection.readpartial(READ_CHUNK) puts "Buffer = #{data}" parser &lt;&lt; data end until parser.headers connection.write("HTTP/1.1 200 \r\n") connection.write("Content-Type: text/html\r\n") connection.write("Status 200 \r\n") connection.write("Connection: close \r\n") connection.write("\r\n\r\n") connection.write("Hello World \r\n") connection.close end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload