Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3605084
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:04:47+00:00 2026-05-18T21:04:47+00:00

I am learning erlang, and am trying to build an Http Server to better

  • 0

I am learning erlang, and am trying to build an Http Server to better learn about how erlang works, I am able to get the request:

<<“GET / HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nConnection: keep-alive\r\nCache-Control: max-age=0\r\nAccept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.51 Safari/534.3\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n\r\n”>>

but I’m not exactly sure how to begin pattern matching, or am wondering if I’m going to have to build a FSM or something to keep track of the current parses and the state. Is there a simple method to extract headers and body using pattern matching, maybe splitting on \r\n? I’d prefer not to use something like mochiweb, since I am trying to learn fundamentals.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:04:48+00:00Added an answer on May 18, 2026 at 9:04 pm

    Dead simple solution: check inet:setopts/2 and the {packet, http_bin} option.

    The more involved solution:

    You need to parse the binary. Something along the lines of:

    -module(foo).
    -compile(export_all).
    
    x() ->
        <<"GET /hello/world/ HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nConnection: keep-alive\r\nCache-Control: max-age=0\r\nAccept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.51 Safari/534.3\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n\r\n">>.
    
    parse(<<"GET ", R/binary>>) ->
        parse_get(R).
    
    parse_get(Bin) ->
        [Path, R] = binary:split(Bin, [<<" ">>]),
        {{get, Path}, R}.
    

    The basic trick is that you want to see a parser as binary() -> {parse(), binary()} where the binary output is the remaining things to parse. This sets you up nicely for a combinator-parser or a recursive descent. An alternative is to convert the binary to a list and work on that, but it is going to be considerably slower. Look at the binary modules which can do a lot of heavylifting for you in this case.

    Another alternative is to check either the Yaws or the Mochiweb applications which already has to do this and lure out what they do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started learning Erlang and am trying out some Project Euler problems
Learning java server technologies, trying to clarify some things. There are few technologies that
I am learning Erlang and I am trying to create a very sample blog
I've been learning Erlang for a while now, and for to learn it I'm
Learning C#, WPF. Currently trying to get to grips with Dispatchers, specifically between threads
I'm in the process of learning Erlang. As an exercise I picked up the
Since a few months I've been learning Erlang, and now it was time to
Learning a little about T-SQL, and thought an interesting exercise would be to generate
Learning from my last question , most member names seem to get included in
Will learning C++ help me build native applications with good speed? Will it help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.