Wednesday, September 3, 2008

gen_tcp {packet, http} mode - Erlang

This is a very useful undocumented feature in Erlang and very soon they are going to make it official. But there is nothing to refer in erlang documentation yet, So i thought of writing someting about this. Yaws uses this mode very largely and also, http://www.trapexit.org/A_fast_web_server_demonstrating_some_undocumented_Erlang_features

is a good resource for the people who are further interested in about this mode.

In this mode the http header lines are comming line by line and in a format which is very easy to decode and use.

Passive mode:

You can turn your socket in to passive mode by setting the option {active, false}

Request line:

{ok, {http_request, Method, { absoluteURI, http, URL, undefined, Rest}, {Maj, Min}}}

Method – GET, POST, etc

Keep in mind the full PATH you want to get is: URL ++ Rest

{Maj, MIN} is the digits of the http version (i.e: {1, 1} for HTTP/1.1, {1, 0} for HTTP/1.0) , Maj-Min-integer

A sample request line is given below,

{ok,{http_request,'GET',{absoluteURI,http,"www.google.com",undefined,

"/"},{1,0}}}

Header lines:

{ok, {http_header, _Num, Header_Name, undefined, Value}} - This is common for both request and response.

Header_Name - name of the header usually an atom but for user defined headers it can be a string.

Value - value of the header (string)

End of header:

{ok, http _eoh} – This is common for both request and response.

Response Line:

{ok, {http_response, {Maj, Min}, Code, ResContent}}

{Maj, Min} – Same as in Request line.

Code – http status code (e.g: 100, 200) - integer

ResContent – the status code description. (e.g: OK, Moved temporary) - string

Active mode

tuples like this in active mode:

{http_request, Socket, ...}
{http_response, Socket, ...}
{http_header, Socket, ...}

The other fields will be same as the passive mode. But in future they are going to change this to the following,

{http, Socket, {http_request, ...}}
{http, Socket, {http_response, ...}}
{http, Socket, {http_header, ...}}


The purpose is to make the inner tuples look the same regardless of how they were received.

34 comments:

sbelur said...

Hi

Just wondering whether the http socket feature is documented officially.

Is it possible for you to share this?

simoneleech said...

小遊戲,ut男同志聊天室,成人圖片區,交友104相親網,0951成人頻道下載,男同志聊天室,成人貼圖,成人影片,tt1069同志交友網,成人視訊,aio交友愛情館,情色視訊,情色視訊,色情遊戲,交友戀愛小站,jp成人,熊貓貼圖,成人圖片,成人文章,正妹,成人小說,杜蕾斯成人,ut 聊天室,熊貓貼圖區,交友聊天找e爵,ol制服美女影片,777成人區,bt成人,女同志聊天室,貼圖片區,一葉情貼圖片區,6k聊天室,69成人,成人貼圖站,色情影片,聊天室ut,免費成人影片,成人漫畫,0204貼圖區,小高聊天室,歐美免費影片,

如此的 said...

你的部落格很棒,我期待更新喔........................................

聊天室 said...

看到大家都留言,我也來留個言支持!!!加油囉 ........................................

香蕉哥哥 said...

how do u do?

治男治男 said...

nice job! waiting for your new artical. ........................................

啟俊淳達詩涵 said...

No one knows the weight of anothers burden. ......................................................

劉WileyMares said...

may the blessing be always with you!! ........................................

ElvisS_Scholten0188 said...

喜樂的心是健康良藥,憂傷的靈使骨枯乾。........................................

90809eugeniopals said...

Lets cross the bridge when we come to it........................................

詩涵 said...

噴泉的高度,不會超過它的源頭。一個人的事業也是如此,它的成就絕不會超過自己的信念。

ColtonBrawner倩亮 said...

都都成人站哈雷聊天室919sex色片直播網ao3美女圖sexsun comaaaaa7777788卡提諾成人日本a片-aa片免費看av999免費影片250av女優免費影片日本影片自拍日本影片區日本巨乳a片日本屎尿片日本少女寫真集dvd專賣店日本學生偷情影片日本學生寫真集日本寫真美女 dvd日本寫真集 rain日本寫真集女星美女 視訊美女 視訊免費線上成人影片戀愛ing聊天室免費聊天firework嘿咻kiss168cu成人bt情色 網援交友留言聊天室找一夜666成人無碼免費girl5320視訊做愛色美媚歐美模特兒寫真天空交友八國聯軍成人曼雪兒成人文學小說曼雪兒成人文學曼雪兒情色文學成人小說曼雪兒成人曼雪兒成人免費小說

LudivinaLe88787 said...

成人 免費視訊影音觀賞 聊天網 免費h卡通 0401交友 台灣女優 性感裸體寫真 免費影片線上觀看 本土自拍偷拍露點照 免費豆豆聊天室 愛愛 情趣丁字褲 成人遊戲18禁 少女裸體圖片 嘟嘟影城85c 免費a圖a片 美眉情色網 麗的色情遊戲 一夜情短片 av383tv影片 完美女人聊天室 玩美女人影音視訊 性感熱辣美女寫真 裸睡的辣妹圖片 人妻自拍畫廊 超熟女性愛 視訊聊天 空姐免費a片 a圖網情色貼圖 寫真 85cc卡通影城 杜蕾斯成人 微風 嘟嘟 av女優777 情色貼圖片 台灣援交自拍影片 情人視訊聊天室 鋼管辣妹 免費av 洪爺性愛貼圖 大奶裸體辣妹 www.sex520.com 電話下載片 日本巨乳貼圖 性愛自拍圖貼 後宮電影院女優 限制級 0204 性愛影片觀看 內褲走光

NedaD承蓁 said...

累死了…來去看看文章轉換心情~ .........................................

于呈均名 said...

天生我材必有用,千金散盡還復來。 ..................................................

淑慧 said...

愛,拆開來是心和受兩個字。用心去接受對方的一切,用心去愛對方的所有。.................................................................

義珊 said...

人間好話,要如海綿遇水牢牢吸住..................................................................

木堯木堯 said...

在莫非定律中有項笨蛋定律:「一個組織中的笨蛋,恆大於等於三分之二。」......................................................................

珍昕珍昕 said...

pleasure to find such a good artical! please keep update!!.................................................................

靜宸靜宸 said...

人有兩眼一舌,是為了觀察倍於說話的緣故。............................................................

雅莊王edgd春2蕙婷余惠其 said...

噴泉的高度,不會超過它的源頭。一個人的事業也是如此,它的成就絕不會超過自己的信念。.................................................................

賢林賢林 said...

感謝予我如此動感的blog!..................................................................

云依恩HFH謝鄭JTR安 said...

越來越多人看你的部落格 要繼續加油喔 ..................................................................

萬宇萬宇 said...

生命如夏花洵爛;死如秋葉之靜美。.......................................................

陳明陽陳明陽 said...

It may be that your sole purpose in life is simply to serve as a warning to others.............................................................

KyungBivo中如 said...

先為別人的快樂著想,是超人;先為自己的快樂著想,是凡人;使別人不快樂,自己也不快樂的,是笨人。..................................................

蔡靜芳蔡靜芳 said...

GOOD POST~~~~~~~~~~~~Support!!!!.................................[/url]...............

陳璇竹陳璇竹 said...

Habit is a second nature...................................................

許惠吟許惠吟 said...

支持好的blog~繼續加油~~..................................................................

承王蓁 said...

一句話,那就是,"船到橋頭自然直."..................................................................

皇紫勳紫勳豪 said...

死亡是悲哀的,但活得不快樂更悲哀。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

蕾蕾 said...

很耐斯的部落格,留言支持你繼續加油............................................................

王志陳雅竹豪 said...

獨居時,要反省自己的過錯;在社會大眾之間,則要忘卻別人的過失。..................................................

舒夏怡 said...

人生像一杯茶,若一飲而盡,會提早見到杯底..................................................