man page for yaws apiWord文件下载.docx
- 文档编号:18922093
- 上传时间:2023-01-02
- 格式:DOCX
- 页数:19
- 大小:22.38KB
man page for yaws apiWord文件下载.docx
《man page for yaws apiWord文件下载.docx》由会员分享,可在线阅读,更多相关《man page for yaws apiWord文件下载.docx(19页珍藏版)》请在冰豆网上搜索。
/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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- man page for yaws api