man page for yaws apiWord文件下载.docx

上传人:b****5 文档编号:18922093 上传时间:2023-01-02 格式:DOCX 页数:19 大小:22.38KB
下载 相关 举报
man page for yaws apiWord文件下载.docx_第1页
第1页 / 共19页
man page for yaws apiWord文件下载.docx_第2页
第2页 / 共19页
man page for yaws apiWord文件下载.docx_第3页
第3页 / 共19页
man page for yaws apiWord文件下载.docx_第4页
第4页 / 共19页
man page for yaws apiWord文件下载.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

man page for yaws apiWord文件下载.docx

《man page for yaws apiWord文件下载.docx》由会员分享,可在线阅读,更多相关《man page for yaws apiWord文件下载.docx(19页珍藏版)》请在冰豆网上搜索。

man page for yaws apiWord文件下载.docx

/body>

/html>

Theout(Arg)functionissuppliedoneargument,an#arg{}structure.

Wehavethefollowingrelevantrecorddefinitions:

-record(arg,{

clisock,%%thesocketleadingtothepeerclient

client_ip_port,%%{ClientIp,ClientPort}tuple

headers,%%headers

req,%%request

clidata,%%Theclientdata(asabinaryinPOSTrequests)

server_path,%%Thenormalizedserverpath

querydata,%%WastheURLontheformof...?

query(GETreqs)

appmoddata,%%theremainderofthepathuptothequery

docroot,%%where'

sthedata

fullpath,%%fullpathtoyawsfile

cont,%%Continuationforchunkedmultipartuploads

state,%%Stateforusebyusersoftheout/1callback

pid,%%pidoftheyawsworkerprocess

opaque,%%usefultopassstaticdata

appmod_prepath,%%pathinfrontof:

appmod>

appmoddata>

pathinfo%%Setto'

d/e'

whencallingc.yawsfortherequest

%%http:

//some.host/a/b/c.yaws/d/e

}).

Theheadersargumentisalsoarecord:

-record(headers,{

connection,

accept,

host,

if_modified_since,

if_match,

if_none_match,

if_range,

if_unmodified_since,

range,

referer,

user_agent,

accept_ranges,

cookie=[],

keep_alive,

content_length,

authorization,

other=[]%%miscotherheaders

itlikes.Wehavethefollowingfunctionstoaidthatgeneration.

API

ssi(DocRoot,ListOfFiles)

Serversideinclude.Justincludethefilesasisinthedocu-

ment.Thefileswillnotbeparsedandsearchedfor<

tags.

pre_ssi_files(DocRoot,ListOfFiles)->

Serversideincludeofpreindentedcode.ThedatainFiles

willbeincludedbutcontainedina<

pre>

tag.Thedatawillbe

htmlized.

pre_ssi_string(String)

IncludehtmlizedcontentfromString.

f(Fmt,Args)

Theequivalentofio_lib:

format/2.Thisfunctionisautomati-

cally-includedinallerlangcodewhichisapartofayaws

page.

htmlize(Binary|List|Char)

HtmlizeanIOlistobject.

setcookie(Name,Value,[Path,[Expire,[Domain,[Secure]]]])

Setsacookietothebrowser.

find_cookie_val(Cookie,Header)

Thisfunctioncanbeusedtosearchforacookiethatwasprevi-

ouslysetbysetcookie/2-6.Forexampleifwesetacookieas

setcookie("

sid"

SomeRandomSid),thenonsubsequent

requestsfromthebrowserwecancall:

find_cookie("

(Arg#arg.headers)#headers.cookie)

Thefunctionreturns[]ifnocookiewasfound,otherwisethe

actualcookieisreturnedasastring.

redirect(Url

Thisfunctiongeneratesaredirecttothebrowser.Itwill

clearanypreviouslysetheaders.Sotogeneratearedirectand

setacookie,weneedtosetthecookieaftertheredirectas

in:

...dosomestuff

Ret=[{redirect,"

"

},

setcookie("

Random)

].

redirect_self(Arg)

Ifwewanttoissuearedirecttoourselves,thisfunctionis

useful.Itreturnsarecord#redir_self{}definedin

yaws_api.hrl.TherecordcontainsfieldstoconstructaURLto

ourselves.

-record(redir_self,{

host,%%string()-ourownhost

scheme,%%http|https

scheme_str,%%"

https:

//"

|"

http:

port,%%integer()-ourownport

port_str%%"

:

int>

-theoptionalportpart

%%toappendtotheurl

get_line(String)

Thisfunctionisconvenientwhengetting\r\nterminatedlines

fromastreamofdata.Itreturns:

{line,Line,Tail}or{lastline,Line,Tail}

Thefunctionhandlesmultilinesasdefinedine.g.SMTPorHTTP

mime_type(FileName)

ReturnsthemimetypeasdefinedbytheextensionofFileName

stream_chunk_deliver(YawsPid,Data)

Whenayawsfunctionneedstodeliverchunksofdatawhichitgets

fromaprocess.Theotherprocesscancallthisfunctiontodeliver

thesechunks.Itrequirestheout/1functiontoreturnthe

value{streamcontent,MimeType,FirstChunk}towork.

YawsPidistheprocessidentifieroftheyawsprocessdeliveringtheoriginal

ThePidmusttypicallybepassed(somehow)totheproducerofthestream.

stream_chunk_deliver_blocking(YawsPid,Data)

Asynchronousversionoftheabovefunction.Thissynchronousversion

mustalwaysbeusedwhentheproducerofthestreamisfasterthanthe

consumer.ThisisusuallythecasesincetheclientistheWWWbrowser.

stream_chunk_end(YawsPid)

Whentheprocessdiscussedaboveisdonedeliveringdata,itmustcall

thisfunctiontolettheyawscontentdeliveringprocessfinishup

theHTTPtransaction.

stream_process_deliver(Socket,IoList)

Yawsallowsapplicationprocessestodeliverdatadirectlytothe

client.Theapplicationtellsyawsaboutsuchaprocessbyreturning

{streamcontent_from_pid,MimeType,Pid}fromitsout/1

function.Inthiscase,Pidusesthe

stream_process_deliver/2functiontodeliverdatatothe

client.TheapplicationgetsSocketfromArg#arg.clisock,

andIoLististhedatatobesenttotheclient.

stream_process_deliver_chunk(Socket,IoList)

SameasabovebutdeliversIoListusingHTTPchunkedtransfer

format.IoListmusthaveasizegreaterthanzero.The

applicationprocessdeliveringthedatawillhavehadtohavemake

surethattheHTTPheadersoftheresponseindicatechunkedtransfer

mode,eitherbyensuringnoContent-Lengthheaderissetorby

specificallysettingtheTransfer-Encodingheadertochunked.

stream_process_deliver_final_chunk(Socket,IoList)

Iftheapplicationprocessdeliveringdatatotheclientuseschunked

transfermode,itmustcallthistodeliverthefinalchunkofthe

transfer.Thistellsyawstocreateaspecialfinalchunkinthe

formatrequiredbytheHTTPspecification(RFC2616).IoListmay

beempty,butifitssizeisgreaterthanzero,thatdatawillbe

sentasaseparatechunkbeforethefinalchunk.

stream_process_end(Socket,YawsPid)

Applicationprocessesdeliveringdatadirectlytoclientsmustcall

thisfunctiontoinformyawsthatthey'

vefinishedusing

Socket.TheYawsPidargumentwillhavebeenpassedtothe

processearlierwhenyawssentitamessagetellingittoproceedwith

datadelivery.YawsexpectsSockettobeopen.

stream_process_end(closed,YawsPid)

Sameasthepreviousfunctionbuttheapplicationcallsthisifit

closestheclientsocketaspartofitsdatadeliveryprocess.This

allowsyawstocontinuewithoutassumingthesocketisstillopenand

encounteringerrorsduetothatassumption.TheYawsPidargument

willhavebeenpassedtotheapplicationprocessearlierwhenyaws

sentitamessagetellingittoproceedwithdatadelivery.

parse_query(Arg)

ThisfunctionwillparsethequerypartoftheURL.

Itwillreturna{Key,Value}listoftheitemssuppliedinthequery

partoftheURL.

queryvar(Arg,VarName)

Thisfunctionisautomaticallyincludedfromyaws_apiinall

.yawspages.Itisusedtosearchforavariableinthe

querypartoftheurl.Returns{ok,Val}orundefined.

Ifavariableisdefinedmultipletimes,thefunctionmayalso

return{Val1,....}.

parse_post(Arg)

ThisfunctionwillparsethePOSTdataassuppliedfromthebrowser.

Itwillreturna{Key,Value}listoftheitemssetbythebrowser.

postvar(Arg,VarName)

POSTeddatafromtheclient.Returns{ok,Val}orundefined.

getvar(Arg,VarName)

ThisfunctionlooksattheHTTPrequestmethodfromthe

clientandinvokespostvar/2ifitisaPOSTfromtheclient

andqueryvar/2ifitisaGETrequestfromtheclient.

parse_multipart_post(Arg)

IfthebrowserhassettheContent-Typeheadertothevalue

"

multipart/form-data"

whichisthecasewhenthebrowser

wantstouploadafiletotheserverthefollowinghappens:

Ifthefunctionreturns{result,Res}nomoredata

willcomefromthebrowser.

Ifthefunctionreturns{cont,Cont,Res}thebrowser

willsupplymoredata.(Thefilewastobigtocomeinoneread)

Thisindicatesthatthereismoredatatocomeandtheout/1function

shouldreturn{get_more,Cont,User_state}whereUser_statemight

usefullybeaFileDescriptor.

TheResvalueisalistofeither:

{header,Header}|{part_body,Binary}|{body,Binary}

Exampleusagecouldbe:

out(A)->

caseyaws_api:

parse_multipart_post(A)of

{cont,Cont,Res}->

St=handle_res(A,Res),

{get_more,Cont,St};

{result,Res}->

handle_res(A,Res),

{html,f("

Done<

/pre>

[])}

end.

handle_res(A,[{head,Name}|T])->

io:

format("

head:

~p~n"

[Name]),

handle_res(A,T);

handle_res(A,[{part_body,Data}|T])->

part_body:

[Data]),

handle_res(A,[{body,Data}|T])->

body:

handle_res(A,[])->

End_res~n"

).

new_cookie_session(Opaque)

Createanewcookiebasedsession,theyawssystemwillsetthe

cookie.Thenewrandomgeneratedcookieisreturnedfromthis

function.TheOpaqueargumentwilltypicallycontainuserdata

suchasusernameandpa

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1