nghttp2.h 186 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487
  1. /*
  2. * nghttp2 - HTTP/2 C Library
  3. *
  4. * Copyright (c) 2013, 2014 Tatsuhiro Tsujikawa
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGHTTP2_H
  26. #define NGHTTP2_H
  27. /* Define WIN32 when build target is Win32 API (borrowed from
  28. libcurl) */
  29. #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
  30. # define WIN32
  31. #endif
  32. /* Compatibility for non-Clang compilers */
  33. #ifndef __has_declspec_attribute
  34. # define __has_declspec_attribute(x) 0
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #include <stdlib.h>
  40. #if defined(_MSC_VER) && (_MSC_VER < 1800)
  41. /* MSVC < 2013 does not have inttypes.h because it is not C99
  42. compliant. See compiler macros and version number in
  43. https://sourceforge.net/p/predef/wiki/Compilers/ */
  44. # include <stdint.h>
  45. #else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
  46. # include <inttypes.h>
  47. #endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
  48. #include <sys/types.h>
  49. #include <stdarg.h>
  50. #include <nghttp2/nghttp2ver.h>
  51. #ifdef NGHTTP2_STATICLIB
  52. # define NGHTTP2_EXTERN
  53. #elif defined(WIN32) || (__has_declspec_attribute(dllexport) && \
  54. __has_declspec_attribute(dllimport))
  55. # ifdef BUILDING_NGHTTP2
  56. # define NGHTTP2_EXTERN __declspec(dllexport)
  57. # else /* !BUILDING_NGHTTP2 */
  58. # define NGHTTP2_EXTERN __declspec(dllimport)
  59. # endif /* !BUILDING_NGHTTP2 */
  60. #else /* !defined(WIN32) */
  61. # ifdef BUILDING_NGHTTP2
  62. # define NGHTTP2_EXTERN __attribute__((visibility("default")))
  63. # else /* !BUILDING_NGHTTP2 */
  64. # define NGHTTP2_EXTERN
  65. # endif /* !BUILDING_NGHTTP2 */
  66. #endif /* !defined(WIN32) */
  67. /**
  68. * @macro
  69. *
  70. * The protocol version identification string of this library
  71. * supports. This identifier is used if HTTP/2 is used over TLS.
  72. */
  73. #define NGHTTP2_PROTO_VERSION_ID "h2"
  74. /**
  75. * @macro
  76. *
  77. * The length of :macro:`NGHTTP2_PROTO_VERSION_ID`.
  78. */
  79. #define NGHTTP2_PROTO_VERSION_ID_LEN 2
  80. /**
  81. * @macro
  82. *
  83. * The serialized form of ALPN protocol identifier this library
  84. * supports. Notice that first byte is the length of following
  85. * protocol identifier. This is the same wire format of `TLS ALPN
  86. * extension <https://tools.ietf.org/html/rfc7301>`_. This is useful
  87. * to process incoming ALPN tokens in wire format.
  88. */
  89. #define NGHTTP2_PROTO_ALPN "\x2h2"
  90. /**
  91. * @macro
  92. *
  93. * The length of :macro:`NGHTTP2_PROTO_ALPN`.
  94. */
  95. #define NGHTTP2_PROTO_ALPN_LEN (sizeof(NGHTTP2_PROTO_ALPN) - 1)
  96. /**
  97. * @macro
  98. *
  99. * The protocol version identification string of this library
  100. * supports. This identifier is used if HTTP/2 is used over cleartext
  101. * TCP.
  102. */
  103. #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c"
  104. /**
  105. * @macro
  106. *
  107. * The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`.
  108. */
  109. #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3
  110. struct nghttp2_session;
  111. /**
  112. * @struct
  113. *
  114. * The primary structure to hold the resources needed for a HTTP/2
  115. * session. The details of this structure are intentionally hidden
  116. * from the public API.
  117. */
  118. typedef struct nghttp2_session nghttp2_session;
  119. /**
  120. * @macro
  121. *
  122. * The age of :type:`nghttp2_info`
  123. */
  124. #define NGHTTP2_VERSION_AGE 1
  125. /**
  126. * @struct
  127. *
  128. * This struct is what `nghttp2_version()` returns. It holds
  129. * information about the particular nghttp2 version.
  130. */
  131. typedef struct {
  132. /**
  133. * Age of this struct. This instance of nghttp2 sets it to
  134. * :macro:`NGHTTP2_VERSION_AGE` but a future version may bump it and
  135. * add more struct fields at the bottom
  136. */
  137. int age;
  138. /**
  139. * the :macro:`NGHTTP2_VERSION_NUM` number (since age ==1)
  140. */
  141. int version_num;
  142. /**
  143. * points to the :macro:`NGHTTP2_VERSION` string (since age ==1)
  144. */
  145. const char *version_str;
  146. /**
  147. * points to the :macro:`NGHTTP2_PROTO_VERSION_ID` string this
  148. * instance implements (since age ==1)
  149. */
  150. const char *proto_str;
  151. /* -------- the above fields all exist when age == 1 */
  152. } nghttp2_info;
  153. /**
  154. * @macro
  155. *
  156. * The default weight of stream dependency.
  157. */
  158. #define NGHTTP2_DEFAULT_WEIGHT 16
  159. /**
  160. * @macro
  161. *
  162. * The maximum weight of stream dependency.
  163. */
  164. #define NGHTTP2_MAX_WEIGHT 256
  165. /**
  166. * @macro
  167. *
  168. * The minimum weight of stream dependency.
  169. */
  170. #define NGHTTP2_MIN_WEIGHT 1
  171. /**
  172. * @macro
  173. *
  174. * The maximum window size
  175. */
  176. #define NGHTTP2_MAX_WINDOW_SIZE ((int32_t)((1U << 31) - 1))
  177. /**
  178. * @macro
  179. *
  180. * The initial window size for stream level flow control.
  181. */
  182. #define NGHTTP2_INITIAL_WINDOW_SIZE ((1 << 16) - 1)
  183. /**
  184. * @macro
  185. *
  186. * The initial window size for connection level flow control.
  187. */
  188. #define NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE ((1 << 16) - 1)
  189. /**
  190. * @macro
  191. *
  192. * The default header table size.
  193. */
  194. #define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12)
  195. /**
  196. * @macro
  197. *
  198. * The client magic string, which is the first 24 bytes byte string of
  199. * client connection preface.
  200. */
  201. #define NGHTTP2_CLIENT_MAGIC "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
  202. /**
  203. * @macro
  204. *
  205. * The length of :macro:`NGHTTP2_CLIENT_MAGIC`.
  206. */
  207. #define NGHTTP2_CLIENT_MAGIC_LEN 24
  208. /**
  209. * @enum
  210. *
  211. * Error codes used in this library. The code range is [-999, -500],
  212. * inclusive. The following values are defined:
  213. */
  214. typedef enum {
  215. /**
  216. * Invalid argument passed.
  217. */
  218. NGHTTP2_ERR_INVALID_ARGUMENT = -501,
  219. /**
  220. * Out of buffer space.
  221. */
  222. NGHTTP2_ERR_BUFFER_ERROR = -502,
  223. /**
  224. * The specified protocol version is not supported.
  225. */
  226. NGHTTP2_ERR_UNSUPPORTED_VERSION = -503,
  227. /**
  228. * Used as a return value from :type:`nghttp2_send_callback`,
  229. * :type:`nghttp2_recv_callback` and
  230. * :type:`nghttp2_send_data_callback` to indicate that the operation
  231. * would block.
  232. */
  233. NGHTTP2_ERR_WOULDBLOCK = -504,
  234. /**
  235. * General protocol error
  236. */
  237. NGHTTP2_ERR_PROTO = -505,
  238. /**
  239. * The frame is invalid.
  240. */
  241. NGHTTP2_ERR_INVALID_FRAME = -506,
  242. /**
  243. * The peer performed a shutdown on the connection.
  244. */
  245. NGHTTP2_ERR_EOF = -507,
  246. /**
  247. * Used as a return value from
  248. * :func:`nghttp2_data_source_read_callback` to indicate that data
  249. * transfer is postponed. See
  250. * :func:`nghttp2_data_source_read_callback` for details.
  251. */
  252. NGHTTP2_ERR_DEFERRED = -508,
  253. /**
  254. * Stream ID has reached the maximum value. Therefore no stream ID
  255. * is available.
  256. */
  257. NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509,
  258. /**
  259. * The stream is already closed; or the stream ID is invalid.
  260. */
  261. NGHTTP2_ERR_STREAM_CLOSED = -510,
  262. /**
  263. * RST_STREAM has been added to the outbound queue. The stream is
  264. * in closing state.
  265. */
  266. NGHTTP2_ERR_STREAM_CLOSING = -511,
  267. /**
  268. * The transmission is not allowed for this stream (e.g., a frame
  269. * with END_STREAM flag set has already sent).
  270. */
  271. NGHTTP2_ERR_STREAM_SHUT_WR = -512,
  272. /**
  273. * The stream ID is invalid.
  274. */
  275. NGHTTP2_ERR_INVALID_STREAM_ID = -513,
  276. /**
  277. * The state of the stream is not valid (e.g., DATA cannot be sent
  278. * to the stream if response HEADERS has not been sent).
  279. */
  280. NGHTTP2_ERR_INVALID_STREAM_STATE = -514,
  281. /**
  282. * Another DATA frame has already been deferred.
  283. */
  284. NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515,
  285. /**
  286. * Starting new stream is not allowed (e.g., GOAWAY has been sent
  287. * and/or received).
  288. */
  289. NGHTTP2_ERR_START_STREAM_NOT_ALLOWED = -516,
  290. /**
  291. * GOAWAY has already been sent.
  292. */
  293. NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517,
  294. /**
  295. * The received frame contains the invalid header block (e.g., There
  296. * are duplicate header names; or the header names are not encoded
  297. * in US-ASCII character set and not lower cased; or the header name
  298. * is zero-length string; or the header value contains multiple
  299. * in-sequence NUL bytes).
  300. */
  301. NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518,
  302. /**
  303. * Indicates that the context is not suitable to perform the
  304. * requested operation.
  305. */
  306. NGHTTP2_ERR_INVALID_STATE = -519,
  307. /**
  308. * The user callback function failed due to the temporal error.
  309. */
  310. NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521,
  311. /**
  312. * The length of the frame is invalid, either too large or too small.
  313. */
  314. NGHTTP2_ERR_FRAME_SIZE_ERROR = -522,
  315. /**
  316. * Header block inflate/deflate error.
  317. */
  318. NGHTTP2_ERR_HEADER_COMP = -523,
  319. /**
  320. * Flow control error
  321. */
  322. NGHTTP2_ERR_FLOW_CONTROL = -524,
  323. /**
  324. * Insufficient buffer size given to function.
  325. */
  326. NGHTTP2_ERR_INSUFF_BUFSIZE = -525,
  327. /**
  328. * Callback was paused by the application
  329. */
  330. NGHTTP2_ERR_PAUSE = -526,
  331. /**
  332. * There are too many in-flight SETTING frame and no more
  333. * transmission of SETTINGS is allowed.
  334. */
  335. NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS = -527,
  336. /**
  337. * The server push is disabled.
  338. */
  339. NGHTTP2_ERR_PUSH_DISABLED = -528,
  340. /**
  341. * DATA or HEADERS frame for a given stream has been already
  342. * submitted and has not been fully processed yet. Application
  343. * should wait for the transmission of the previously submitted
  344. * frame before submitting another.
  345. */
  346. NGHTTP2_ERR_DATA_EXIST = -529,
  347. /**
  348. * The current session is closing due to a connection error or
  349. * `nghttp2_session_terminate_session()` is called.
  350. */
  351. NGHTTP2_ERR_SESSION_CLOSING = -530,
  352. /**
  353. * Invalid HTTP header field was received and stream is going to be
  354. * closed.
  355. */
  356. NGHTTP2_ERR_HTTP_HEADER = -531,
  357. /**
  358. * Violation in HTTP messaging rule.
  359. */
  360. NGHTTP2_ERR_HTTP_MESSAGING = -532,
  361. /**
  362. * Stream was refused.
  363. */
  364. NGHTTP2_ERR_REFUSED_STREAM = -533,
  365. /**
  366. * Unexpected internal error, but recovered.
  367. */
  368. NGHTTP2_ERR_INTERNAL = -534,
  369. /**
  370. * Indicates that a processing was canceled.
  371. */
  372. NGHTTP2_ERR_CANCEL = -535,
  373. /**
  374. * When a local endpoint expects to receive SETTINGS frame, it
  375. * receives an other type of frame.
  376. */
  377. NGHTTP2_ERR_SETTINGS_EXPECTED = -536,
  378. /**
  379. * The errors < :enum:`NGHTTP2_ERR_FATAL` mean that the library is
  380. * under unexpected condition and processing was terminated (e.g.,
  381. * out of memory). If application receives this error code, it must
  382. * stop using that :type:`nghttp2_session` object and only allowed
  383. * operation for that object is deallocate it using
  384. * `nghttp2_session_del()`.
  385. */
  386. NGHTTP2_ERR_FATAL = -900,
  387. /**
  388. * Out of memory. This is a fatal error.
  389. */
  390. NGHTTP2_ERR_NOMEM = -901,
  391. /**
  392. * The user callback function failed. This is a fatal error.
  393. */
  394. NGHTTP2_ERR_CALLBACK_FAILURE = -902,
  395. /**
  396. * Invalid client magic (see :macro:`NGHTTP2_CLIENT_MAGIC`) was
  397. * received and further processing is not possible.
  398. */
  399. NGHTTP2_ERR_BAD_CLIENT_MAGIC = -903,
  400. /**
  401. * Possible flooding by peer was detected in this HTTP/2 session.
  402. * Flooding is measured by how many PING and SETTINGS frames with
  403. * ACK flag set are queued for transmission. These frames are
  404. * response for the peer initiated frames, and peer can cause memory
  405. * exhaustion on server side to send these frames forever and does
  406. * not read network.
  407. */
  408. NGHTTP2_ERR_FLOODED = -904
  409. } nghttp2_error;
  410. /**
  411. * @struct
  412. *
  413. * The object representing single contiguous buffer.
  414. */
  415. typedef struct {
  416. /**
  417. * The pointer to the buffer.
  418. */
  419. uint8_t *base;
  420. /**
  421. * The length of the buffer.
  422. */
  423. size_t len;
  424. } nghttp2_vec;
  425. struct nghttp2_rcbuf;
  426. /**
  427. * @struct
  428. *
  429. * The object representing reference counted buffer. The details of
  430. * this structure are intentionally hidden from the public API.
  431. */
  432. typedef struct nghttp2_rcbuf nghttp2_rcbuf;
  433. /**
  434. * @function
  435. *
  436. * Increments the reference count of |rcbuf| by 1.
  437. */
  438. NGHTTP2_EXTERN void nghttp2_rcbuf_incref(nghttp2_rcbuf *rcbuf);
  439. /**
  440. * @function
  441. *
  442. * Decrements the reference count of |rcbuf| by 1. If the reference
  443. * count becomes zero, the object pointed by |rcbuf| will be freed.
  444. * In this case, application must not use |rcbuf| again.
  445. */
  446. NGHTTP2_EXTERN void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf);
  447. /**
  448. * @function
  449. *
  450. * Returns the underlying buffer managed by |rcbuf|.
  451. */
  452. NGHTTP2_EXTERN nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf);
  453. /**
  454. * @function
  455. *
  456. * Returns nonzero if the underlying buffer is statically allocated,
  457. * and 0 otherwise. This can be useful for language bindings that wish
  458. * to avoid creating duplicate strings for these buffers.
  459. */
  460. NGHTTP2_EXTERN int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf);
  461. /**
  462. * @enum
  463. *
  464. * The flags for header field name/value pair.
  465. */
  466. typedef enum {
  467. /**
  468. * No flag set.
  469. */
  470. NGHTTP2_NV_FLAG_NONE = 0,
  471. /**
  472. * Indicates that this name/value pair must not be indexed ("Literal
  473. * Header Field never Indexed" representation must be used in HPACK
  474. * encoding). Other implementation calls this bit as "sensitive".
  475. */
  476. NGHTTP2_NV_FLAG_NO_INDEX = 0x01,
  477. /**
  478. * This flag is set solely by application. If this flag is set, the
  479. * library does not make a copy of header field name. This could
  480. * improve performance.
  481. */
  482. NGHTTP2_NV_FLAG_NO_COPY_NAME = 0x02,
  483. /**
  484. * This flag is set solely by application. If this flag is set, the
  485. * library does not make a copy of header field value. This could
  486. * improve performance.
  487. */
  488. NGHTTP2_NV_FLAG_NO_COPY_VALUE = 0x04
  489. } nghttp2_nv_flag;
  490. /**
  491. * @struct
  492. *
  493. * The name/value pair, which mainly used to represent header fields.
  494. */
  495. typedef struct {
  496. /**
  497. * The |name| byte string. If this struct is presented from library
  498. * (e.g., :type:`nghttp2_on_frame_recv_callback`), |name| is
  499. * guaranteed to be NULL-terminated. For some callbacks
  500. * (:type:`nghttp2_before_frame_send_callback`,
  501. * :type:`nghttp2_on_frame_send_callback`, and
  502. * :type:`nghttp2_on_frame_not_send_callback`), it may not be
  503. * NULL-terminated if header field is passed from application with
  504. * the flag :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`). When application
  505. * is constructing this struct, |name| is not required to be
  506. * NULL-terminated.
  507. */
  508. uint8_t *name;
  509. /**
  510. * The |value| byte string. If this struct is presented from
  511. * library (e.g., :type:`nghttp2_on_frame_recv_callback`), |value|
  512. * is guaranteed to be NULL-terminated. For some callbacks
  513. * (:type:`nghttp2_before_frame_send_callback`,
  514. * :type:`nghttp2_on_frame_send_callback`, and
  515. * :type:`nghttp2_on_frame_not_send_callback`), it may not be
  516. * NULL-terminated if header field is passed from application with
  517. * the flag :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE`). When
  518. * application is constructing this struct, |value| is not required
  519. * to be NULL-terminated.
  520. */
  521. uint8_t *value;
  522. /**
  523. * The length of the |name|, excluding terminating NULL.
  524. */
  525. size_t namelen;
  526. /**
  527. * The length of the |value|, excluding terminating NULL.
  528. */
  529. size_t valuelen;
  530. /**
  531. * Bitwise OR of one or more of :type:`nghttp2_nv_flag`.
  532. */
  533. uint8_t flags;
  534. } nghttp2_nv;
  535. /**
  536. * @enum
  537. *
  538. * The frame types in HTTP/2 specification.
  539. */
  540. typedef enum {
  541. /**
  542. * The DATA frame.
  543. */
  544. NGHTTP2_DATA = 0,
  545. /**
  546. * The HEADERS frame.
  547. */
  548. NGHTTP2_HEADERS = 0x01,
  549. /**
  550. * The PRIORITY frame.
  551. */
  552. NGHTTP2_PRIORITY = 0x02,
  553. /**
  554. * The RST_STREAM frame.
  555. */
  556. NGHTTP2_RST_STREAM = 0x03,
  557. /**
  558. * The SETTINGS frame.
  559. */
  560. NGHTTP2_SETTINGS = 0x04,
  561. /**
  562. * The PUSH_PROMISE frame.
  563. */
  564. NGHTTP2_PUSH_PROMISE = 0x05,
  565. /**
  566. * The PING frame.
  567. */
  568. NGHTTP2_PING = 0x06,
  569. /**
  570. * The GOAWAY frame.
  571. */
  572. NGHTTP2_GOAWAY = 0x07,
  573. /**
  574. * The WINDOW_UPDATE frame.
  575. */
  576. NGHTTP2_WINDOW_UPDATE = 0x08,
  577. /**
  578. * The CONTINUATION frame. This frame type won't be passed to any
  579. * callbacks because the library processes this frame type and its
  580. * preceding HEADERS/PUSH_PROMISE as a single frame.
  581. */
  582. NGHTTP2_CONTINUATION = 0x09,
  583. /**
  584. * The ALTSVC frame, which is defined in `RFC 7383
  585. * <https://tools.ietf.org/html/rfc7838#section-4>`_.
  586. */
  587. NGHTTP2_ALTSVC = 0x0a,
  588. /**
  589. * The ORIGIN frame, which is defined by `RFC 8336
  590. * <https://tools.ietf.org/html/rfc8336>`_.
  591. */
  592. NGHTTP2_ORIGIN = 0x0c
  593. } nghttp2_frame_type;
  594. /**
  595. * @enum
  596. *
  597. * The flags for HTTP/2 frames. This enum defines all flags for all
  598. * frames.
  599. */
  600. typedef enum {
  601. /**
  602. * No flag set.
  603. */
  604. NGHTTP2_FLAG_NONE = 0,
  605. /**
  606. * The END_STREAM flag.
  607. */
  608. NGHTTP2_FLAG_END_STREAM = 0x01,
  609. /**
  610. * The END_HEADERS flag.
  611. */
  612. NGHTTP2_FLAG_END_HEADERS = 0x04,
  613. /**
  614. * The ACK flag.
  615. */
  616. NGHTTP2_FLAG_ACK = 0x01,
  617. /**
  618. * The PADDED flag.
  619. */
  620. NGHTTP2_FLAG_PADDED = 0x08,
  621. /**
  622. * The PRIORITY flag.
  623. */
  624. NGHTTP2_FLAG_PRIORITY = 0x20
  625. } nghttp2_flag;
  626. /**
  627. * @enum
  628. * The SETTINGS ID.
  629. */
  630. typedef enum {
  631. /**
  632. * SETTINGS_HEADER_TABLE_SIZE
  633. */
  634. NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x01,
  635. /**
  636. * SETTINGS_ENABLE_PUSH
  637. */
  638. NGHTTP2_SETTINGS_ENABLE_PUSH = 0x02,
  639. /**
  640. * SETTINGS_MAX_CONCURRENT_STREAMS
  641. */
  642. NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x03,
  643. /**
  644. * SETTINGS_INITIAL_WINDOW_SIZE
  645. */
  646. NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x04,
  647. /**
  648. * SETTINGS_MAX_FRAME_SIZE
  649. */
  650. NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 0x05,
  651. /**
  652. * SETTINGS_MAX_HEADER_LIST_SIZE
  653. */
  654. NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x06,
  655. /**
  656. * SETTINGS_ENABLE_CONNECT_PROTOCOL
  657. * (`RFC 8441 <https://tools.ietf.org/html/rfc8441>`_)
  658. */
  659. NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x08
  660. } nghttp2_settings_id;
  661. /* Note: If we add SETTINGS, update the capacity of
  662. NGHTTP2_INBOUND_NUM_IV as well */
  663. /**
  664. * @macro
  665. *
  666. * .. warning::
  667. *
  668. * Deprecated. The initial max concurrent streams is 0xffffffffu.
  669. *
  670. * Default maximum number of incoming concurrent streams. Use
  671. * `nghttp2_submit_settings()` with
  672. * :enum:`NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS` to change the
  673. * maximum number of incoming concurrent streams.
  674. *
  675. * .. note::
  676. *
  677. * The maximum number of outgoing concurrent streams is 100 by
  678. * default.
  679. */
  680. #define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1)
  681. /**
  682. * @enum
  683. * The status codes for the RST_STREAM and GOAWAY frames.
  684. */
  685. typedef enum {
  686. /**
  687. * No errors.
  688. */
  689. NGHTTP2_NO_ERROR = 0x00,
  690. /**
  691. * PROTOCOL_ERROR
  692. */
  693. NGHTTP2_PROTOCOL_ERROR = 0x01,
  694. /**
  695. * INTERNAL_ERROR
  696. */
  697. NGHTTP2_INTERNAL_ERROR = 0x02,
  698. /**
  699. * FLOW_CONTROL_ERROR
  700. */
  701. NGHTTP2_FLOW_CONTROL_ERROR = 0x03,
  702. /**
  703. * SETTINGS_TIMEOUT
  704. */
  705. NGHTTP2_SETTINGS_TIMEOUT = 0x04,
  706. /**
  707. * STREAM_CLOSED
  708. */
  709. NGHTTP2_STREAM_CLOSED = 0x05,
  710. /**
  711. * FRAME_SIZE_ERROR
  712. */
  713. NGHTTP2_FRAME_SIZE_ERROR = 0x06,
  714. /**
  715. * REFUSED_STREAM
  716. */
  717. NGHTTP2_REFUSED_STREAM = 0x07,
  718. /**
  719. * CANCEL
  720. */
  721. NGHTTP2_CANCEL = 0x08,
  722. /**
  723. * COMPRESSION_ERROR
  724. */
  725. NGHTTP2_COMPRESSION_ERROR = 0x09,
  726. /**
  727. * CONNECT_ERROR
  728. */
  729. NGHTTP2_CONNECT_ERROR = 0x0a,
  730. /**
  731. * ENHANCE_YOUR_CALM
  732. */
  733. NGHTTP2_ENHANCE_YOUR_CALM = 0x0b,
  734. /**
  735. * INADEQUATE_SECURITY
  736. */
  737. NGHTTP2_INADEQUATE_SECURITY = 0x0c,
  738. /**
  739. * HTTP_1_1_REQUIRED
  740. */
  741. NGHTTP2_HTTP_1_1_REQUIRED = 0x0d
  742. } nghttp2_error_code;
  743. /**
  744. * @struct
  745. * The frame header.
  746. */
  747. typedef struct {
  748. /**
  749. * The length field of this frame, excluding frame header.
  750. */
  751. size_t length;
  752. /**
  753. * The stream identifier (aka, stream ID)
  754. */
  755. int32_t stream_id;
  756. /**
  757. * The type of this frame. See `nghttp2_frame_type`.
  758. */
  759. uint8_t type;
  760. /**
  761. * The flags.
  762. */
  763. uint8_t flags;
  764. /**
  765. * Reserved bit in frame header. Currently, this is always set to 0
  766. * and application should not expect something useful in here.
  767. */
  768. uint8_t reserved;
  769. } nghttp2_frame_hd;
  770. /**
  771. * @union
  772. *
  773. * This union represents the some kind of data source passed to
  774. * :type:`nghttp2_data_source_read_callback`.
  775. */
  776. typedef union {
  777. /**
  778. * The integer field, suitable for a file descriptor.
  779. */
  780. int fd;
  781. /**
  782. * The pointer to an arbitrary object.
  783. */
  784. void *ptr;
  785. } nghttp2_data_source;
  786. /**
  787. * @enum
  788. *
  789. * The flags used to set in |data_flags| output parameter in
  790. * :type:`nghttp2_data_source_read_callback`.
  791. */
  792. typedef enum {
  793. /**
  794. * No flag set.
  795. */
  796. NGHTTP2_DATA_FLAG_NONE = 0,
  797. /**
  798. * Indicates EOF was sensed.
  799. */
  800. NGHTTP2_DATA_FLAG_EOF = 0x01,
  801. /**
  802. * Indicates that END_STREAM flag must not be set even if
  803. * NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send
  804. * trailer fields with `nghttp2_submit_request()` or
  805. * `nghttp2_submit_response()`.
  806. */
  807. NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02,
  808. /**
  809. * Indicates that application will send complete DATA frame in
  810. * :type:`nghttp2_send_data_callback`.
  811. */
  812. NGHTTP2_DATA_FLAG_NO_COPY = 0x04
  813. } nghttp2_data_flag;
  814. /**
  815. * @functypedef
  816. *
  817. * Callback function invoked when the library wants to read data from
  818. * the |source|. The read data is sent in the stream |stream_id|.
  819. * The implementation of this function must read at most |length|
  820. * bytes of data from |source| (or possibly other places) and store
  821. * them in |buf| and return number of data stored in |buf|. If EOF is
  822. * reached, set :enum:`NGHTTP2_DATA_FLAG_EOF` flag in |*data_flags|.
  823. *
  824. * Sometime it is desirable to avoid copying data into |buf| and let
  825. * application to send data directly. To achieve this, set
  826. * :enum:`NGHTTP2_DATA_FLAG_NO_COPY` to |*data_flags| (and possibly
  827. * other flags, just like when we do copy), and return the number of
  828. * bytes to send without copying data into |buf|. The library, seeing
  829. * :enum:`NGHTTP2_DATA_FLAG_NO_COPY`, will invoke
  830. * :type:`nghttp2_send_data_callback`. The application must send
  831. * complete DATA frame in that callback.
  832. *
  833. * If this callback is set by `nghttp2_submit_request()`,
  834. * `nghttp2_submit_response()` or `nghttp2_submit_headers()` and
  835. * `nghttp2_submit_data()` with flag parameter
  836. * :enum:`NGHTTP2_FLAG_END_STREAM` set, and
  837. * :enum:`NGHTTP2_DATA_FLAG_EOF` flag is set to |*data_flags|, DATA
  838. * frame will have END_STREAM flag set. Usually, this is expected
  839. * behaviour and all are fine. One exception is send trailer fields.
  840. * You cannot send trailer fields after sending frame with END_STREAM
  841. * set. To avoid this problem, one can set
  842. * :enum:`NGHTTP2_DATA_FLAG_NO_END_STREAM` along with
  843. * :enum:`NGHTTP2_DATA_FLAG_EOF` to signal the library not to set
  844. * END_STREAM in DATA frame. Then application can use
  845. * `nghttp2_submit_trailer()` to send trailer fields.
  846. * `nghttp2_submit_trailer()` can be called inside this callback.
  847. *
  848. * If the application wants to postpone DATA frames (e.g.,
  849. * asynchronous I/O, or reading data blocks for long time), it is
  850. * achieved by returning :enum:`NGHTTP2_ERR_DEFERRED` without reading
  851. * any data in this invocation. The library removes DATA frame from
  852. * the outgoing queue temporarily. To move back deferred DATA frame
  853. * to outgoing queue, call `nghttp2_session_resume_data()`.
  854. *
  855. * By default, |length| is limited to 16KiB at maximum. If peer
  856. * allows larger frames, application can enlarge transmission buffer
  857. * size. See :type:`nghttp2_data_source_read_length_callback` for
  858. * more details.
  859. *
  860. * If the application just wants to return from
  861. * `nghttp2_session_send()` or `nghttp2_session_mem_send()` without
  862. * sending anything, return :enum:`NGHTTP2_ERR_PAUSE`.
  863. *
  864. * In case of error, there are 2 choices. Returning
  865. * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close the stream
  866. * by issuing RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. If a
  867. * different error code is desirable, use
  868. * `nghttp2_submit_rst_stream()` with a desired error code and then
  869. * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Returning
  870. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session
  871. * failure.
  872. */
  873. typedef ssize_t (*nghttp2_data_source_read_callback)(
  874. nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length,
  875. uint32_t *data_flags, nghttp2_data_source *source, void *user_data);
  876. /**
  877. * @struct
  878. *
  879. * This struct represents the data source and the way to read a chunk
  880. * of data from it.
  881. */
  882. typedef struct {
  883. /**
  884. * The data source.
  885. */
  886. nghttp2_data_source source;
  887. /**
  888. * The callback function to read a chunk of data from the |source|.
  889. */
  890. nghttp2_data_source_read_callback read_callback;
  891. } nghttp2_data_provider;
  892. /**
  893. * @struct
  894. *
  895. * The DATA frame. The received data is delivered via
  896. * :type:`nghttp2_on_data_chunk_recv_callback`.
  897. */
  898. typedef struct {
  899. nghttp2_frame_hd hd;
  900. /**
  901. * The length of the padding in this frame. This includes PAD_HIGH
  902. * and PAD_LOW.
  903. */
  904. size_t padlen;
  905. } nghttp2_data;
  906. /**
  907. * @enum
  908. *
  909. * The category of HEADERS, which indicates the role of the frame. In
  910. * HTTP/2 spec, request, response, push response and other arbitrary
  911. * headers (e.g., trailer fields) are all called just HEADERS. To
  912. * give the application the role of incoming HEADERS frame, we define
  913. * several categories.
  914. */
  915. typedef enum {
  916. /**
  917. * The HEADERS frame is opening new stream, which is analogous to
  918. * SYN_STREAM in SPDY.
  919. */
  920. NGHTTP2_HCAT_REQUEST = 0,
  921. /**
  922. * The HEADERS frame is the first response headers, which is
  923. * analogous to SYN_REPLY in SPDY.
  924. */
  925. NGHTTP2_HCAT_RESPONSE = 1,
  926. /**
  927. * The HEADERS frame is the first headers sent against reserved
  928. * stream.
  929. */
  930. NGHTTP2_HCAT_PUSH_RESPONSE = 2,
  931. /**
  932. * The HEADERS frame which does not apply for the above categories,
  933. * which is analogous to HEADERS in SPDY. If non-final response
  934. * (e.g., status 1xx) is used, final response HEADERS frame will be
  935. * categorized here.
  936. */
  937. NGHTTP2_HCAT_HEADERS = 3
  938. } nghttp2_headers_category;
  939. /**
  940. * @struct
  941. *
  942. * The structure to specify stream dependency.
  943. */
  944. typedef struct {
  945. /**
  946. * The stream ID of the stream to depend on. Specifying 0 makes
  947. * stream not depend any other stream.
  948. */
  949. int32_t stream_id;
  950. /**
  951. * The weight of this dependency.
  952. */
  953. int32_t weight;
  954. /**
  955. * nonzero means exclusive dependency
  956. */
  957. uint8_t exclusive;
  958. } nghttp2_priority_spec;
  959. /**
  960. * @struct
  961. *
  962. * The HEADERS frame. It has the following members:
  963. */
  964. typedef struct {
  965. /**
  966. * The frame header.
  967. */
  968. nghttp2_frame_hd hd;
  969. /**
  970. * The length of the padding in this frame. This includes PAD_HIGH
  971. * and PAD_LOW.
  972. */
  973. size_t padlen;
  974. /**
  975. * The priority specification
  976. */
  977. nghttp2_priority_spec pri_spec;
  978. /**
  979. * The name/value pairs.
  980. */
  981. nghttp2_nv *nva;
  982. /**
  983. * The number of name/value pairs in |nva|.
  984. */
  985. size_t nvlen;
  986. /**
  987. * The category of this HEADERS frame.
  988. */
  989. nghttp2_headers_category cat;
  990. } nghttp2_headers;
  991. /**
  992. * @struct
  993. *
  994. * The PRIORITY frame. It has the following members:
  995. */
  996. typedef struct {
  997. /**
  998. * The frame header.
  999. */
  1000. nghttp2_frame_hd hd;
  1001. /**
  1002. * The priority specification.
  1003. */
  1004. nghttp2_priority_spec pri_spec;
  1005. } nghttp2_priority;
  1006. /**
  1007. * @struct
  1008. *
  1009. * The RST_STREAM frame. It has the following members:
  1010. */
  1011. typedef struct {
  1012. /**
  1013. * The frame header.
  1014. */
  1015. nghttp2_frame_hd hd;
  1016. /**
  1017. * The error code. See :type:`nghttp2_error_code`.
  1018. */
  1019. uint32_t error_code;
  1020. } nghttp2_rst_stream;
  1021. /**
  1022. * @struct
  1023. *
  1024. * The SETTINGS ID/Value pair. It has the following members:
  1025. */
  1026. typedef struct {
  1027. /**
  1028. * The SETTINGS ID. See :type:`nghttp2_settings_id`.
  1029. */
  1030. int32_t settings_id;
  1031. /**
  1032. * The value of this entry.
  1033. */
  1034. uint32_t value;
  1035. } nghttp2_settings_entry;
  1036. /**
  1037. * @struct
  1038. *
  1039. * The SETTINGS frame. It has the following members:
  1040. */
  1041. typedef struct {
  1042. /**
  1043. * The frame header.
  1044. */
  1045. nghttp2_frame_hd hd;
  1046. /**
  1047. * The number of SETTINGS ID/Value pairs in |iv|.
  1048. */
  1049. size_t niv;
  1050. /**
  1051. * The pointer to the array of SETTINGS ID/Value pair.
  1052. */
  1053. nghttp2_settings_entry *iv;
  1054. } nghttp2_settings;
  1055. /**
  1056. * @struct
  1057. *
  1058. * The PUSH_PROMISE frame. It has the following members:
  1059. */
  1060. typedef struct {
  1061. /**
  1062. * The frame header.
  1063. */
  1064. nghttp2_frame_hd hd;
  1065. /**
  1066. * The length of the padding in this frame. This includes PAD_HIGH
  1067. * and PAD_LOW.
  1068. */
  1069. size_t padlen;
  1070. /**
  1071. * The name/value pairs.
  1072. */
  1073. nghttp2_nv *nva;
  1074. /**
  1075. * The number of name/value pairs in |nva|.
  1076. */
  1077. size_t nvlen;
  1078. /**
  1079. * The promised stream ID
  1080. */
  1081. int32_t promised_stream_id;
  1082. /**
  1083. * Reserved bit. Currently this is always set to 0 and application
  1084. * should not expect something useful in here.
  1085. */
  1086. uint8_t reserved;
  1087. } nghttp2_push_promise;
  1088. /**
  1089. * @struct
  1090. *
  1091. * The PING frame. It has the following members:
  1092. */
  1093. typedef struct {
  1094. /**
  1095. * The frame header.
  1096. */
  1097. nghttp2_frame_hd hd;
  1098. /**
  1099. * The opaque data
  1100. */
  1101. uint8_t opaque_data[8];
  1102. } nghttp2_ping;
  1103. /**
  1104. * @struct
  1105. *
  1106. * The GOAWAY frame. It has the following members:
  1107. */
  1108. typedef struct {
  1109. /**
  1110. * The frame header.
  1111. */
  1112. nghttp2_frame_hd hd;
  1113. /**
  1114. * The last stream stream ID.
  1115. */
  1116. int32_t last_stream_id;
  1117. /**
  1118. * The error code. See :type:`nghttp2_error_code`.
  1119. */
  1120. uint32_t error_code;
  1121. /**
  1122. * The additional debug data
  1123. */
  1124. uint8_t *opaque_data;
  1125. /**
  1126. * The length of |opaque_data| member.
  1127. */
  1128. size_t opaque_data_len;
  1129. /**
  1130. * Reserved bit. Currently this is always set to 0 and application
  1131. * should not expect something useful in here.
  1132. */
  1133. uint8_t reserved;
  1134. } nghttp2_goaway;
  1135. /**
  1136. * @struct
  1137. *
  1138. * The WINDOW_UPDATE frame. It has the following members:
  1139. */
  1140. typedef struct {
  1141. /**
  1142. * The frame header.
  1143. */
  1144. nghttp2_frame_hd hd;
  1145. /**
  1146. * The window size increment.
  1147. */
  1148. int32_t window_size_increment;
  1149. /**
  1150. * Reserved bit. Currently this is always set to 0 and application
  1151. * should not expect something useful in here.
  1152. */
  1153. uint8_t reserved;
  1154. } nghttp2_window_update;
  1155. /**
  1156. * @struct
  1157. *
  1158. * The extension frame. It has following members:
  1159. */
  1160. typedef struct {
  1161. /**
  1162. * The frame header.
  1163. */
  1164. nghttp2_frame_hd hd;
  1165. /**
  1166. * The pointer to extension payload. The exact pointer type is
  1167. * determined by hd.type.
  1168. *
  1169. * Currently, no extension is supported. This is a place holder for
  1170. * the future extensions.
  1171. */
  1172. void *payload;
  1173. } nghttp2_extension;
  1174. /**
  1175. * @union
  1176. *
  1177. * This union includes all frames to pass them to various function
  1178. * calls as nghttp2_frame type. The CONTINUATION frame is omitted
  1179. * from here because the library deals with it internally.
  1180. */
  1181. typedef union {
  1182. /**
  1183. * The frame header, which is convenient to inspect frame header.
  1184. */
  1185. nghttp2_frame_hd hd;
  1186. /**
  1187. * The DATA frame.
  1188. */
  1189. nghttp2_data data;
  1190. /**
  1191. * The HEADERS frame.
  1192. */
  1193. nghttp2_headers headers;
  1194. /**
  1195. * The PRIORITY frame.
  1196. */
  1197. nghttp2_priority priority;
  1198. /**
  1199. * The RST_STREAM frame.
  1200. */
  1201. nghttp2_rst_stream rst_stream;
  1202. /**
  1203. * The SETTINGS frame.
  1204. */
  1205. nghttp2_settings settings;
  1206. /**
  1207. * The PUSH_PROMISE frame.
  1208. */
  1209. nghttp2_push_promise push_promise;
  1210. /**
  1211. * The PING frame.
  1212. */
  1213. nghttp2_ping ping;
  1214. /**
  1215. * The GOAWAY frame.
  1216. */
  1217. nghttp2_goaway goaway;
  1218. /**
  1219. * The WINDOW_UPDATE frame.
  1220. */
  1221. nghttp2_window_update window_update;
  1222. /**
  1223. * The extension frame.
  1224. */
  1225. nghttp2_extension ext;
  1226. } nghttp2_frame;
  1227. /**
  1228. * @functypedef
  1229. *
  1230. * Callback function invoked when |session| wants to send data to the
  1231. * remote peer. The implementation of this function must send at most
  1232. * |length| bytes of data stored in |data|. The |flags| is currently
  1233. * not used and always 0. It must return the number of bytes sent if
  1234. * it succeeds. If it cannot send any single byte without blocking,
  1235. * it must return :enum:`NGHTTP2_ERR_WOULDBLOCK`. For other errors,
  1236. * it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. The
  1237. * |user_data| pointer is the third argument passed in to the call to
  1238. * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
  1239. *
  1240. * This callback is required if the application uses
  1241. * `nghttp2_session_send()` to send data to the remote endpoint. If
  1242. * the application uses solely `nghttp2_session_mem_send()` instead,
  1243. * this callback function is unnecessary.
  1244. *
  1245. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1246. * `nghttp2_session_callbacks_set_send_callback()`.
  1247. *
  1248. * .. note::
  1249. *
  1250. * The |length| may be very small. If that is the case, and
  1251. * application disables Nagle algorithm (``TCP_NODELAY``), then just
  1252. * writing |data| to the network stack leads to very small packet,
  1253. * and it is very inefficient. An application should be responsible
  1254. * to buffer up small chunks of data as necessary to avoid this
  1255. * situation.
  1256. */
  1257. typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session,
  1258. const uint8_t *data, size_t length,
  1259. int flags, void *user_data);
  1260. /**
  1261. * @functypedef
  1262. *
  1263. * Callback function invoked when :enum:`NGHTTP2_DATA_FLAG_NO_COPY` is
  1264. * used in :type:`nghttp2_data_source_read_callback` to send complete
  1265. * DATA frame.
  1266. *
  1267. * The |frame| is a DATA frame to send. The |framehd| is the
  1268. * serialized frame header (9 bytes). The |length| is the length of
  1269. * application data to send (this does not include padding). The
  1270. * |source| is the same pointer passed to
  1271. * :type:`nghttp2_data_source_read_callback`.
  1272. *
  1273. * The application first must send frame header |framehd| of length 9
  1274. * bytes. If ``frame->data.padlen > 0``, send 1 byte of value
  1275. * ``frame->data.padlen - 1``. Then send exactly |length| bytes of
  1276. * application data. Finally, if ``frame->data.padlen > 1``, send
  1277. * ``frame->data.padlen - 1`` bytes of zero as padding.
  1278. *
  1279. * The application has to send complete DATA frame in this callback.
  1280. * If all data were written successfully, return 0.
  1281. *
  1282. * If it cannot send any data at all, just return
  1283. * :enum:`NGHTTP2_ERR_WOULDBLOCK`; the library will call this callback
  1284. * with the same parameters later (It is recommended to send complete
  1285. * DATA frame at once in this function to deal with error; if partial
  1286. * frame data has already sent, it is impossible to send another data
  1287. * in that state, and all we can do is tear down connection). When
  1288. * data is fully processed, but application wants to make
  1289. * `nghttp2_session_mem_send()` or `nghttp2_session_send()` return
  1290. * immediately without processing next frames, return
  1291. * :enum:`NGHTTP2_ERR_PAUSE`. If application decided to reset this
  1292. * stream, return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`, then
  1293. * the library will send RST_STREAM with INTERNAL_ERROR as error code.
  1294. * The application can also return
  1295. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`, which will result in
  1296. * connection closure. Returning any other value is treated as
  1297. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned.
  1298. */
  1299. typedef int (*nghttp2_send_data_callback)(nghttp2_session *session,
  1300. nghttp2_frame *frame,
  1301. const uint8_t *framehd, size_t length,
  1302. nghttp2_data_source *source,
  1303. void *user_data);
  1304. /**
  1305. * @functypedef
  1306. *
  1307. * Callback function invoked when |session| wants to receive data from
  1308. * the remote peer. The implementation of this function must read at
  1309. * most |length| bytes of data and store it in |buf|. The |flags| is
  1310. * currently not used and always 0. It must return the number of
  1311. * bytes written in |buf| if it succeeds. If it cannot read any
  1312. * single byte without blocking, it must return
  1313. * :enum:`NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF before it reads any
  1314. * single byte, it must return :enum:`NGHTTP2_ERR_EOF`. For other
  1315. * errors, it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1316. * Returning 0 is treated as :enum:`NGHTTP2_ERR_WOULDBLOCK`. The
  1317. * |user_data| pointer is the third argument passed in to the call to
  1318. * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
  1319. *
  1320. * This callback is required if the application uses
  1321. * `nghttp2_session_recv()` to receive data from the remote endpoint.
  1322. * If the application uses solely `nghttp2_session_mem_recv()`
  1323. * instead, this callback function is unnecessary.
  1324. *
  1325. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1326. * `nghttp2_session_callbacks_set_recv_callback()`.
  1327. */
  1328. typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf,
  1329. size_t length, int flags,
  1330. void *user_data);
  1331. /**
  1332. * @functypedef
  1333. *
  1334. * Callback function invoked by `nghttp2_session_recv()` and
  1335. * `nghttp2_session_mem_recv()` when a frame is received. The
  1336. * |user_data| pointer is the third argument passed in to the call to
  1337. * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
  1338. *
  1339. * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``
  1340. * member of their data structure are always ``NULL`` and 0
  1341. * respectively. The header name/value pairs are emitted via
  1342. * :type:`nghttp2_on_header_callback`.
  1343. *
  1344. * For HEADERS, PUSH_PROMISE and DATA frames, this callback may be
  1345. * called after stream is closed (see
  1346. * :type:`nghttp2_on_stream_close_callback`). The application should
  1347. * check that stream is still alive using its own stream management or
  1348. * :func:`nghttp2_session_get_stream_user_data()`.
  1349. *
  1350. * Only HEADERS and DATA frame can signal the end of incoming data.
  1351. * If ``frame->hd.flags & NGHTTP2_FLAG_END_STREAM`` is nonzero, the
  1352. * |frame| is the last frame from the remote peer in this stream.
  1353. *
  1354. * This callback won't be called for CONTINUATION frames.
  1355. * HEADERS/PUSH_PROMISE + CONTINUATIONs are treated as single frame.
  1356. *
  1357. * The implementation of this function must return 0 if it succeeds.
  1358. * If nonzero value is returned, it is treated as fatal error and
  1359. * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
  1360. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1361. *
  1362. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1363. * `nghttp2_session_callbacks_set_on_frame_recv_callback()`.
  1364. */
  1365. typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session,
  1366. const nghttp2_frame *frame,
  1367. void *user_data);
  1368. /**
  1369. * @functypedef
  1370. *
  1371. * Callback function invoked by `nghttp2_session_recv()` and
  1372. * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is
  1373. * received. The error is indicated by the |lib_error_code|, which is
  1374. * one of the values defined in :type:`nghttp2_error`. When this
  1375. * callback function is invoked, the library automatically submits
  1376. * either RST_STREAM or GOAWAY frame. The |user_data| pointer is the
  1377. * third argument passed in to the call to
  1378. * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
  1379. *
  1380. * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``
  1381. * member of their data structure are always ``NULL`` and 0
  1382. * respectively.
  1383. *
  1384. * The implementation of this function must return 0 if it succeeds.
  1385. * If nonzero is returned, it is treated as fatal error and
  1386. * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
  1387. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1388. *
  1389. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1390. * `nghttp2_session_callbacks_set_on_invalid_frame_recv_callback()`.
  1391. */
  1392. typedef int (*nghttp2_on_invalid_frame_recv_callback)(
  1393. nghttp2_session *session, const nghttp2_frame *frame, int lib_error_code,
  1394. void *user_data);
  1395. /**
  1396. * @functypedef
  1397. *
  1398. * Callback function invoked when a chunk of data in DATA frame is
  1399. * received. The |stream_id| is the stream ID this DATA frame belongs
  1400. * to. The |flags| is the flags of DATA frame which this data chunk
  1401. * is contained. ``(flags & NGHTTP2_FLAG_END_STREAM) != 0`` does not
  1402. * necessarily mean this chunk of data is the last one in the stream.
  1403. * You should use :type:`nghttp2_on_frame_recv_callback` to know all
  1404. * data frames are received. The |user_data| pointer is the third
  1405. * argument passed in to the call to `nghttp2_session_client_new()` or
  1406. * `nghttp2_session_server_new()`.
  1407. *
  1408. * If the application uses `nghttp2_session_mem_recv()`, it can return
  1409. * :enum:`NGHTTP2_ERR_PAUSE` to make `nghttp2_session_mem_recv()`
  1410. * return without processing further input bytes. The memory by
  1411. * pointed by the |data| is retained until
  1412. * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called.
  1413. * The application must retain the input bytes which was used to
  1414. * produce the |data| parameter, because it may refer to the memory
  1415. * region included in the input bytes.
  1416. *
  1417. * The implementation of this function must return 0 if it succeeds.
  1418. * If nonzero is returned, it is treated as fatal error, and
  1419. * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
  1420. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1421. *
  1422. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1423. * `nghttp2_session_callbacks_set_on_data_chunk_recv_callback()`.
  1424. */
  1425. typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session,
  1426. uint8_t flags,
  1427. int32_t stream_id,
  1428. const uint8_t *data,
  1429. size_t len, void *user_data);
  1430. /**
  1431. * @functypedef
  1432. *
  1433. * Callback function invoked just before the non-DATA frame |frame| is
  1434. * sent. The |user_data| pointer is the third argument passed in to
  1435. * the call to `nghttp2_session_client_new()` or
  1436. * `nghttp2_session_server_new()`.
  1437. *
  1438. * The implementation of this function must return 0 if it succeeds.
  1439. * It can also return :enum:`NGHTTP2_ERR_CANCEL` to cancel the
  1440. * transmission of the given frame.
  1441. *
  1442. * If there is a fatal error while executing this callback, the
  1443. * implementation should return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`,
  1444. * which makes `nghttp2_session_send()` and
  1445. * `nghttp2_session_mem_send()` functions immediately return
  1446. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1447. *
  1448. * If the other value is returned, it is treated as if
  1449. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned. But the
  1450. * implementation should not rely on this since the library may define
  1451. * new return value to extend its capability.
  1452. *
  1453. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1454. * `nghttp2_session_callbacks_set_before_frame_send_callback()`.
  1455. */
  1456. typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session,
  1457. const nghttp2_frame *frame,
  1458. void *user_data);
  1459. /**
  1460. * @functypedef
  1461. *
  1462. * Callback function invoked after the frame |frame| is sent. The
  1463. * |user_data| pointer is the third argument passed in to the call to
  1464. * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
  1465. *
  1466. * The implementation of this function must return 0 if it succeeds.
  1467. * If nonzero is returned, it is treated as fatal error and
  1468. * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
  1469. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1470. *
  1471. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1472. * `nghttp2_session_callbacks_set_on_frame_send_callback()`.
  1473. */
  1474. typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session,
  1475. const nghttp2_frame *frame,
  1476. void *user_data);
  1477. /**
  1478. * @functypedef
  1479. *
  1480. * Callback function invoked after the non-DATA frame |frame| is not
  1481. * sent because of the error. The error is indicated by the
  1482. * |lib_error_code|, which is one of the values defined in
  1483. * :type:`nghttp2_error`. The |user_data| pointer is the third
  1484. * argument passed in to the call to `nghttp2_session_client_new()` or
  1485. * `nghttp2_session_server_new()`.
  1486. *
  1487. * The implementation of this function must return 0 if it succeeds.
  1488. * If nonzero is returned, it is treated as fatal error and
  1489. * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
  1490. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1491. *
  1492. * `nghttp2_session_get_stream_user_data()` can be used to get
  1493. * associated data.
  1494. *
  1495. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1496. * `nghttp2_session_callbacks_set_on_frame_not_send_callback()`.
  1497. */
  1498. typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session,
  1499. const nghttp2_frame *frame,
  1500. int lib_error_code,
  1501. void *user_data);
  1502. /**
  1503. * @functypedef
  1504. *
  1505. * Callback function invoked when the stream |stream_id| is closed.
  1506. * The reason of closure is indicated by the |error_code|. The
  1507. * |error_code| is usually one of :enum:`nghttp2_error_code`, but that
  1508. * is not guaranteed. The stream_user_data, which was specified in
  1509. * `nghttp2_submit_request()` or `nghttp2_submit_headers()`, is still
  1510. * available in this function. The |user_data| pointer is the third
  1511. * argument passed in to the call to `nghttp2_session_client_new()` or
  1512. * `nghttp2_session_server_new()`.
  1513. *
  1514. * This function is also called for a stream in reserved state.
  1515. *
  1516. * The implementation of this function must return 0 if it succeeds.
  1517. * If nonzero is returned, it is treated as fatal error and
  1518. * `nghttp2_session_recv()`, `nghttp2_session_mem_recv()`,
  1519. * `nghttp2_session_send()`, and `nghttp2_session_mem_send()`
  1520. * functions immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1521. *
  1522. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1523. * `nghttp2_session_callbacks_set_on_stream_close_callback()`.
  1524. */
  1525. typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session,
  1526. int32_t stream_id,
  1527. uint32_t error_code,
  1528. void *user_data);
  1529. /**
  1530. * @functypedef
  1531. *
  1532. * Callback function invoked when the reception of header block in
  1533. * HEADERS or PUSH_PROMISE is started. Each header name/value pair
  1534. * will be emitted by :type:`nghttp2_on_header_callback`.
  1535. *
  1536. * The ``frame->hd.flags`` may not have
  1537. * :enum:`NGHTTP2_FLAG_END_HEADERS` flag set, which indicates that one
  1538. * or more CONTINUATION frames are involved. But the application does
  1539. * not need to care about that because the header name/value pairs are
  1540. * emitted transparently regardless of CONTINUATION frames.
  1541. *
  1542. * The server applications probably create an object to store
  1543. * information about new stream if ``frame->hd.type ==
  1544. * NGHTTP2_HEADERS`` and ``frame->headers.cat ==
  1545. * NGHTTP2_HCAT_REQUEST``. If |session| is configured as server side,
  1546. * ``frame->headers.cat`` is either ``NGHTTP2_HCAT_REQUEST``
  1547. * containing request headers or ``NGHTTP2_HCAT_HEADERS`` containing
  1548. * trailer fields and never get PUSH_PROMISE in this callback.
  1549. *
  1550. * For the client applications, ``frame->hd.type`` is either
  1551. * ``NGHTTP2_HEADERS`` or ``NGHTTP2_PUSH_PROMISE``. In case of
  1552. * ``NGHTTP2_HEADERS``, ``frame->headers.cat ==
  1553. * NGHTTP2_HCAT_RESPONSE`` means that it is the first response
  1554. * headers, but it may be non-final response which is indicated by 1xx
  1555. * status code. In this case, there may be zero or more HEADERS frame
  1556. * with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` which has
  1557. * non-final response code and finally client gets exactly one HEADERS
  1558. * frame with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS``
  1559. * containing final response headers (non-1xx status code). The
  1560. * trailer fields also has ``frame->headers.cat ==
  1561. * NGHTTP2_HCAT_HEADERS`` which does not contain any status code.
  1562. *
  1563. * Returning :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close
  1564. * the stream (promised stream if frame is PUSH_PROMISE) by issuing
  1565. * RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. In this case,
  1566. * :type:`nghttp2_on_header_callback` and
  1567. * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a
  1568. * different error code is desirable, use
  1569. * `nghttp2_submit_rst_stream()` with a desired error code and then
  1570. * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Again, use
  1571. * ``frame->push_promise.promised_stream_id`` as stream_id parameter
  1572. * in `nghttp2_submit_rst_stream()` if frame is PUSH_PROMISE.
  1573. *
  1574. * The implementation of this function must return 0 if it succeeds.
  1575. * It can return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` to
  1576. * reset the stream (promised stream if frame is PUSH_PROMISE). For
  1577. * critical errors, it must return
  1578. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the other value is
  1579. * returned, it is treated as if :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
  1580. * is returned. If :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned,
  1581. * `nghttp2_session_mem_recv()` function will immediately return
  1582. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1583. *
  1584. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1585. * `nghttp2_session_callbacks_set_on_begin_headers_callback()`.
  1586. */
  1587. typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session,
  1588. const nghttp2_frame *frame,
  1589. void *user_data);
  1590. /**
  1591. * @functypedef
  1592. *
  1593. * Callback function invoked when a header name/value pair is received
  1594. * for the |frame|. The |name| of length |namelen| is header name.
  1595. * The |value| of length |valuelen| is header value. The |flags| is
  1596. * bitwise OR of one or more of :type:`nghttp2_nv_flag`.
  1597. *
  1598. * If :enum:`NGHTTP2_NV_FLAG_NO_INDEX` is set in |flags|, the receiver
  1599. * must not index this name/value pair when forwarding it to the next
  1600. * hop. More specifically, "Literal Header Field never Indexed"
  1601. * representation must be used in HPACK encoding.
  1602. *
  1603. * When this callback is invoked, ``frame->hd.type`` is either
  1604. * :enum:`NGHTTP2_HEADERS` or :enum:`NGHTTP2_PUSH_PROMISE`. After all
  1605. * header name/value pairs are processed with this callback, and no
  1606. * error has been detected, :type:`nghttp2_on_frame_recv_callback`
  1607. * will be invoked. If there is an error in decompression,
  1608. * :type:`nghttp2_on_frame_recv_callback` for the |frame| will not be
  1609. * invoked.
  1610. *
  1611. * Both |name| and |value| are guaranteed to be NULL-terminated. The
  1612. * |namelen| and |valuelen| do not include terminal NULL. If
  1613. * `nghttp2_option_set_no_http_messaging()` is used with nonzero
  1614. * value, NULL character may be included in |name| or |value| before
  1615. * terminating NULL.
  1616. *
  1617. * Please note that unless `nghttp2_option_set_no_http_messaging()` is
  1618. * used, nghttp2 library does perform validation against the |name|
  1619. * and the |value| using `nghttp2_check_header_name()` and
  1620. * `nghttp2_check_header_value()`. In addition to this, nghttp2
  1621. * performs validation based on HTTP Messaging rule, which is briefly
  1622. * explained in :ref:`http-messaging` section.
  1623. *
  1624. * If the application uses `nghttp2_session_mem_recv()`, it can return
  1625. * :enum:`NGHTTP2_ERR_PAUSE` to make `nghttp2_session_mem_recv()`
  1626. * return without processing further input bytes. The memory pointed
  1627. * by |frame|, |name| and |value| parameters are retained until
  1628. * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called.
  1629. * The application must retain the input bytes which was used to
  1630. * produce these parameters, because it may refer to the memory region
  1631. * included in the input bytes.
  1632. *
  1633. * Returning :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close
  1634. * the stream (promised stream if frame is PUSH_PROMISE) by issuing
  1635. * RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. In this case,
  1636. * :type:`nghttp2_on_header_callback` and
  1637. * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a
  1638. * different error code is desirable, use
  1639. * `nghttp2_submit_rst_stream()` with a desired error code and then
  1640. * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Again, use
  1641. * ``frame->push_promise.promised_stream_id`` as stream_id parameter
  1642. * in `nghttp2_submit_rst_stream()` if frame is PUSH_PROMISE.
  1643. *
  1644. * The implementation of this function must return 0 if it succeeds.
  1645. * It may return :enum:`NGHTTP2_ERR_PAUSE` or
  1646. * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. For other critical
  1647. * failures, it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If
  1648. * the other nonzero value is returned, it is treated as
  1649. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If
  1650. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned,
  1651. * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
  1652. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1653. *
  1654. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1655. * `nghttp2_session_callbacks_set_on_header_callback()`.
  1656. *
  1657. * .. warning::
  1658. *
  1659. * Application should properly limit the total buffer size to store
  1660. * incoming header fields. Without it, peer may send large number
  1661. * of header fields or large header fields to cause out of memory in
  1662. * local endpoint. Due to how HPACK works, peer can do this
  1663. * effectively without using much memory on their own.
  1664. */
  1665. typedef int (*nghttp2_on_header_callback)(nghttp2_session *session,
  1666. const nghttp2_frame *frame,
  1667. const uint8_t *name, size_t namelen,
  1668. const uint8_t *value, size_t valuelen,
  1669. uint8_t flags, void *user_data);
  1670. /**
  1671. * @functypedef
  1672. *
  1673. * Callback function invoked when a header name/value pair is received
  1674. * for the |frame|. The |name| is header name. The |value| is header
  1675. * value. The |flags| is bitwise OR of one or more of
  1676. * :type:`nghttp2_nv_flag`.
  1677. *
  1678. * This callback behaves like :type:`nghttp2_on_header_callback`,
  1679. * except that |name| and |value| are stored in reference counted
  1680. * buffer. If application wishes to keep these references without
  1681. * copying them, use `nghttp2_rcbuf_incref()` to increment their
  1682. * reference count. It is the application's responsibility to call
  1683. * `nghttp2_rcbuf_decref()` if they called `nghttp2_rcbuf_incref()` so
  1684. * as not to leak memory. If the |session| is created by
  1685. * `nghttp2_session_server_new3()` or `nghttp2_session_client_new3()`,
  1686. * the function to free memory is the one belongs to the mem
  1687. * parameter. As long as this free function alives, |name| and
  1688. * |value| can live after |session| was destroyed.
  1689. */
  1690. typedef int (*nghttp2_on_header_callback2)(nghttp2_session *session,
  1691. const nghttp2_frame *frame,
  1692. nghttp2_rcbuf *name,
  1693. nghttp2_rcbuf *value, uint8_t flags,
  1694. void *user_data);
  1695. /**
  1696. * @functypedef
  1697. *
  1698. * Callback function invoked when a invalid header name/value pair is
  1699. * received for the |frame|.
  1700. *
  1701. * The parameter and behaviour are similar to
  1702. * :type:`nghttp2_on_header_callback`. The difference is that this
  1703. * callback is only invoked when a invalid header name/value pair is
  1704. * received which is treated as stream error if this callback is not
  1705. * set. Only invalid regular header field are passed to this
  1706. * callback. In other words, invalid pseudo header field is not
  1707. * passed to this callback. Also header fields which includes upper
  1708. * cased latter are also treated as error without passing them to this
  1709. * callback.
  1710. *
  1711. * This callback is only considered if HTTP messaging validation is
  1712. * turned on (which is on by default, see
  1713. * `nghttp2_option_set_no_http_messaging()`).
  1714. *
  1715. * With this callback, application inspects the incoming invalid
  1716. * field, and it also can reset stream from this callback by returning
  1717. * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By default, the
  1718. * error code is :enum:`NGHTTP2_PROTOCOL_ERROR`. To change the error
  1719. * code, call `nghttp2_submit_rst_stream()` with the error code of
  1720. * choice in addition to returning
  1721. * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
  1722. *
  1723. * If 0 is returned, the header field is ignored, and the stream is
  1724. * not reset.
  1725. */
  1726. typedef int (*nghttp2_on_invalid_header_callback)(
  1727. nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name,
  1728. size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags,
  1729. void *user_data);
  1730. /**
  1731. * @functypedef
  1732. *
  1733. * Callback function invoked when a invalid header name/value pair is
  1734. * received for the |frame|.
  1735. *
  1736. * The parameter and behaviour are similar to
  1737. * :type:`nghttp2_on_header_callback2`. The difference is that this
  1738. * callback is only invoked when a invalid header name/value pair is
  1739. * received which is silently ignored if this callback is not set.
  1740. * Only invalid regular header field are passed to this callback. In
  1741. * other words, invalid pseudo header field is not passed to this
  1742. * callback. Also header fields which includes upper cased latter are
  1743. * also treated as error without passing them to this callback.
  1744. *
  1745. * This callback is only considered if HTTP messaging validation is
  1746. * turned on (which is on by default, see
  1747. * `nghttp2_option_set_no_http_messaging()`).
  1748. *
  1749. * With this callback, application inspects the incoming invalid
  1750. * field, and it also can reset stream from this callback by returning
  1751. * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By default, the
  1752. * error code is :enum:`NGHTTP2_INTERNAL_ERROR`. To change the error
  1753. * code, call `nghttp2_submit_rst_stream()` with the error code of
  1754. * choice in addition to returning
  1755. * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
  1756. */
  1757. typedef int (*nghttp2_on_invalid_header_callback2)(
  1758. nghttp2_session *session, const nghttp2_frame *frame, nghttp2_rcbuf *name,
  1759. nghttp2_rcbuf *value, uint8_t flags, void *user_data);
  1760. /**
  1761. * @functypedef
  1762. *
  1763. * Callback function invoked when the library asks application how
  1764. * many padding bytes are required for the transmission of the
  1765. * |frame|. The application must choose the total length of payload
  1766. * including padded bytes in range [frame->hd.length, max_payloadlen],
  1767. * inclusive. Choosing number not in this range will be treated as
  1768. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. Returning
  1769. * ``frame->hd.length`` means no padding is added. Returning
  1770. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will make
  1771. * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
  1772. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1773. *
  1774. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1775. * `nghttp2_session_callbacks_set_select_padding_callback()`.
  1776. */
  1777. typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session,
  1778. const nghttp2_frame *frame,
  1779. size_t max_payloadlen,
  1780. void *user_data);
  1781. /**
  1782. * @functypedef
  1783. *
  1784. * Callback function invoked when library wants to get max length of
  1785. * data to send data to the remote peer. The implementation of this
  1786. * function should return a value in the following range. [1,
  1787. * min(|session_remote_window_size|, |stream_remote_window_size|,
  1788. * |remote_max_frame_size|)]. If a value greater than this range is
  1789. * returned than the max allow value will be used. Returning a value
  1790. * smaller than this range is treated as
  1791. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. The |frame_type| is provided
  1792. * for future extensibility and identifies the type of frame (see
  1793. * :type:`nghttp2_frame_type`) for which to get the length for.
  1794. * Currently supported frame types are: :enum:`NGHTTP2_DATA`.
  1795. *
  1796. * This callback can be used to control the length in bytes for which
  1797. * :type:`nghttp2_data_source_read_callback` is allowed to send to the
  1798. * remote endpoint. This callback is optional. Returning
  1799. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session
  1800. * failure.
  1801. *
  1802. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1803. * `nghttp2_session_callbacks_set_data_source_read_length_callback()`.
  1804. */
  1805. typedef ssize_t (*nghttp2_data_source_read_length_callback)(
  1806. nghttp2_session *session, uint8_t frame_type, int32_t stream_id,
  1807. int32_t session_remote_window_size, int32_t stream_remote_window_size,
  1808. uint32_t remote_max_frame_size, void *user_data);
  1809. /**
  1810. * @functypedef
  1811. *
  1812. * Callback function invoked when a frame header is received. The
  1813. * |hd| points to received frame header.
  1814. *
  1815. * Unlike :type:`nghttp2_on_frame_recv_callback`, this callback will
  1816. * also be called when frame header of CONTINUATION frame is received.
  1817. *
  1818. * If both :type:`nghttp2_on_begin_frame_callback` and
  1819. * :type:`nghttp2_on_begin_headers_callback` are set and HEADERS or
  1820. * PUSH_PROMISE is received, :type:`nghttp2_on_begin_frame_callback`
  1821. * will be called first.
  1822. *
  1823. * The implementation of this function must return 0 if it succeeds.
  1824. * If nonzero value is returned, it is treated as fatal error and
  1825. * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
  1826. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1827. *
  1828. * To set this callback to :type:`nghttp2_session_callbacks`, use
  1829. * `nghttp2_session_callbacks_set_on_begin_frame_callback()`.
  1830. */
  1831. typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session,
  1832. const nghttp2_frame_hd *hd,
  1833. void *user_data);
  1834. /**
  1835. * @functypedef
  1836. *
  1837. * Callback function invoked when chunk of extension frame payload is
  1838. * received. The |hd| points to frame header. The received
  1839. * chunk is |data| of length |len|.
  1840. *
  1841. * The implementation of this function must return 0 if it succeeds.
  1842. *
  1843. * To abort processing this extension frame, return
  1844. * :enum:`NGHTTP2_ERR_CANCEL`.
  1845. *
  1846. * If fatal error occurred, application should return
  1847. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
  1848. * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
  1849. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the
  1850. * other values are returned, currently they are treated as
  1851. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1852. */
  1853. typedef int (*nghttp2_on_extension_chunk_recv_callback)(
  1854. nghttp2_session *session, const nghttp2_frame_hd *hd, const uint8_t *data,
  1855. size_t len, void *user_data);
  1856. /**
  1857. * @functypedef
  1858. *
  1859. * Callback function invoked when library asks the application to
  1860. * unpack extension payload from its wire format. The extension
  1861. * payload has been passed to the application using
  1862. * :type:`nghttp2_on_extension_chunk_recv_callback`. The frame header
  1863. * is already unpacked by the library and provided as |hd|.
  1864. *
  1865. * To receive extension frames, the application must tell desired
  1866. * extension frame type to the library using
  1867. * `nghttp2_option_set_user_recv_extension_type()`.
  1868. *
  1869. * The implementation of this function may store the pointer to the
  1870. * created object as a result of unpacking in |*payload|, and returns
  1871. * 0. The pointer stored in |*payload| is opaque to the library, and
  1872. * the library does not own its pointer. |*payload| is initialized as
  1873. * ``NULL``. The |*payload| is available as ``frame->ext.payload`` in
  1874. * :type:`nghttp2_on_frame_recv_callback`. Therefore if application
  1875. * can free that memory inside :type:`nghttp2_on_frame_recv_callback`
  1876. * callback. Of course, application has a liberty not ot use
  1877. * |*payload|, and do its own mechanism to process extension frames.
  1878. *
  1879. * To abort processing this extension frame, return
  1880. * :enum:`NGHTTP2_ERR_CANCEL`.
  1881. *
  1882. * If fatal error occurred, application should return
  1883. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
  1884. * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
  1885. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the
  1886. * other values are returned, currently they are treated as
  1887. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1888. */
  1889. typedef int (*nghttp2_unpack_extension_callback)(nghttp2_session *session,
  1890. void **payload,
  1891. const nghttp2_frame_hd *hd,
  1892. void *user_data);
  1893. /**
  1894. * @functypedef
  1895. *
  1896. * Callback function invoked when library asks the application to pack
  1897. * extension payload in its wire format. The frame header will be
  1898. * packed by library. Application must pack payload only.
  1899. * ``frame->ext.payload`` is the object passed to
  1900. * `nghttp2_submit_extension()` as payload parameter. Application
  1901. * must pack extension payload to the |buf| of its capacity |len|
  1902. * bytes. The |len| is at least 16KiB.
  1903. *
  1904. * The implementation of this function should return the number of
  1905. * bytes written into |buf| when it succeeds.
  1906. *
  1907. * To abort processing this extension frame, return
  1908. * :enum:`NGHTTP2_ERR_CANCEL`, and
  1909. * :type:`nghttp2_on_frame_not_send_callback` will be invoked.
  1910. *
  1911. * If fatal error occurred, application should return
  1912. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
  1913. * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
  1914. * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the
  1915. * other values are returned, currently they are treated as
  1916. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the return value is
  1917. * strictly larger than |len|, it is treated as
  1918. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
  1919. */
  1920. typedef ssize_t (*nghttp2_pack_extension_callback)(nghttp2_session *session,
  1921. uint8_t *buf, size_t len,
  1922. const nghttp2_frame *frame,
  1923. void *user_data);
  1924. /**
  1925. * @functypedef
  1926. *
  1927. * Callback function invoked when library provides the error message
  1928. * intended for human consumption. This callback is solely for
  1929. * debugging purpose. The |msg| is typically NULL-terminated string
  1930. * of length |len|. |len| does not include the sentinel NULL
  1931. * character.
  1932. *
  1933. * This function is deprecated. The new application should use
  1934. * :type:`nghttp2_error_callback2`.
  1935. *
  1936. * The format of error message may change between nghttp2 library
  1937. * versions. The application should not depend on the particular
  1938. * format.
  1939. *
  1940. * Normally, application should return 0 from this callback. If fatal
  1941. * error occurred while doing something in this callback, application
  1942. * should return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
  1943. * library will return immediately with return value
  1944. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if nonzero value
  1945. * is returned from this callback, they are treated as
  1946. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`, but application should not
  1947. * rely on this details.
  1948. */
  1949. typedef int (*nghttp2_error_callback)(nghttp2_session *session, const char *msg,
  1950. size_t len, void *user_data);
  1951. /**
  1952. * @functypedef
  1953. *
  1954. * Callback function invoked when library provides the error code, and
  1955. * message. This callback is solely for debugging purpose.
  1956. * |lib_error_code| is one of error code defined in
  1957. * :enum:`nghttp2_error`. The |msg| is typically NULL-terminated
  1958. * string of length |len|, and intended for human consumption. |len|
  1959. * does not include the sentinel NULL character.
  1960. *
  1961. * The format of error message may change between nghttp2 library
  1962. * versions. The application should not depend on the particular
  1963. * format.
  1964. *
  1965. * Normally, application should return 0 from this callback. If fatal
  1966. * error occurred while doing something in this callback, application
  1967. * should return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
  1968. * library will return immediately with return value
  1969. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if nonzero value
  1970. * is returned from this callback, they are treated as
  1971. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`, but application should not
  1972. * rely on this details.
  1973. */
  1974. typedef int (*nghttp2_error_callback2)(nghttp2_session *session,
  1975. int lib_error_code, const char *msg,
  1976. size_t len, void *user_data);
  1977. struct nghttp2_session_callbacks;
  1978. /**
  1979. * @struct
  1980. *
  1981. * Callback functions for :type:`nghttp2_session`. The details of
  1982. * this structure are intentionally hidden from the public API.
  1983. */
  1984. typedef struct nghttp2_session_callbacks nghttp2_session_callbacks;
  1985. /**
  1986. * @function
  1987. *
  1988. * Initializes |*callbacks_ptr| with NULL values.
  1989. *
  1990. * The initialized object can be used when initializing multiple
  1991. * :type:`nghttp2_session` objects.
  1992. *
  1993. * When the application finished using this object, it can use
  1994. * `nghttp2_session_callbacks_del()` to free its memory.
  1995. *
  1996. * This function returns 0 if it succeeds, or one of the following
  1997. * negative error codes:
  1998. *
  1999. * :enum:`NGHTTP2_ERR_NOMEM`
  2000. * Out of memory.
  2001. */
  2002. NGHTTP2_EXTERN int
  2003. nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr);
  2004. /**
  2005. * @function
  2006. *
  2007. * Frees any resources allocated for |callbacks|. If |callbacks| is
  2008. * ``NULL``, this function does nothing.
  2009. */
  2010. NGHTTP2_EXTERN void
  2011. nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks);
  2012. /**
  2013. * @function
  2014. *
  2015. * Sets callback function invoked when a session wants to send data to
  2016. * the remote peer. This callback is not necessary if the application
  2017. * uses solely `nghttp2_session_mem_send()` to serialize data to
  2018. * transmit.
  2019. */
  2020. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback(
  2021. nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback);
  2022. /**
  2023. * @function
  2024. *
  2025. * Sets callback function invoked when the a session wants to receive
  2026. * data from the remote peer. This callback is not necessary if the
  2027. * application uses solely `nghttp2_session_mem_recv()` to process
  2028. * received data.
  2029. */
  2030. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback(
  2031. nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback);
  2032. /**
  2033. * @function
  2034. *
  2035. * Sets callback function invoked by `nghttp2_session_recv()` and
  2036. * `nghttp2_session_mem_recv()` when a frame is received.
  2037. */
  2038. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback(
  2039. nghttp2_session_callbacks *cbs,
  2040. nghttp2_on_frame_recv_callback on_frame_recv_callback);
  2041. /**
  2042. * @function
  2043. *
  2044. * Sets callback function invoked by `nghttp2_session_recv()` and
  2045. * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is
  2046. * received.
  2047. */
  2048. NGHTTP2_EXTERN void
  2049. nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(
  2050. nghttp2_session_callbacks *cbs,
  2051. nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback);
  2052. /**
  2053. * @function
  2054. *
  2055. * Sets callback function invoked when a chunk of data in DATA frame
  2056. * is received.
  2057. */
  2058. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_data_chunk_recv_callback(
  2059. nghttp2_session_callbacks *cbs,
  2060. nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback);
  2061. /**
  2062. * @function
  2063. *
  2064. * Sets callback function invoked before a non-DATA frame is sent.
  2065. */
  2066. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_before_frame_send_callback(
  2067. nghttp2_session_callbacks *cbs,
  2068. nghttp2_before_frame_send_callback before_frame_send_callback);
  2069. /**
  2070. * @function
  2071. *
  2072. * Sets callback function invoked after a frame is sent.
  2073. */
  2074. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_send_callback(
  2075. nghttp2_session_callbacks *cbs,
  2076. nghttp2_on_frame_send_callback on_frame_send_callback);
  2077. /**
  2078. * @function
  2079. *
  2080. * Sets callback function invoked when a non-DATA frame is not sent
  2081. * because of an error.
  2082. */
  2083. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_not_send_callback(
  2084. nghttp2_session_callbacks *cbs,
  2085. nghttp2_on_frame_not_send_callback on_frame_not_send_callback);
  2086. /**
  2087. * @function
  2088. *
  2089. * Sets callback function invoked when the stream is closed.
  2090. */
  2091. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_stream_close_callback(
  2092. nghttp2_session_callbacks *cbs,
  2093. nghttp2_on_stream_close_callback on_stream_close_callback);
  2094. /**
  2095. * @function
  2096. *
  2097. * Sets callback function invoked when the reception of header block
  2098. * in HEADERS or PUSH_PROMISE is started.
  2099. */
  2100. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_headers_callback(
  2101. nghttp2_session_callbacks *cbs,
  2102. nghttp2_on_begin_headers_callback on_begin_headers_callback);
  2103. /**
  2104. * @function
  2105. *
  2106. * Sets callback function invoked when a header name/value pair is
  2107. * received. If both
  2108. * `nghttp2_session_callbacks_set_on_header_callback()` and
  2109. * `nghttp2_session_callbacks_set_on_header_callback2()` are used to
  2110. * set callbacks, the latter has the precedence.
  2111. */
  2112. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback(
  2113. nghttp2_session_callbacks *cbs,
  2114. nghttp2_on_header_callback on_header_callback);
  2115. /**
  2116. * @function
  2117. *
  2118. * Sets callback function invoked when a header name/value pair is
  2119. * received.
  2120. */
  2121. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback2(
  2122. nghttp2_session_callbacks *cbs,
  2123. nghttp2_on_header_callback2 on_header_callback2);
  2124. /**
  2125. * @function
  2126. *
  2127. * Sets callback function invoked when a invalid header name/value
  2128. * pair is received. If both
  2129. * `nghttp2_session_callbacks_set_on_invalid_header_callback()` and
  2130. * `nghttp2_session_callbacks_set_on_invalid_header_callback2()` are
  2131. * used to set callbacks, the latter takes the precedence.
  2132. */
  2133. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback(
  2134. nghttp2_session_callbacks *cbs,
  2135. nghttp2_on_invalid_header_callback on_invalid_header_callback);
  2136. /**
  2137. * @function
  2138. *
  2139. * Sets callback function invoked when a invalid header name/value
  2140. * pair is received.
  2141. */
  2142. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback2(
  2143. nghttp2_session_callbacks *cbs,
  2144. nghttp2_on_invalid_header_callback2 on_invalid_header_callback2);
  2145. /**
  2146. * @function
  2147. *
  2148. * Sets callback function invoked when the library asks application
  2149. * how many padding bytes are required for the transmission of the
  2150. * given frame.
  2151. */
  2152. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback(
  2153. nghttp2_session_callbacks *cbs,
  2154. nghttp2_select_padding_callback select_padding_callback);
  2155. /**
  2156. * @function
  2157. *
  2158. * Sets callback function determine the length allowed in
  2159. * :type:`nghttp2_data_source_read_callback`.
  2160. */
  2161. NGHTTP2_EXTERN void
  2162. nghttp2_session_callbacks_set_data_source_read_length_callback(
  2163. nghttp2_session_callbacks *cbs,
  2164. nghttp2_data_source_read_length_callback data_source_read_length_callback);
  2165. /**
  2166. * @function
  2167. *
  2168. * Sets callback function invoked when a frame header is received.
  2169. */
  2170. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback(
  2171. nghttp2_session_callbacks *cbs,
  2172. nghttp2_on_begin_frame_callback on_begin_frame_callback);
  2173. /**
  2174. * @function
  2175. *
  2176. * Sets callback function invoked when
  2177. * :enum:`NGHTTP2_DATA_FLAG_NO_COPY` is used in
  2178. * :type:`nghttp2_data_source_read_callback` to avoid data copy.
  2179. */
  2180. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback(
  2181. nghttp2_session_callbacks *cbs,
  2182. nghttp2_send_data_callback send_data_callback);
  2183. /**
  2184. * @function
  2185. *
  2186. * Sets callback function invoked when the library asks the
  2187. * application to pack extension frame payload in wire format.
  2188. */
  2189. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback(
  2190. nghttp2_session_callbacks *cbs,
  2191. nghttp2_pack_extension_callback pack_extension_callback);
  2192. /**
  2193. * @function
  2194. *
  2195. * Sets callback function invoked when the library asks the
  2196. * application to unpack extension frame payload from wire format.
  2197. */
  2198. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_unpack_extension_callback(
  2199. nghttp2_session_callbacks *cbs,
  2200. nghttp2_unpack_extension_callback unpack_extension_callback);
  2201. /**
  2202. * @function
  2203. *
  2204. * Sets callback function invoked when chunk of extension frame
  2205. * payload is received.
  2206. */
  2207. NGHTTP2_EXTERN void
  2208. nghttp2_session_callbacks_set_on_extension_chunk_recv_callback(
  2209. nghttp2_session_callbacks *cbs,
  2210. nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback);
  2211. /**
  2212. * @function
  2213. *
  2214. * Sets callback function invoked when library tells error message to
  2215. * the application.
  2216. *
  2217. * This function is deprecated. The new application should use
  2218. * `nghttp2_session_callbacks_set_error_callback2()`.
  2219. *
  2220. * If both :type:`nghttp2_error_callback` and
  2221. * :type:`nghttp2_error_callback2` are set, the latter takes
  2222. * precedence.
  2223. */
  2224. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback(
  2225. nghttp2_session_callbacks *cbs, nghttp2_error_callback error_callback);
  2226. /**
  2227. * @function
  2228. *
  2229. * Sets callback function invoked when library tells error code, and
  2230. * message to the application.
  2231. *
  2232. * If both :type:`nghttp2_error_callback` and
  2233. * :type:`nghttp2_error_callback2` are set, the latter takes
  2234. * precedence.
  2235. */
  2236. NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback2(
  2237. nghttp2_session_callbacks *cbs, nghttp2_error_callback2 error_callback2);
  2238. /**
  2239. * @functypedef
  2240. *
  2241. * Custom memory allocator to replace malloc(). The |mem_user_data|
  2242. * is the mem_user_data member of :type:`nghttp2_mem` structure.
  2243. */
  2244. typedef void *(*nghttp2_malloc)(size_t size, void *mem_user_data);
  2245. /**
  2246. * @functypedef
  2247. *
  2248. * Custom memory allocator to replace free(). The |mem_user_data| is
  2249. * the mem_user_data member of :type:`nghttp2_mem` structure.
  2250. */
  2251. typedef void (*nghttp2_free)(void *ptr, void *mem_user_data);
  2252. /**
  2253. * @functypedef
  2254. *
  2255. * Custom memory allocator to replace calloc(). The |mem_user_data|
  2256. * is the mem_user_data member of :type:`nghttp2_mem` structure.
  2257. */
  2258. typedef void *(*nghttp2_calloc)(size_t nmemb, size_t size, void *mem_user_data);
  2259. /**
  2260. * @functypedef
  2261. *
  2262. * Custom memory allocator to replace realloc(). The |mem_user_data|
  2263. * is the mem_user_data member of :type:`nghttp2_mem` structure.
  2264. */
  2265. typedef void *(*nghttp2_realloc)(void *ptr, size_t size, void *mem_user_data);
  2266. /**
  2267. * @struct
  2268. *
  2269. * Custom memory allocator functions and user defined pointer. The
  2270. * |mem_user_data| member is passed to each allocator function. This
  2271. * can be used, for example, to achieve per-session memory pool.
  2272. *
  2273. * In the following example code, ``my_malloc``, ``my_free``,
  2274. * ``my_calloc`` and ``my_realloc`` are the replacement of the
  2275. * standard allocators ``malloc``, ``free``, ``calloc`` and
  2276. * ``realloc`` respectively::
  2277. *
  2278. * void *my_malloc_cb(size_t size, void *mem_user_data) {
  2279. * return my_malloc(size);
  2280. * }
  2281. *
  2282. * void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); }
  2283. *
  2284. * void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) {
  2285. * return my_calloc(nmemb, size);
  2286. * }
  2287. *
  2288. * void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) {
  2289. * return my_realloc(ptr, size);
  2290. * }
  2291. *
  2292. * void session_new() {
  2293. * nghttp2_session *session;
  2294. * nghttp2_session_callbacks *callbacks;
  2295. * nghttp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb,
  2296. * my_realloc_cb};
  2297. *
  2298. * ...
  2299. *
  2300. * nghttp2_session_client_new3(&session, callbacks, NULL, NULL, &mem);
  2301. *
  2302. * ...
  2303. * }
  2304. */
  2305. typedef struct {
  2306. /**
  2307. * An arbitrary user supplied data. This is passed to each
  2308. * allocator function.
  2309. */
  2310. void *mem_user_data;
  2311. /**
  2312. * Custom allocator function to replace malloc().
  2313. */
  2314. nghttp2_malloc malloc;
  2315. /**
  2316. * Custom allocator function to replace free().
  2317. */
  2318. nghttp2_free free;
  2319. /**
  2320. * Custom allocator function to replace calloc().
  2321. */
  2322. nghttp2_calloc calloc;
  2323. /**
  2324. * Custom allocator function to replace realloc().
  2325. */
  2326. nghttp2_realloc realloc;
  2327. } nghttp2_mem;
  2328. struct nghttp2_option;
  2329. /**
  2330. * @struct
  2331. *
  2332. * Configuration options for :type:`nghttp2_session`. The details of
  2333. * this structure are intentionally hidden from the public API.
  2334. */
  2335. typedef struct nghttp2_option nghttp2_option;
  2336. /**
  2337. * @function
  2338. *
  2339. * Initializes |*option_ptr| with default values.
  2340. *
  2341. * When the application finished using this object, it can use
  2342. * `nghttp2_option_del()` to free its memory.
  2343. *
  2344. * This function returns 0 if it succeeds, or one of the following
  2345. * negative error codes:
  2346. *
  2347. * :enum:`NGHTTP2_ERR_NOMEM`
  2348. * Out of memory.
  2349. */
  2350. NGHTTP2_EXTERN int nghttp2_option_new(nghttp2_option **option_ptr);
  2351. /**
  2352. * @function
  2353. *
  2354. * Frees any resources allocated for |option|. If |option| is
  2355. * ``NULL``, this function does nothing.
  2356. */
  2357. NGHTTP2_EXTERN void nghttp2_option_del(nghttp2_option *option);
  2358. /**
  2359. * @function
  2360. *
  2361. * This option prevents the library from sending WINDOW_UPDATE for a
  2362. * connection automatically. If this option is set to nonzero, the
  2363. * library won't send WINDOW_UPDATE for DATA until application calls
  2364. * `nghttp2_session_consume()` to indicate the consumed amount of
  2365. * data. Don't use `nghttp2_submit_window_update()` for this purpose.
  2366. * By default, this option is set to zero.
  2367. */
  2368. NGHTTP2_EXTERN void
  2369. nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val);
  2370. /**
  2371. * @function
  2372. *
  2373. * This option sets the SETTINGS_MAX_CONCURRENT_STREAMS value of
  2374. * remote endpoint as if it is received in SETTINGS frame. Without
  2375. * specifying this option, the maximum number of outgoing concurrent
  2376. * streams is initially limited to 100 to avoid issues when the local
  2377. * endpoint submits lots of requests before receiving initial SETTINGS
  2378. * frame from the remote endpoint, since sending them at once to the
  2379. * remote endpoint could lead to rejection of some of the requests.
  2380. * This value will be overwritten when the local endpoint receives
  2381. * initial SETTINGS frame from the remote endpoint, either to the
  2382. * value advertised in SETTINGS_MAX_CONCURRENT_STREAMS or to the
  2383. * default value (unlimited) if none was advertised.
  2384. */
  2385. NGHTTP2_EXTERN void
  2386. nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option,
  2387. uint32_t val);
  2388. /**
  2389. * @function
  2390. *
  2391. * By default, nghttp2 library, if configured as server, requires
  2392. * first 24 bytes of client magic byte string (MAGIC). In most cases,
  2393. * this will simplify the implementation of server. But sometimes
  2394. * server may want to detect the application protocol based on first
  2395. * few bytes on clear text communication.
  2396. *
  2397. * If this option is used with nonzero |val|, nghttp2 library does not
  2398. * handle MAGIC. It still checks following SETTINGS frame. This
  2399. * means that applications should deal with MAGIC by themselves.
  2400. *
  2401. * If this option is not used or used with zero value, if MAGIC does
  2402. * not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()`
  2403. * and `nghttp2_session_mem_recv()` will return error
  2404. * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal error.
  2405. */
  2406. NGHTTP2_EXTERN void
  2407. nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val);
  2408. /**
  2409. * @function
  2410. *
  2411. * By default, nghttp2 library enforces subset of HTTP Messaging rules
  2412. * described in `HTTP/2 specification, section 8
  2413. * <https://tools.ietf.org/html/rfc7540#section-8>`_. See
  2414. * :ref:`http-messaging` section for details. For those applications
  2415. * who use nghttp2 library as non-HTTP use, give nonzero to |val| to
  2416. * disable this enforcement. Please note that disabling this feature
  2417. * does not change the fundamental client and server model of HTTP.
  2418. * That is, even if the validation is disabled, only client can send
  2419. * requests.
  2420. */
  2421. NGHTTP2_EXTERN void nghttp2_option_set_no_http_messaging(nghttp2_option *option,
  2422. int val);
  2423. /**
  2424. * @function
  2425. *
  2426. * RFC 7540 does not enforce any limit on the number of incoming
  2427. * reserved streams (in RFC 7540 terms, streams in reserved (remote)
  2428. * state). This only affects client side, since only server can push
  2429. * streams. Malicious server can push arbitrary number of streams,
  2430. * and make client's memory exhausted. This option can set the
  2431. * maximum number of such incoming streams to avoid possible memory
  2432. * exhaustion. If this option is set, and pushed streams are
  2433. * automatically closed on reception, without calling user provided
  2434. * callback, if they exceed the given limit. The default value is
  2435. * 200. If session is configured as server side, this option has no
  2436. * effect. Server can control the number of streams to push.
  2437. */
  2438. NGHTTP2_EXTERN void
  2439. nghttp2_option_set_max_reserved_remote_streams(nghttp2_option *option,
  2440. uint32_t val);
  2441. /**
  2442. * @function
  2443. *
  2444. * Sets extension frame type the application is willing to handle with
  2445. * user defined callbacks (see
  2446. * :type:`nghttp2_on_extension_chunk_recv_callback` and
  2447. * :type:`nghttp2_unpack_extension_callback`). The |type| is
  2448. * extension frame type, and must be strictly greater than 0x9.
  2449. * Otherwise, this function does nothing. The application can call
  2450. * this function multiple times to set more than one frame type to
  2451. * receive. The application does not have to call this function if it
  2452. * just sends extension frames.
  2453. */
  2454. NGHTTP2_EXTERN void
  2455. nghttp2_option_set_user_recv_extension_type(nghttp2_option *option,
  2456. uint8_t type);
  2457. /**
  2458. * @function
  2459. *
  2460. * Sets extension frame type the application is willing to receive
  2461. * using builtin handler. The |type| is the extension frame type to
  2462. * receive, and must be strictly greater than 0x9. Otherwise, this
  2463. * function does nothing. The application can call this function
  2464. * multiple times to set more than one frame type to receive. The
  2465. * application does not have to call this function if it just sends
  2466. * extension frames.
  2467. *
  2468. * If same frame type is passed to both
  2469. * `nghttp2_option_set_builtin_recv_extension_type()` and
  2470. * `nghttp2_option_set_user_recv_extension_type()`, the latter takes
  2471. * precedence.
  2472. */
  2473. NGHTTP2_EXTERN void
  2474. nghttp2_option_set_builtin_recv_extension_type(nghttp2_option *option,
  2475. uint8_t type);
  2476. /**
  2477. * @function
  2478. *
  2479. * This option prevents the library from sending PING frame with ACK
  2480. * flag set automatically when PING frame without ACK flag set is
  2481. * received. If this option is set to nonzero, the library won't send
  2482. * PING frame with ACK flag set in the response for incoming PING
  2483. * frame. The application can send PING frame with ACK flag set using
  2484. * `nghttp2_submit_ping()` with :enum:`NGHTTP2_FLAG_ACK` as flags
  2485. * parameter.
  2486. */
  2487. NGHTTP2_EXTERN void nghttp2_option_set_no_auto_ping_ack(nghttp2_option *option,
  2488. int val);
  2489. /**
  2490. * @function
  2491. *
  2492. * This option sets the maximum length of header block (a set of
  2493. * header fields per one HEADERS frame) to send. The length of a
  2494. * given set of header fields is calculated using
  2495. * `nghttp2_hd_deflate_bound()`. The default value is 64KiB. If
  2496. * application attempts to send header fields larger than this limit,
  2497. * the transmission of the frame fails with error code
  2498. * :enum:`NGHTTP2_ERR_FRAME_SIZE_ERROR`.
  2499. */
  2500. NGHTTP2_EXTERN void
  2501. nghttp2_option_set_max_send_header_block_length(nghttp2_option *option,
  2502. size_t val);
  2503. /**
  2504. * @function
  2505. *
  2506. * This option sets the maximum dynamic table size for deflating
  2507. * header fields. The default value is 4KiB. In HTTP/2, receiver of
  2508. * deflated header block can specify maximum dynamic table size. The
  2509. * actual maximum size is the minimum of the size receiver specified
  2510. * and this option value.
  2511. */
  2512. NGHTTP2_EXTERN void
  2513. nghttp2_option_set_max_deflate_dynamic_table_size(nghttp2_option *option,
  2514. size_t val);
  2515. /**
  2516. * @function
  2517. *
  2518. * This option prevents the library from retaining closed streams to
  2519. * maintain the priority tree. If this option is set to nonzero,
  2520. * applications can discard closed stream completely to save memory.
  2521. */
  2522. NGHTTP2_EXTERN void nghttp2_option_set_no_closed_streams(nghttp2_option *option,
  2523. int val);
  2524. /**
  2525. * @function
  2526. *
  2527. * This function sets the maximum number of outgoing SETTINGS ACK and
  2528. * PING ACK frames retained in :type:`nghttp2_session` object. If
  2529. * more than those frames are retained, the peer is considered to be
  2530. * misbehaving and session will be closed. The default value is 1000.
  2531. */
  2532. NGHTTP2_EXTERN void nghttp2_option_set_max_outbound_ack(nghttp2_option *option,
  2533. size_t val);
  2534. /**
  2535. * @function
  2536. *
  2537. * Initializes |*session_ptr| for client use. The all members of
  2538. * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|
  2539. * does not store |callbacks|. The |user_data| is an arbitrary user
  2540. * supplied data, which will be passed to the callback functions.
  2541. *
  2542. * The :type:`nghttp2_send_callback` must be specified. If the
  2543. * application code uses `nghttp2_session_recv()`, the
  2544. * :type:`nghttp2_recv_callback` must be specified. The other members
  2545. * of |callbacks| can be ``NULL``.
  2546. *
  2547. * If this function fails, |*session_ptr| is left untouched.
  2548. *
  2549. * This function returns 0 if it succeeds, or one of the following
  2550. * negative error codes:
  2551. *
  2552. * :enum:`NGHTTP2_ERR_NOMEM`
  2553. * Out of memory.
  2554. */
  2555. NGHTTP2_EXTERN int
  2556. nghttp2_session_client_new(nghttp2_session **session_ptr,
  2557. const nghttp2_session_callbacks *callbacks,
  2558. void *user_data);
  2559. /**
  2560. * @function
  2561. *
  2562. * Initializes |*session_ptr| for server use. The all members of
  2563. * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|
  2564. * does not store |callbacks|. The |user_data| is an arbitrary user
  2565. * supplied data, which will be passed to the callback functions.
  2566. *
  2567. * The :type:`nghttp2_send_callback` must be specified. If the
  2568. * application code uses `nghttp2_session_recv()`, the
  2569. * :type:`nghttp2_recv_callback` must be specified. The other members
  2570. * of |callbacks| can be ``NULL``.
  2571. *
  2572. * If this function fails, |*session_ptr| is left untouched.
  2573. *
  2574. * This function returns 0 if it succeeds, or one of the following
  2575. * negative error codes:
  2576. *
  2577. * :enum:`NGHTTP2_ERR_NOMEM`
  2578. * Out of memory.
  2579. */
  2580. NGHTTP2_EXTERN int
  2581. nghttp2_session_server_new(nghttp2_session **session_ptr,
  2582. const nghttp2_session_callbacks *callbacks,
  2583. void *user_data);
  2584. /**
  2585. * @function
  2586. *
  2587. * Like `nghttp2_session_client_new()`, but with additional options
  2588. * specified in the |option|.
  2589. *
  2590. * The |option| can be ``NULL`` and the call is equivalent to
  2591. * `nghttp2_session_client_new()`.
  2592. *
  2593. * This function does not take ownership |option|. The application is
  2594. * responsible for freeing |option| if it finishes using the object.
  2595. *
  2596. * The library code does not refer to |option| after this function
  2597. * returns.
  2598. *
  2599. * This function returns 0 if it succeeds, or one of the following
  2600. * negative error codes:
  2601. *
  2602. * :enum:`NGHTTP2_ERR_NOMEM`
  2603. * Out of memory.
  2604. */
  2605. NGHTTP2_EXTERN int
  2606. nghttp2_session_client_new2(nghttp2_session **session_ptr,
  2607. const nghttp2_session_callbacks *callbacks,
  2608. void *user_data, const nghttp2_option *option);
  2609. /**
  2610. * @function
  2611. *
  2612. * Like `nghttp2_session_server_new()`, but with additional options
  2613. * specified in the |option|.
  2614. *
  2615. * The |option| can be ``NULL`` and the call is equivalent to
  2616. * `nghttp2_session_server_new()`.
  2617. *
  2618. * This function does not take ownership |option|. The application is
  2619. * responsible for freeing |option| if it finishes using the object.
  2620. *
  2621. * The library code does not refer to |option| after this function
  2622. * returns.
  2623. *
  2624. * This function returns 0 if it succeeds, or one of the following
  2625. * negative error codes:
  2626. *
  2627. * :enum:`NGHTTP2_ERR_NOMEM`
  2628. * Out of memory.
  2629. */
  2630. NGHTTP2_EXTERN int
  2631. nghttp2_session_server_new2(nghttp2_session **session_ptr,
  2632. const nghttp2_session_callbacks *callbacks,
  2633. void *user_data, const nghttp2_option *option);
  2634. /**
  2635. * @function
  2636. *
  2637. * Like `nghttp2_session_client_new2()`, but with additional custom
  2638. * memory allocator specified in the |mem|.
  2639. *
  2640. * The |mem| can be ``NULL`` and the call is equivalent to
  2641. * `nghttp2_session_client_new2()`.
  2642. *
  2643. * This function does not take ownership |mem|. The application is
  2644. * responsible for freeing |mem|.
  2645. *
  2646. * The library code does not refer to |mem| pointer after this
  2647. * function returns, so the application can safely free it.
  2648. *
  2649. * This function returns 0 if it succeeds, or one of the following
  2650. * negative error codes:
  2651. *
  2652. * :enum:`NGHTTP2_ERR_NOMEM`
  2653. * Out of memory.
  2654. */
  2655. NGHTTP2_EXTERN int nghttp2_session_client_new3(
  2656. nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
  2657. void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
  2658. /**
  2659. * @function
  2660. *
  2661. * Like `nghttp2_session_server_new2()`, but with additional custom
  2662. * memory allocator specified in the |mem|.
  2663. *
  2664. * The |mem| can be ``NULL`` and the call is equivalent to
  2665. * `nghttp2_session_server_new2()`.
  2666. *
  2667. * This function does not take ownership |mem|. The application is
  2668. * responsible for freeing |mem|.
  2669. *
  2670. * The library code does not refer to |mem| pointer after this
  2671. * function returns, so the application can safely free it.
  2672. *
  2673. * This function returns 0 if it succeeds, or one of the following
  2674. * negative error codes:
  2675. *
  2676. * :enum:`NGHTTP2_ERR_NOMEM`
  2677. * Out of memory.
  2678. */
  2679. NGHTTP2_EXTERN int nghttp2_session_server_new3(
  2680. nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
  2681. void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
  2682. /**
  2683. * @function
  2684. *
  2685. * Frees any resources allocated for |session|. If |session| is
  2686. * ``NULL``, this function does nothing.
  2687. */
  2688. NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session);
  2689. /**
  2690. * @function
  2691. *
  2692. * Sends pending frames to the remote peer.
  2693. *
  2694. * This function retrieves the highest prioritized frame from the
  2695. * outbound queue and sends it to the remote peer. It does this as
  2696. * many as possible until the user callback
  2697. * :type:`nghttp2_send_callback` returns
  2698. * :enum:`NGHTTP2_ERR_WOULDBLOCK` or the outbound queue becomes empty.
  2699. * This function calls several callback functions which are passed
  2700. * when initializing the |session|. Here is the simple time chart
  2701. * which tells when each callback is invoked:
  2702. *
  2703. * 1. Get the next frame to send from outbound queue.
  2704. *
  2705. * 2. Prepare transmission of the frame.
  2706. *
  2707. * 3. If the control frame cannot be sent because some preconditions
  2708. * are not met (e.g., request HEADERS cannot be sent after GOAWAY),
  2709. * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort
  2710. * the following steps.
  2711. *
  2712. * 4. If the frame is HEADERS, PUSH_PROMISE or DATA,
  2713. * :type:`nghttp2_select_padding_callback` is invoked.
  2714. *
  2715. * 5. If the frame is request HEADERS, the stream is opened here.
  2716. *
  2717. * 6. :type:`nghttp2_before_frame_send_callback` is invoked.
  2718. *
  2719. * 7. If :enum:`NGHTTP2_ERR_CANCEL` is returned from
  2720. * :type:`nghttp2_before_frame_send_callback`, the current frame
  2721. * transmission is canceled, and
  2722. * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort
  2723. * the following steps.
  2724. *
  2725. * 8. :type:`nghttp2_send_callback` is invoked one or more times to
  2726. * send the frame.
  2727. *
  2728. * 9. :type:`nghttp2_on_frame_send_callback` is invoked.
  2729. *
  2730. * 10. If the transmission of the frame triggers closure of the
  2731. * stream, the stream is closed and
  2732. * :type:`nghttp2_on_stream_close_callback` is invoked.
  2733. *
  2734. * This function returns 0 if it succeeds, or one of the following
  2735. * negative error codes:
  2736. *
  2737. * :enum:`NGHTTP2_ERR_NOMEM`
  2738. * Out of memory.
  2739. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
  2740. * The callback function failed.
  2741. */
  2742. NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session);
  2743. /**
  2744. * @function
  2745. *
  2746. * Returns the serialized data to send.
  2747. *
  2748. * This function behaves like `nghttp2_session_send()` except that it
  2749. * does not use :type:`nghttp2_send_callback` to transmit data.
  2750. * Instead, it assigns the pointer to the serialized data to the
  2751. * |*data_ptr| and returns its length. The other callbacks are called
  2752. * in the same way as they are in `nghttp2_session_send()`.
  2753. *
  2754. * If no data is available to send, this function returns 0.
  2755. *
  2756. * This function may not return all serialized data in one invocation.
  2757. * To get all data, call this function repeatedly until it returns 0
  2758. * or one of negative error codes.
  2759. *
  2760. * The assigned |*data_ptr| is valid until the next call of
  2761. * `nghttp2_session_mem_send()` or `nghttp2_session_send()`.
  2762. *
  2763. * The caller must send all data before sending the next chunk of
  2764. * data.
  2765. *
  2766. * This function returns the length of the data pointed by the
  2767. * |*data_ptr| if it succeeds, or one of the following negative error
  2768. * codes:
  2769. *
  2770. * :enum:`NGHTTP2_ERR_NOMEM`
  2771. * Out of memory.
  2772. *
  2773. * .. note::
  2774. *
  2775. * This function may produce very small byte string. If that is the
  2776. * case, and application disables Nagle algorithm (``TCP_NODELAY``),
  2777. * then writing this small chunk leads to very small packet, and it
  2778. * is very inefficient. An application should be responsible to
  2779. * buffer up small chunks of data as necessary to avoid this
  2780. * situation.
  2781. */
  2782. NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session,
  2783. const uint8_t **data_ptr);
  2784. /**
  2785. * @function
  2786. *
  2787. * Receives frames from the remote peer.
  2788. *
  2789. * This function receives as many frames as possible until the user
  2790. * callback :type:`nghttp2_recv_callback` returns
  2791. * :enum:`NGHTTP2_ERR_WOULDBLOCK`. This function calls several
  2792. * callback functions which are passed when initializing the
  2793. * |session|. Here is the simple time chart which tells when each
  2794. * callback is invoked:
  2795. *
  2796. * 1. :type:`nghttp2_recv_callback` is invoked one or more times to
  2797. * receive frame header.
  2798. *
  2799. * 2. When frame header is received,
  2800. * :type:`nghttp2_on_begin_frame_callback` is invoked.
  2801. *
  2802. * 3. If the frame is DATA frame:
  2803. *
  2804. * 1. :type:`nghttp2_recv_callback` is invoked to receive DATA
  2805. * payload. For each chunk of data,
  2806. * :type:`nghttp2_on_data_chunk_recv_callback` is invoked.
  2807. *
  2808. * 2. If one DATA frame is completely received,
  2809. * :type:`nghttp2_on_frame_recv_callback` is invoked. If the
  2810. * reception of the frame triggers the closure of the stream,
  2811. * :type:`nghttp2_on_stream_close_callback` is invoked.
  2812. *
  2813. * 4. If the frame is the control frame:
  2814. *
  2815. * 1. :type:`nghttp2_recv_callback` is invoked one or more times to
  2816. * receive whole frame.
  2817. *
  2818. * 2. If the received frame is valid, then following actions are
  2819. * taken. If the frame is either HEADERS or PUSH_PROMISE,
  2820. * :type:`nghttp2_on_begin_headers_callback` is invoked. Then
  2821. * :type:`nghttp2_on_header_callback` is invoked for each header
  2822. * name/value pair. For invalid header field,
  2823. * :type:`nghttp2_on_invalid_header_callback` is called. After
  2824. * all name/value pairs are emitted successfully,
  2825. * :type:`nghttp2_on_frame_recv_callback` is invoked. For other
  2826. * frames, :type:`nghttp2_on_frame_recv_callback` is invoked.
  2827. * If the reception of the frame triggers the closure of the
  2828. * stream, :type:`nghttp2_on_stream_close_callback` is invoked.
  2829. *
  2830. * 3. If the received frame is unpacked but is interpreted as
  2831. * invalid, :type:`nghttp2_on_invalid_frame_recv_callback` is
  2832. * invoked.
  2833. *
  2834. * This function returns 0 if it succeeds, or one of the following
  2835. * negative error codes:
  2836. *
  2837. * :enum:`NGHTTP2_ERR_EOF`
  2838. * The remote peer did shutdown on the connection.
  2839. * :enum:`NGHTTP2_ERR_NOMEM`
  2840. * Out of memory.
  2841. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
  2842. * The callback function failed.
  2843. * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`
  2844. * Invalid client magic was detected. This error only returns
  2845. * when |session| was configured as server and
  2846. * `nghttp2_option_set_no_recv_client_magic()` is not used with
  2847. * nonzero value.
  2848. * :enum:`NGHTTP2_ERR_FLOODED`
  2849. * Flooding was detected in this HTTP/2 session, and it must be
  2850. * closed. This is most likely caused by misbehaviour of peer.
  2851. */
  2852. NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session);
  2853. /**
  2854. * @function
  2855. *
  2856. * Processes data |in| as an input from the remote endpoint. The
  2857. * |inlen| indicates the number of bytes in the |in|.
  2858. *
  2859. * This function behaves like `nghttp2_session_recv()` except that it
  2860. * does not use :type:`nghttp2_recv_callback` to receive data; the
  2861. * |in| is the only data for the invocation of this function. If all
  2862. * bytes are processed, this function returns. The other callbacks
  2863. * are called in the same way as they are in `nghttp2_session_recv()`.
  2864. *
  2865. * In the current implementation, this function always tries to
  2866. * processes all input data unless either an error occurs or
  2867. * :enum:`NGHTTP2_ERR_PAUSE` is returned from
  2868. * :type:`nghttp2_on_header_callback` or
  2869. * :type:`nghttp2_on_data_chunk_recv_callback`. If
  2870. * :enum:`NGHTTP2_ERR_PAUSE` is used, the return value includes the
  2871. * number of bytes which was used to produce the data or frame for the
  2872. * callback.
  2873. *
  2874. * This function returns the number of processed bytes, or one of the
  2875. * following negative error codes:
  2876. *
  2877. * :enum:`NGHTTP2_ERR_NOMEM`
  2878. * Out of memory.
  2879. * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
  2880. * The callback function failed.
  2881. * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`
  2882. * Invalid client magic was detected. This error only returns
  2883. * when |session| was configured as server and
  2884. * `nghttp2_option_set_no_recv_client_magic()` is not used with
  2885. * nonzero value.
  2886. * :enum:`NGHTTP2_ERR_FLOODED`
  2887. * Flooding was detected in this HTTP/2 session, and it must be
  2888. * closed. This is most likely caused by misbehaviour of peer.
  2889. */
  2890. NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
  2891. const uint8_t *in,
  2892. size_t inlen);
  2893. /**
  2894. * @function
  2895. *
  2896. * Puts back previously deferred DATA frame in the stream |stream_id|
  2897. * to the outbound queue.
  2898. *
  2899. * This function returns 0 if it succeeds, or one of the following
  2900. * negative error codes:
  2901. *
  2902. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  2903. * The stream does not exist; or no deferred data exist.
  2904. * :enum:`NGHTTP2_ERR_NOMEM`
  2905. * Out of memory.
  2906. */
  2907. NGHTTP2_EXTERN int nghttp2_session_resume_data(nghttp2_session *session,
  2908. int32_t stream_id);
  2909. /**
  2910. * @function
  2911. *
  2912. * Returns nonzero value if |session| wants to receive data from the
  2913. * remote peer.
  2914. *
  2915. * If both `nghttp2_session_want_read()` and
  2916. * `nghttp2_session_want_write()` return 0, the application should
  2917. * drop the connection.
  2918. */
  2919. NGHTTP2_EXTERN int nghttp2_session_want_read(nghttp2_session *session);
  2920. /**
  2921. * @function
  2922. *
  2923. * Returns nonzero value if |session| wants to send data to the remote
  2924. * peer.
  2925. *
  2926. * If both `nghttp2_session_want_read()` and
  2927. * `nghttp2_session_want_write()` return 0, the application should
  2928. * drop the connection.
  2929. */
  2930. NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session);
  2931. /**
  2932. * @function
  2933. *
  2934. * Returns stream_user_data for the stream |stream_id|. The
  2935. * stream_user_data is provided by `nghttp2_submit_request()`,
  2936. * `nghttp2_submit_headers()` or
  2937. * `nghttp2_session_set_stream_user_data()`. Unless it is set using
  2938. * `nghttp2_session_set_stream_user_data()`, if the stream is
  2939. * initiated by the remote endpoint, stream_user_data is always
  2940. * ``NULL``. If the stream does not exist, this function returns
  2941. * ``NULL``.
  2942. */
  2943. NGHTTP2_EXTERN void *
  2944. nghttp2_session_get_stream_user_data(nghttp2_session *session,
  2945. int32_t stream_id);
  2946. /**
  2947. * @function
  2948. *
  2949. * Sets the |stream_user_data| to the stream denoted by the
  2950. * |stream_id|. If a stream user data is already set to the stream,
  2951. * it is replaced with the |stream_user_data|. It is valid to specify
  2952. * ``NULL`` in the |stream_user_data|, which nullifies the associated
  2953. * data pointer.
  2954. *
  2955. * It is valid to set the |stream_user_data| to the stream reserved by
  2956. * PUSH_PROMISE frame.
  2957. *
  2958. * This function returns 0 if it succeeds, or one of following
  2959. * negative error codes:
  2960. *
  2961. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  2962. * The stream does not exist
  2963. */
  2964. NGHTTP2_EXTERN int
  2965. nghttp2_session_set_stream_user_data(nghttp2_session *session,
  2966. int32_t stream_id, void *stream_user_data);
  2967. /**
  2968. * @function
  2969. *
  2970. * Sets |user_data| to |session|, overwriting the existing user data
  2971. * specified in `nghttp2_session_client_new()`, or
  2972. * `nghttp2_session_server_new()`.
  2973. */
  2974. NGHTTP2_EXTERN void nghttp2_session_set_user_data(nghttp2_session *session,
  2975. void *user_data);
  2976. /**
  2977. * @function
  2978. *
  2979. * Returns the number of frames in the outbound queue. This does not
  2980. * include the deferred DATA frames.
  2981. */
  2982. NGHTTP2_EXTERN size_t
  2983. nghttp2_session_get_outbound_queue_size(nghttp2_session *session);
  2984. /**
  2985. * @function
  2986. *
  2987. * Returns the number of DATA payload in bytes received without
  2988. * WINDOW_UPDATE transmission for the stream |stream_id|. The local
  2989. * (receive) window size can be adjusted by
  2990. * `nghttp2_submit_window_update()`. This function takes into account
  2991. * that and returns effective data length. In particular, if the
  2992. * local window size is reduced by submitting negative
  2993. * window_size_increment with `nghttp2_submit_window_update()`, this
  2994. * function returns the number of bytes less than actually received.
  2995. *
  2996. * This function returns -1 if it fails.
  2997. */
  2998. NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_recv_data_length(
  2999. nghttp2_session *session, int32_t stream_id);
  3000. /**
  3001. * @function
  3002. *
  3003. * Returns the local (receive) window size for the stream |stream_id|.
  3004. * The local window size can be adjusted by
  3005. * `nghttp2_submit_window_update()`. This function takes into account
  3006. * that and returns effective window size.
  3007. *
  3008. * This function does not take into account the amount of received
  3009. * data from the remote endpoint. Use
  3010. * `nghttp2_session_get_stream_local_window_size()` to know the amount
  3011. * of data the remote endpoint can send without receiving stream level
  3012. * WINDOW_UPDATE frame. Note that each stream is still subject to the
  3013. * connection level flow control.
  3014. *
  3015. * This function returns -1 if it fails.
  3016. */
  3017. NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_local_window_size(
  3018. nghttp2_session *session, int32_t stream_id);
  3019. /**
  3020. * @function
  3021. *
  3022. * Returns the amount of flow-controlled payload (e.g., DATA) that the
  3023. * remote endpoint can send without receiving stream level
  3024. * WINDOW_UPDATE frame. It is also subject to the connection level
  3025. * flow control. So the actual amount of data to send is
  3026. * min(`nghttp2_session_get_stream_local_window_size()`,
  3027. * `nghttp2_session_get_local_window_size()`).
  3028. *
  3029. * This function returns -1 if it fails.
  3030. */
  3031. NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_local_window_size(
  3032. nghttp2_session *session, int32_t stream_id);
  3033. /**
  3034. * @function
  3035. *
  3036. * Returns the number of DATA payload in bytes received without
  3037. * WINDOW_UPDATE transmission for a connection. The local (receive)
  3038. * window size can be adjusted by `nghttp2_submit_window_update()`.
  3039. * This function takes into account that and returns effective data
  3040. * length. In particular, if the local window size is reduced by
  3041. * submitting negative window_size_increment with
  3042. * `nghttp2_submit_window_update()`, this function returns the number
  3043. * of bytes less than actually received.
  3044. *
  3045. * This function returns -1 if it fails.
  3046. */
  3047. NGHTTP2_EXTERN int32_t
  3048. nghttp2_session_get_effective_recv_data_length(nghttp2_session *session);
  3049. /**
  3050. * @function
  3051. *
  3052. * Returns the local (receive) window size for a connection. The
  3053. * local window size can be adjusted by
  3054. * `nghttp2_submit_window_update()`. This function takes into account
  3055. * that and returns effective window size.
  3056. *
  3057. * This function does not take into account the amount of received
  3058. * data from the remote endpoint. Use
  3059. * `nghttp2_session_get_local_window_size()` to know the amount of
  3060. * data the remote endpoint can send without receiving
  3061. * connection-level WINDOW_UPDATE frame. Note that each stream is
  3062. * still subject to the stream level flow control.
  3063. *
  3064. * This function returns -1 if it fails.
  3065. */
  3066. NGHTTP2_EXTERN int32_t
  3067. nghttp2_session_get_effective_local_window_size(nghttp2_session *session);
  3068. /**
  3069. * @function
  3070. *
  3071. * Returns the amount of flow-controlled payload (e.g., DATA) that the
  3072. * remote endpoint can send without receiving connection level
  3073. * WINDOW_UPDATE frame. Note that each stream is still subject to the
  3074. * stream level flow control (see
  3075. * `nghttp2_session_get_stream_local_window_size()`).
  3076. *
  3077. * This function returns -1 if it fails.
  3078. */
  3079. NGHTTP2_EXTERN int32_t
  3080. nghttp2_session_get_local_window_size(nghttp2_session *session);
  3081. /**
  3082. * @function
  3083. *
  3084. * Returns the remote window size for a given stream |stream_id|.
  3085. *
  3086. * This is the amount of flow-controlled payload (e.g., DATA) that the
  3087. * local endpoint can send without stream level WINDOW_UPDATE. There
  3088. * is also connection level flow control, so the effective size of
  3089. * payload that the local endpoint can actually send is
  3090. * min(`nghttp2_session_get_stream_remote_window_size()`,
  3091. * `nghttp2_session_get_remote_window_size()`).
  3092. *
  3093. * This function returns -1 if it fails.
  3094. */
  3095. NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_remote_window_size(
  3096. nghttp2_session *session, int32_t stream_id);
  3097. /**
  3098. * @function
  3099. *
  3100. * Returns the remote window size for a connection.
  3101. *
  3102. * This function always succeeds.
  3103. */
  3104. NGHTTP2_EXTERN int32_t
  3105. nghttp2_session_get_remote_window_size(nghttp2_session *session);
  3106. /**
  3107. * @function
  3108. *
  3109. * Returns 1 if local peer half closed the given stream |stream_id|.
  3110. * Returns 0 if it did not. Returns -1 if no such stream exists.
  3111. */
  3112. NGHTTP2_EXTERN int
  3113. nghttp2_session_get_stream_local_close(nghttp2_session *session,
  3114. int32_t stream_id);
  3115. /**
  3116. * @function
  3117. *
  3118. * Returns 1 if remote peer half closed the given stream |stream_id|.
  3119. * Returns 0 if it did not. Returns -1 if no such stream exists.
  3120. */
  3121. NGHTTP2_EXTERN int
  3122. nghttp2_session_get_stream_remote_close(nghttp2_session *session,
  3123. int32_t stream_id);
  3124. /**
  3125. * @function
  3126. *
  3127. * Returns the current dynamic table size of HPACK inflater, including
  3128. * the overhead 32 bytes per entry described in RFC 7541.
  3129. */
  3130. NGHTTP2_EXTERN size_t
  3131. nghttp2_session_get_hd_inflate_dynamic_table_size(nghttp2_session *session);
  3132. /**
  3133. * @function
  3134. *
  3135. * Returns the current dynamic table size of HPACK deflater including
  3136. * the overhead 32 bytes per entry described in RFC 7541.
  3137. */
  3138. NGHTTP2_EXTERN size_t
  3139. nghttp2_session_get_hd_deflate_dynamic_table_size(nghttp2_session *session);
  3140. /**
  3141. * @function
  3142. *
  3143. * Signals the session so that the connection should be terminated.
  3144. *
  3145. * The last stream ID is the minimum value between the stream ID of a
  3146. * stream for which :type:`nghttp2_on_frame_recv_callback` was called
  3147. * most recently and the last stream ID we have sent to the peer
  3148. * previously.
  3149. *
  3150. * The |error_code| is the error code of this GOAWAY frame. The
  3151. * pre-defined error code is one of :enum:`nghttp2_error_code`.
  3152. *
  3153. * After the transmission, both `nghttp2_session_want_read()` and
  3154. * `nghttp2_session_want_write()` return 0.
  3155. *
  3156. * This function should be called when the connection should be
  3157. * terminated after sending GOAWAY. If the remaining streams should
  3158. * be processed after GOAWAY, use `nghttp2_submit_goaway()` instead.
  3159. *
  3160. * This function returns 0 if it succeeds, or one of the following
  3161. * negative error codes:
  3162. *
  3163. * :enum:`NGHTTP2_ERR_NOMEM`
  3164. * Out of memory.
  3165. */
  3166. NGHTTP2_EXTERN int nghttp2_session_terminate_session(nghttp2_session *session,
  3167. uint32_t error_code);
  3168. /**
  3169. * @function
  3170. *
  3171. * Signals the session so that the connection should be terminated.
  3172. *
  3173. * This function behaves like `nghttp2_session_terminate_session()`,
  3174. * but the last stream ID can be specified by the application for fine
  3175. * grained control of stream. The HTTP/2 specification does not allow
  3176. * last_stream_id to be increased. So the actual value sent as
  3177. * last_stream_id is the minimum value between the given
  3178. * |last_stream_id| and the last_stream_id we have previously sent to
  3179. * the peer.
  3180. *
  3181. * The |last_stream_id| is peer's stream ID or 0. So if |session| is
  3182. * initialized as client, |last_stream_id| must be even or 0. If
  3183. * |session| is initialized as server, |last_stream_id| must be odd or
  3184. * 0.
  3185. *
  3186. * This function returns 0 if it succeeds, or one of the following
  3187. * negative error codes:
  3188. *
  3189. * :enum:`NGHTTP2_ERR_NOMEM`
  3190. * Out of memory.
  3191. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3192. * The |last_stream_id| is invalid.
  3193. */
  3194. NGHTTP2_EXTERN int nghttp2_session_terminate_session2(nghttp2_session *session,
  3195. int32_t last_stream_id,
  3196. uint32_t error_code);
  3197. /**
  3198. * @function
  3199. *
  3200. * Signals to the client that the server started graceful shutdown
  3201. * procedure.
  3202. *
  3203. * This function is only usable for server. If this function is
  3204. * called with client side session, this function returns
  3205. * :enum:`NGHTTP2_ERR_INVALID_STATE`.
  3206. *
  3207. * To gracefully shutdown HTTP/2 session, server should call this
  3208. * function to send GOAWAY with last_stream_id (1u << 31) - 1. And
  3209. * after some delay (e.g., 1 RTT), send another GOAWAY with the stream
  3210. * ID that the server has some processing using
  3211. * `nghttp2_submit_goaway()`. See also
  3212. * `nghttp2_session_get_last_proc_stream_id()`.
  3213. *
  3214. * Unlike `nghttp2_submit_goaway()`, this function just sends GOAWAY
  3215. * and does nothing more. This is a mere indication to the client
  3216. * that session shutdown is imminent. The application should call
  3217. * `nghttp2_submit_goaway()` with appropriate last_stream_id after
  3218. * this call.
  3219. *
  3220. * If one or more GOAWAY frame have been already sent by either
  3221. * `nghttp2_submit_goaway()` or `nghttp2_session_terminate_session()`,
  3222. * this function has no effect.
  3223. *
  3224. * This function returns 0 if it succeeds, or one of the following
  3225. * negative error codes:
  3226. *
  3227. * :enum:`NGHTTP2_ERR_NOMEM`
  3228. * Out of memory.
  3229. * :enum:`NGHTTP2_ERR_INVALID_STATE`
  3230. * The |session| is initialized as client.
  3231. */
  3232. NGHTTP2_EXTERN int nghttp2_submit_shutdown_notice(nghttp2_session *session);
  3233. /**
  3234. * @function
  3235. *
  3236. * Returns the value of SETTINGS |id| notified by a remote endpoint.
  3237. * The |id| must be one of values defined in
  3238. * :enum:`nghttp2_settings_id`.
  3239. */
  3240. NGHTTP2_EXTERN uint32_t nghttp2_session_get_remote_settings(
  3241. nghttp2_session *session, nghttp2_settings_id id);
  3242. /**
  3243. * @function
  3244. *
  3245. * Returns the value of SETTINGS |id| of local endpoint acknowledged
  3246. * by the remote endpoint. The |id| must be one of the values defined
  3247. * in :enum:`nghttp2_settings_id`.
  3248. */
  3249. NGHTTP2_EXTERN uint32_t nghttp2_session_get_local_settings(
  3250. nghttp2_session *session, nghttp2_settings_id id);
  3251. /**
  3252. * @function
  3253. *
  3254. * Tells the |session| that next stream ID is |next_stream_id|. The
  3255. * |next_stream_id| must be equal or greater than the value returned
  3256. * by `nghttp2_session_get_next_stream_id()`.
  3257. *
  3258. * This function returns 0 if it succeeds, or one of the following
  3259. * negative error codes:
  3260. *
  3261. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3262. * The |next_stream_id| is strictly less than the value
  3263. * `nghttp2_session_get_next_stream_id()` returns; or
  3264. * |next_stream_id| is invalid (e.g., even integer for client, or
  3265. * odd integer for server).
  3266. */
  3267. NGHTTP2_EXTERN int nghttp2_session_set_next_stream_id(nghttp2_session *session,
  3268. int32_t next_stream_id);
  3269. /**
  3270. * @function
  3271. *
  3272. * Returns the next outgoing stream ID. Notice that return type is
  3273. * uint32_t. If we run out of stream ID for this session, this
  3274. * function returns 1 << 31.
  3275. */
  3276. NGHTTP2_EXTERN uint32_t
  3277. nghttp2_session_get_next_stream_id(nghttp2_session *session);
  3278. /**
  3279. * @function
  3280. *
  3281. * Tells the |session| that |size| bytes for a stream denoted by
  3282. * |stream_id| were consumed by application and are ready to
  3283. * WINDOW_UPDATE. The consumed bytes are counted towards both
  3284. * connection and stream level WINDOW_UPDATE (see
  3285. * `nghttp2_session_consume_connection()` and
  3286. * `nghttp2_session_consume_stream()` to update consumption
  3287. * independently). This function is intended to be used without
  3288. * automatic window update (see
  3289. * `nghttp2_option_set_no_auto_window_update()`).
  3290. *
  3291. * This function returns 0 if it succeeds, or one of the following
  3292. * negative error codes:
  3293. *
  3294. * :enum:`NGHTTP2_ERR_NOMEM`
  3295. * Out of memory.
  3296. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3297. * The |stream_id| is 0.
  3298. * :enum:`NGHTTP2_ERR_INVALID_STATE`
  3299. * Automatic WINDOW_UPDATE is not disabled.
  3300. */
  3301. NGHTTP2_EXTERN int nghttp2_session_consume(nghttp2_session *session,
  3302. int32_t stream_id, size_t size);
  3303. /**
  3304. * @function
  3305. *
  3306. * Like `nghttp2_session_consume()`, but this only tells library that
  3307. * |size| bytes were consumed only for connection level. Note that
  3308. * HTTP/2 maintains connection and stream level flow control windows
  3309. * independently.
  3310. *
  3311. * This function returns 0 if it succeeds, or one of the following
  3312. * negative error codes:
  3313. *
  3314. * :enum:`NGHTTP2_ERR_NOMEM`
  3315. * Out of memory.
  3316. * :enum:`NGHTTP2_ERR_INVALID_STATE`
  3317. * Automatic WINDOW_UPDATE is not disabled.
  3318. */
  3319. NGHTTP2_EXTERN int nghttp2_session_consume_connection(nghttp2_session *session,
  3320. size_t size);
  3321. /**
  3322. * @function
  3323. *
  3324. * Like `nghttp2_session_consume()`, but this only tells library that
  3325. * |size| bytes were consumed only for stream denoted by |stream_id|.
  3326. * Note that HTTP/2 maintains connection and stream level flow control
  3327. * windows independently.
  3328. *
  3329. * This function returns 0 if it succeeds, or one of the following
  3330. * negative error codes:
  3331. *
  3332. * :enum:`NGHTTP2_ERR_NOMEM`
  3333. * Out of memory.
  3334. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3335. * The |stream_id| is 0.
  3336. * :enum:`NGHTTP2_ERR_INVALID_STATE`
  3337. * Automatic WINDOW_UPDATE is not disabled.
  3338. */
  3339. NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session,
  3340. int32_t stream_id,
  3341. size_t size);
  3342. /**
  3343. * @function
  3344. *
  3345. * Changes priority of existing stream denoted by |stream_id|. The
  3346. * new priority specification is |pri_spec|.
  3347. *
  3348. * The priority is changed silently and instantly, and no PRIORITY
  3349. * frame will be sent to notify the peer of this change. This
  3350. * function may be useful for server to change the priority of pushed
  3351. * stream.
  3352. *
  3353. * If |session| is initialized as server, and ``pri_spec->stream_id``
  3354. * points to the idle stream, the idle stream is created if it does
  3355. * not exist. The created idle stream will depend on root stream
  3356. * (stream 0) with weight 16.
  3357. *
  3358. * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not
  3359. * found, we use default priority instead of given |pri_spec|. That
  3360. * is make stream depend on root stream with weight 16.
  3361. *
  3362. * This function returns 0 if it succeeds, or one of the following
  3363. * negative error codes:
  3364. *
  3365. * :enum:`NGHTTP2_ERR_NOMEM`
  3366. * Out of memory.
  3367. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3368. * Attempted to depend on itself; or no stream exist for the given
  3369. * |stream_id|; or |stream_id| is 0
  3370. */
  3371. NGHTTP2_EXTERN int
  3372. nghttp2_session_change_stream_priority(nghttp2_session *session,
  3373. int32_t stream_id,
  3374. const nghttp2_priority_spec *pri_spec);
  3375. /**
  3376. * @function
  3377. *
  3378. * Creates idle stream with the given |stream_id|, and priority
  3379. * |pri_spec|.
  3380. *
  3381. * The stream creation is done without sending PRIORITY frame, which
  3382. * means that peer does not know about the existence of this idle
  3383. * stream in the local endpoint.
  3384. *
  3385. * RFC 7540 does not disallow the use of creation of idle stream with
  3386. * odd or even stream ID regardless of client or server. So this
  3387. * function can create odd or even stream ID regardless of client or
  3388. * server. But probably it is a bit safer to use the stream ID the
  3389. * local endpoint can initiate (in other words, use odd stream ID for
  3390. * client, and even stream ID for server), to avoid potential
  3391. * collision from peer's instruction. Also we can use
  3392. * `nghttp2_session_set_next_stream_id()` to avoid to open created
  3393. * idle streams accidentally if we follow this recommendation.
  3394. *
  3395. * If |session| is initialized as server, and ``pri_spec->stream_id``
  3396. * points to the idle stream, the idle stream is created if it does
  3397. * not exist. The created idle stream will depend on root stream
  3398. * (stream 0) with weight 16.
  3399. *
  3400. * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not
  3401. * found, we use default priority instead of given |pri_spec|. That
  3402. * is make stream depend on root stream with weight 16.
  3403. *
  3404. * This function returns 0 if it succeeds, or one of the following
  3405. * negative error codes:
  3406. *
  3407. * :enum:`NGHTTP2_ERR_NOMEM`
  3408. * Out of memory.
  3409. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3410. * Attempted to depend on itself; or stream denoted by |stream_id|
  3411. * already exists; or |stream_id| cannot be used to create idle
  3412. * stream (in other words, local endpoint has already opened
  3413. * stream ID greater than or equal to the given stream ID; or
  3414. * |stream_id| is 0
  3415. */
  3416. NGHTTP2_EXTERN int
  3417. nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id,
  3418. const nghttp2_priority_spec *pri_spec);
  3419. /**
  3420. * @function
  3421. *
  3422. * Performs post-process of HTTP Upgrade request. This function can
  3423. * be called from both client and server, but the behavior is very
  3424. * different in each other.
  3425. *
  3426. * .. warning::
  3427. *
  3428. * This function is deprecated in favor of
  3429. * `nghttp2_session_upgrade2()`, because this function lacks the
  3430. * parameter to tell the library the request method used in the
  3431. * original HTTP request. This information is required for client
  3432. * to validate actual response body length against content-length
  3433. * header field (see `nghttp2_option_set_no_http_messaging()`). If
  3434. * HEAD is used in request, the length of response body must be 0
  3435. * regardless of value included in content-length header field.
  3436. *
  3437. * If called from client side, the |settings_payload| must be the
  3438. * value sent in ``HTTP2-Settings`` header field and must be decoded
  3439. * by base64url decoder. The |settings_payloadlen| is the length of
  3440. * |settings_payload|. The |settings_payload| is unpacked and its
  3441. * setting values will be submitted using `nghttp2_submit_settings()`.
  3442. * This means that the client application code does not need to submit
  3443. * SETTINGS by itself. The stream with stream ID=1 is opened and the
  3444. * |stream_user_data| is used for its stream_user_data. The opened
  3445. * stream becomes half-closed (local) state.
  3446. *
  3447. * If called from server side, the |settings_payload| must be the
  3448. * value received in ``HTTP2-Settings`` header field and must be
  3449. * decoded by base64url decoder. The |settings_payloadlen| is the
  3450. * length of |settings_payload|. It is treated as if the SETTINGS
  3451. * frame with that payload is received. Thus, callback functions for
  3452. * the reception of SETTINGS frame will be invoked. The stream with
  3453. * stream ID=1 is opened. The |stream_user_data| is ignored. The
  3454. * opened stream becomes half-closed (remote).
  3455. *
  3456. * This function returns 0 if it succeeds, or one of the following
  3457. * negative error codes:
  3458. *
  3459. * :enum:`NGHTTP2_ERR_NOMEM`
  3460. * Out of memory.
  3461. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3462. * The |settings_payload| is badly formed.
  3463. * :enum:`NGHTTP2_ERR_PROTO`
  3464. * The stream ID 1 is already used or closed; or is not available.
  3465. */
  3466. NGHTTP2_EXTERN int nghttp2_session_upgrade(nghttp2_session *session,
  3467. const uint8_t *settings_payload,
  3468. size_t settings_payloadlen,
  3469. void *stream_user_data);
  3470. /**
  3471. * @function
  3472. *
  3473. * Performs post-process of HTTP Upgrade request. This function can
  3474. * be called from both client and server, but the behavior is very
  3475. * different in each other.
  3476. *
  3477. * If called from client side, the |settings_payload| must be the
  3478. * value sent in ``HTTP2-Settings`` header field and must be decoded
  3479. * by base64url decoder. The |settings_payloadlen| is the length of
  3480. * |settings_payload|. The |settings_payload| is unpacked and its
  3481. * setting values will be submitted using `nghttp2_submit_settings()`.
  3482. * This means that the client application code does not need to submit
  3483. * SETTINGS by itself. The stream with stream ID=1 is opened and the
  3484. * |stream_user_data| is used for its stream_user_data. The opened
  3485. * stream becomes half-closed (local) state.
  3486. *
  3487. * If called from server side, the |settings_payload| must be the
  3488. * value received in ``HTTP2-Settings`` header field and must be
  3489. * decoded by base64url decoder. The |settings_payloadlen| is the
  3490. * length of |settings_payload|. It is treated as if the SETTINGS
  3491. * frame with that payload is received. Thus, callback functions for
  3492. * the reception of SETTINGS frame will be invoked. The stream with
  3493. * stream ID=1 is opened. The |stream_user_data| is ignored. The
  3494. * opened stream becomes half-closed (remote).
  3495. *
  3496. * If the request method is HEAD, pass nonzero value to
  3497. * |head_request|. Otherwise, pass 0.
  3498. *
  3499. * This function returns 0 if it succeeds, or one of the following
  3500. * negative error codes:
  3501. *
  3502. * :enum:`NGHTTP2_ERR_NOMEM`
  3503. * Out of memory.
  3504. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3505. * The |settings_payload| is badly formed.
  3506. * :enum:`NGHTTP2_ERR_PROTO`
  3507. * The stream ID 1 is already used or closed; or is not available.
  3508. */
  3509. NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session,
  3510. const uint8_t *settings_payload,
  3511. size_t settings_payloadlen,
  3512. int head_request,
  3513. void *stream_user_data);
  3514. /**
  3515. * @function
  3516. *
  3517. * Serializes the SETTINGS values |iv| in the |buf|. The size of the
  3518. * |buf| is specified by |buflen|. The number of entries in the |iv|
  3519. * array is given by |niv|. The required space in |buf| for the |niv|
  3520. * entries is ``6*niv`` bytes and if the given buffer is too small, an
  3521. * error is returned. This function is used mainly for creating a
  3522. * SETTINGS payload to be sent with the ``HTTP2-Settings`` header
  3523. * field in an HTTP Upgrade request. The data written in |buf| is NOT
  3524. * base64url encoded and the application is responsible for encoding.
  3525. *
  3526. * This function returns the number of bytes written in |buf|, or one
  3527. * of the following negative error codes:
  3528. *
  3529. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3530. * The |iv| contains duplicate settings ID or invalid value.
  3531. *
  3532. * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`
  3533. * The provided |buflen| size is too small to hold the output.
  3534. */
  3535. NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload(
  3536. uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv);
  3537. /**
  3538. * @function
  3539. *
  3540. * Returns string describing the |lib_error_code|. The
  3541. * |lib_error_code| must be one of the :enum:`nghttp2_error`.
  3542. */
  3543. NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code);
  3544. /**
  3545. * @function
  3546. *
  3547. * Returns string representation of HTTP/2 error code |error_code|
  3548. * (e.g., ``PROTOCOL_ERROR`` is returned if ``error_code ==
  3549. * NGHTTP2_PROTOCOL_ERROR``). If string representation is unknown for
  3550. * given |error_code|, this function returns string ``unknown``.
  3551. */
  3552. NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code);
  3553. /**
  3554. * @function
  3555. *
  3556. * Initializes |pri_spec| with the |stream_id| of the stream to depend
  3557. * on with |weight| and its exclusive flag. If |exclusive| is
  3558. * nonzero, exclusive flag is set.
  3559. *
  3560. * The |weight| must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
  3561. * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive.
  3562. */
  3563. NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec,
  3564. int32_t stream_id,
  3565. int32_t weight, int exclusive);
  3566. /**
  3567. * @function
  3568. *
  3569. * Initializes |pri_spec| with the default values. The default values
  3570. * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and
  3571. * exclusive = 0.
  3572. */
  3573. NGHTTP2_EXTERN void
  3574. nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec);
  3575. /**
  3576. * @function
  3577. *
  3578. * Returns nonzero if the |pri_spec| is filled with default values.
  3579. */
  3580. NGHTTP2_EXTERN int
  3581. nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec);
  3582. /**
  3583. * @function
  3584. *
  3585. * Submits HEADERS frame and optionally one or more DATA frames.
  3586. *
  3587. * The |pri_spec| is priority specification of this request. ``NULL``
  3588. * means the default priority (see
  3589. * `nghttp2_priority_spec_default_init()`). To specify the priority,
  3590. * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,
  3591. * this function will copy its data members.
  3592. *
  3593. * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
  3594. * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is
  3595. * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
  3596. * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
  3597. * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
  3598. *
  3599. * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
  3600. * |nvlen| elements. The application is responsible to include
  3601. * required pseudo-header fields (header field whose name starts with
  3602. * ":") in |nva| and must place pseudo-headers before regular header
  3603. * fields.
  3604. *
  3605. * This function creates copies of all name/value pairs in |nva|. It
  3606. * also lower-cases all names in |nva|. The order of elements in
  3607. * |nva| is preserved. For header fields with
  3608. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
  3609. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
  3610. * and value are not copied respectively. With
  3611. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
  3612. * pass header field name in lowercase. The application should
  3613. * maintain the references to them until
  3614. * :type:`nghttp2_on_frame_send_callback` or
  3615. * :type:`nghttp2_on_frame_not_send_callback` is called.
  3616. *
  3617. * HTTP/2 specification has requirement about header fields in the
  3618. * request HEADERS. See the specification for more details.
  3619. *
  3620. * If |data_prd| is not ``NULL``, it provides data which will be sent
  3621. * in subsequent DATA frames. In this case, a method that allows
  3622. * request message bodies
  3623. * (https://tools.ietf.org/html/rfc7231#section-4) must be specified
  3624. * with ``:method`` key in |nva| (e.g. ``POST``). This function does
  3625. * not take ownership of the |data_prd|. The function copies the
  3626. * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have
  3627. * END_STREAM set. The |stream_user_data| is data associated to the
  3628. * stream opened by this request and can be an arbitrary pointer,
  3629. * which can be retrieved later by
  3630. * `nghttp2_session_get_stream_user_data()`.
  3631. *
  3632. * This function returns assigned stream ID if it succeeds, or one of
  3633. * the following negative error codes:
  3634. *
  3635. * :enum:`NGHTTP2_ERR_NOMEM`
  3636. * Out of memory.
  3637. * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
  3638. * No stream ID is available because maximum stream ID was
  3639. * reached.
  3640. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3641. * Trying to depend on itself (new stream ID equals
  3642. * ``pri_spec->stream_id``).
  3643. * :enum:`NGHTTP2_ERR_PROTO`
  3644. * The |session| is server session.
  3645. *
  3646. * .. warning::
  3647. *
  3648. * This function returns assigned stream ID if it succeeds. But
  3649. * that stream is not created yet. The application must not submit
  3650. * frame to that stream ID before
  3651. * :type:`nghttp2_before_frame_send_callback` is called for this
  3652. * frame. This means `nghttp2_session_get_stream_user_data()` does
  3653. * not work before the callback. But
  3654. * `nghttp2_session_set_stream_user_data()` handles this situation
  3655. * specially, and it can set data to a stream during this period.
  3656. *
  3657. */
  3658. NGHTTP2_EXTERN int32_t nghttp2_submit_request(
  3659. nghttp2_session *session, const nghttp2_priority_spec *pri_spec,
  3660. const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd,
  3661. void *stream_user_data);
  3662. /**
  3663. * @function
  3664. *
  3665. * Submits response HEADERS frame and optionally one or more DATA
  3666. * frames against the stream |stream_id|.
  3667. *
  3668. * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
  3669. * |nvlen| elements. The application is responsible to include
  3670. * required pseudo-header fields (header field whose name starts with
  3671. * ":") in |nva| and must place pseudo-headers before regular header
  3672. * fields.
  3673. *
  3674. * This function creates copies of all name/value pairs in |nva|. It
  3675. * also lower-cases all names in |nva|. The order of elements in
  3676. * |nva| is preserved. For header fields with
  3677. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
  3678. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
  3679. * and value are not copied respectively. With
  3680. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
  3681. * pass header field name in lowercase. The application should
  3682. * maintain the references to them until
  3683. * :type:`nghttp2_on_frame_send_callback` or
  3684. * :type:`nghttp2_on_frame_not_send_callback` is called.
  3685. *
  3686. * HTTP/2 specification has requirement about header fields in the
  3687. * response HEADERS. See the specification for more details.
  3688. *
  3689. * If |data_prd| is not ``NULL``, it provides data which will be sent
  3690. * in subsequent DATA frames. This function does not take ownership
  3691. * of the |data_prd|. The function copies the members of the
  3692. * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have
  3693. * END_STREAM flag set.
  3694. *
  3695. * This method can be used as normal HTTP response and push response.
  3696. * When pushing a resource using this function, the |session| must be
  3697. * configured using `nghttp2_session_server_new()` or its variants and
  3698. * the target stream denoted by the |stream_id| must be reserved using
  3699. * `nghttp2_submit_push_promise()`.
  3700. *
  3701. * To send non-final response headers (e.g., HTTP status 101), don't
  3702. * use this function because this function half-closes the outbound
  3703. * stream. Instead, use `nghttp2_submit_headers()` for this purpose.
  3704. *
  3705. * This function returns 0 if it succeeds, or one of the following
  3706. * negative error codes:
  3707. *
  3708. * :enum:`NGHTTP2_ERR_NOMEM`
  3709. * Out of memory.
  3710. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3711. * The |stream_id| is 0.
  3712. * :enum:`NGHTTP2_ERR_DATA_EXIST`
  3713. * DATA or HEADERS has been already submitted and not fully
  3714. * processed yet. Normally, this does not happen, but when
  3715. * application wrongly calls `nghttp2_submit_response()` twice,
  3716. * this may happen.
  3717. * :enum:`NGHTTP2_ERR_PROTO`
  3718. * The |session| is client session.
  3719. *
  3720. * .. warning::
  3721. *
  3722. * Calling this function twice for the same stream ID may lead to
  3723. * program crash. It is generally considered to a programming error
  3724. * to commit response twice.
  3725. */
  3726. NGHTTP2_EXTERN int
  3727. nghttp2_submit_response(nghttp2_session *session, int32_t stream_id,
  3728. const nghttp2_nv *nva, size_t nvlen,
  3729. const nghttp2_data_provider *data_prd);
  3730. /**
  3731. * @function
  3732. *
  3733. * Submits trailer fields HEADERS against the stream |stream_id|.
  3734. *
  3735. * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
  3736. * |nvlen| elements. The application must not include pseudo-header
  3737. * fields (headers whose names starts with ":") in |nva|.
  3738. *
  3739. * This function creates copies of all name/value pairs in |nva|. It
  3740. * also lower-cases all names in |nva|. The order of elements in
  3741. * |nva| is preserved. For header fields with
  3742. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
  3743. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
  3744. * and value are not copied respectively. With
  3745. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
  3746. * pass header field name in lowercase. The application should
  3747. * maintain the references to them until
  3748. * :type:`nghttp2_on_frame_send_callback` or
  3749. * :type:`nghttp2_on_frame_not_send_callback` is called.
  3750. *
  3751. * For server, trailer fields must follow response HEADERS or response
  3752. * DATA without END_STREAM flat set. The library does not enforce
  3753. * this requirement, and applications should do this for themselves.
  3754. * If `nghttp2_submit_trailer()` is called before any response HEADERS
  3755. * submission (usually by `nghttp2_submit_response()`), the content of
  3756. * |nva| will be sent as response headers, which will result in error.
  3757. *
  3758. * This function has the same effect with `nghttp2_submit_headers()`,
  3759. * with flags = :enum:`NGHTTP2_FLAG_END_STREAM` and both pri_spec and
  3760. * stream_user_data to NULL.
  3761. *
  3762. * To submit trailer fields after `nghttp2_submit_response()` is
  3763. * called, the application has to specify
  3764. * :type:`nghttp2_data_provider` to `nghttp2_submit_response()`.
  3765. * Inside of :type:`nghttp2_data_source_read_callback`, when setting
  3766. * :enum:`NGHTTP2_DATA_FLAG_EOF`, also set
  3767. * :enum:`NGHTTP2_DATA_FLAG_NO_END_STREAM`. After that, the
  3768. * application can send trailer fields using
  3769. * `nghttp2_submit_trailer()`. `nghttp2_submit_trailer()` can be used
  3770. * inside :type:`nghttp2_data_source_read_callback`.
  3771. *
  3772. * This function returns 0 if it succeeds and |stream_id| is -1.
  3773. * Otherwise, this function returns 0 if it succeeds, or one of the
  3774. * following negative error codes:
  3775. *
  3776. * :enum:`NGHTTP2_ERR_NOMEM`
  3777. * Out of memory.
  3778. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3779. * The |stream_id| is 0.
  3780. */
  3781. NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session,
  3782. int32_t stream_id,
  3783. const nghttp2_nv *nva, size_t nvlen);
  3784. /**
  3785. * @function
  3786. *
  3787. * Submits HEADERS frame. The |flags| is bitwise OR of the
  3788. * following values:
  3789. *
  3790. * * :enum:`NGHTTP2_FLAG_END_STREAM`
  3791. *
  3792. * If |flags| includes :enum:`NGHTTP2_FLAG_END_STREAM`, this frame has
  3793. * END_STREAM flag set.
  3794. *
  3795. * The library handles the CONTINUATION frame internally and it
  3796. * correctly sets END_HEADERS to the last sequence of the PUSH_PROMISE
  3797. * or CONTINUATION frame.
  3798. *
  3799. * If the |stream_id| is -1, this frame is assumed as request (i.e.,
  3800. * request HEADERS frame which opens new stream). In this case, the
  3801. * assigned stream ID will be returned. Otherwise, specify stream ID
  3802. * in |stream_id|.
  3803. *
  3804. * The |pri_spec| is priority specification of this request. ``NULL``
  3805. * means the default priority (see
  3806. * `nghttp2_priority_spec_default_init()`). To specify the priority,
  3807. * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,
  3808. * this function will copy its data members.
  3809. *
  3810. * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
  3811. * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is
  3812. * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
  3813. * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
  3814. * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
  3815. *
  3816. * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
  3817. * |nvlen| elements. The application is responsible to include
  3818. * required pseudo-header fields (header field whose name starts with
  3819. * ":") in |nva| and must place pseudo-headers before regular header
  3820. * fields.
  3821. *
  3822. * This function creates copies of all name/value pairs in |nva|. It
  3823. * also lower-cases all names in |nva|. The order of elements in
  3824. * |nva| is preserved. For header fields with
  3825. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
  3826. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
  3827. * and value are not copied respectively. With
  3828. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
  3829. * pass header field name in lowercase. The application should
  3830. * maintain the references to them until
  3831. * :type:`nghttp2_on_frame_send_callback` or
  3832. * :type:`nghttp2_on_frame_not_send_callback` is called.
  3833. *
  3834. * The |stream_user_data| is a pointer to an arbitrary data which is
  3835. * associated to the stream this frame will open. Therefore it is
  3836. * only used if this frame opens streams, in other words, it changes
  3837. * stream state from idle or reserved to open.
  3838. *
  3839. * This function is low-level in a sense that the application code can
  3840. * specify flags directly. For usual HTTP request,
  3841. * `nghttp2_submit_request()` is useful. Likewise, for HTTP response,
  3842. * prefer `nghttp2_submit_response()`.
  3843. *
  3844. * This function returns newly assigned stream ID if it succeeds and
  3845. * |stream_id| is -1. Otherwise, this function returns 0 if it
  3846. * succeeds, or one of the following negative error codes:
  3847. *
  3848. * :enum:`NGHTTP2_ERR_NOMEM`
  3849. * Out of memory.
  3850. * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
  3851. * No stream ID is available because maximum stream ID was
  3852. * reached.
  3853. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3854. * The |stream_id| is 0; or trying to depend on itself (stream ID
  3855. * equals ``pri_spec->stream_id``).
  3856. * :enum:`NGHTTP2_ERR_DATA_EXIST`
  3857. * DATA or HEADERS has been already submitted and not fully
  3858. * processed yet. This happens if stream denoted by |stream_id|
  3859. * is in reserved state.
  3860. * :enum:`NGHTTP2_ERR_PROTO`
  3861. * The |stream_id| is -1, and |session| is server session.
  3862. *
  3863. * .. warning::
  3864. *
  3865. * This function returns assigned stream ID if it succeeds and
  3866. * |stream_id| is -1. But that stream is not opened yet. The
  3867. * application must not submit frame to that stream ID before
  3868. * :type:`nghttp2_before_frame_send_callback` is called for this
  3869. * frame.
  3870. *
  3871. */
  3872. NGHTTP2_EXTERN int32_t nghttp2_submit_headers(
  3873. nghttp2_session *session, uint8_t flags, int32_t stream_id,
  3874. const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen,
  3875. void *stream_user_data);
  3876. /**
  3877. * @function
  3878. *
  3879. * Submits one or more DATA frames to the stream |stream_id|. The
  3880. * data to be sent are provided by |data_prd|. If |flags| contains
  3881. * :enum:`NGHTTP2_FLAG_END_STREAM`, the last DATA frame has END_STREAM
  3882. * flag set.
  3883. *
  3884. * This function does not take ownership of the |data_prd|. The
  3885. * function copies the members of the |data_prd|.
  3886. *
  3887. * This function returns 0 if it succeeds, or one of the following
  3888. * negative error codes:
  3889. *
  3890. * :enum:`NGHTTP2_ERR_NOMEM`
  3891. * Out of memory.
  3892. * :enum:`NGHTTP2_ERR_DATA_EXIST`
  3893. * DATA or HEADERS has been already submitted and not fully
  3894. * processed yet.
  3895. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3896. * The |stream_id| is 0.
  3897. * :enum:`NGHTTP2_ERR_STREAM_CLOSED`
  3898. * The stream was already closed; or the |stream_id| is invalid.
  3899. *
  3900. * .. note::
  3901. *
  3902. * Currently, only one DATA or HEADERS is allowed for a stream at a
  3903. * time. Submitting these frames more than once before first DATA
  3904. * or HEADERS is finished results in :enum:`NGHTTP2_ERR_DATA_EXIST`
  3905. * error code. The earliest callback which tells that previous
  3906. * frame is done is :type:`nghttp2_on_frame_send_callback`. In side
  3907. * that callback, new data can be submitted using
  3908. * `nghttp2_submit_data()`. Of course, all data except for last one
  3909. * must not have :enum:`NGHTTP2_FLAG_END_STREAM` flag set in
  3910. * |flags|. This sounds a bit complicated, and we recommend to use
  3911. * `nghttp2_submit_request()` and `nghttp2_submit_response()` to
  3912. * avoid this cascading issue. The experience shows that for HTTP
  3913. * use, these two functions are enough to implement both client and
  3914. * server.
  3915. */
  3916. NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
  3917. int32_t stream_id,
  3918. const nghttp2_data_provider *data_prd);
  3919. /**
  3920. * @function
  3921. *
  3922. * Submits PRIORITY frame to change the priority of stream |stream_id|
  3923. * to the priority specification |pri_spec|.
  3924. *
  3925. * The |flags| is currently ignored and should be
  3926. * :enum:`NGHTTP2_FLAG_NONE`.
  3927. *
  3928. * The |pri_spec| is priority specification of this request. ``NULL``
  3929. * is not allowed for this function. To specify the priority, use
  3930. * `nghttp2_priority_spec_init()`. This function will copy its data
  3931. * members.
  3932. *
  3933. * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
  3934. * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is
  3935. * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
  3936. * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
  3937. * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
  3938. *
  3939. * This function returns 0 if it succeeds, or one of the following
  3940. * negative error codes:
  3941. *
  3942. * :enum:`NGHTTP2_ERR_NOMEM`
  3943. * Out of memory.
  3944. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3945. * The |stream_id| is 0; or the |pri_spec| is NULL; or trying to
  3946. * depend on itself.
  3947. */
  3948. NGHTTP2_EXTERN int
  3949. nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
  3950. int32_t stream_id,
  3951. const nghttp2_priority_spec *pri_spec);
  3952. /**
  3953. * @function
  3954. *
  3955. * Submits RST_STREAM frame to cancel/reject the stream |stream_id|
  3956. * with the error code |error_code|.
  3957. *
  3958. * The pre-defined error code is one of :enum:`nghttp2_error_code`.
  3959. *
  3960. * The |flags| is currently ignored and should be
  3961. * :enum:`NGHTTP2_FLAG_NONE`.
  3962. *
  3963. * This function returns 0 if it succeeds, or one of the following
  3964. * negative error codes:
  3965. *
  3966. * :enum:`NGHTTP2_ERR_NOMEM`
  3967. * Out of memory.
  3968. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3969. * The |stream_id| is 0.
  3970. */
  3971. NGHTTP2_EXTERN int nghttp2_submit_rst_stream(nghttp2_session *session,
  3972. uint8_t flags, int32_t stream_id,
  3973. uint32_t error_code);
  3974. /**
  3975. * @function
  3976. *
  3977. * Stores local settings and submits SETTINGS frame. The |iv| is the
  3978. * pointer to the array of :type:`nghttp2_settings_entry`. The |niv|
  3979. * indicates the number of :type:`nghttp2_settings_entry`.
  3980. *
  3981. * The |flags| is currently ignored and should be
  3982. * :enum:`NGHTTP2_FLAG_NONE`.
  3983. *
  3984. * This function does not take ownership of the |iv|. This function
  3985. * copies all the elements in the |iv|.
  3986. *
  3987. * While updating individual stream's local window size, if the window
  3988. * size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE,
  3989. * RST_STREAM is issued against such a stream.
  3990. *
  3991. * SETTINGS with :enum:`NGHTTP2_FLAG_ACK` is automatically submitted
  3992. * by the library and application could not send it at its will.
  3993. *
  3994. * This function returns 0 if it succeeds, or one of the following
  3995. * negative error codes:
  3996. *
  3997. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  3998. * The |iv| contains invalid value (e.g., initial window size
  3999. * strictly greater than (1 << 31) - 1.
  4000. * :enum:`NGHTTP2_ERR_NOMEM`
  4001. * Out of memory.
  4002. */
  4003. NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session,
  4004. uint8_t flags,
  4005. const nghttp2_settings_entry *iv,
  4006. size_t niv);
  4007. /**
  4008. * @function
  4009. *
  4010. * Submits PUSH_PROMISE frame.
  4011. *
  4012. * The |flags| is currently ignored. The library handles the
  4013. * CONTINUATION frame internally and it correctly sets END_HEADERS to
  4014. * the last sequence of the PUSH_PROMISE or CONTINUATION frame.
  4015. *
  4016. * The |stream_id| must be client initiated stream ID.
  4017. *
  4018. * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
  4019. * |nvlen| elements. The application is responsible to include
  4020. * required pseudo-header fields (header field whose name starts with
  4021. * ":") in |nva| and must place pseudo-headers before regular header
  4022. * fields.
  4023. *
  4024. * This function creates copies of all name/value pairs in |nva|. It
  4025. * also lower-cases all names in |nva|. The order of elements in
  4026. * |nva| is preserved. For header fields with
  4027. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
  4028. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
  4029. * and value are not copied respectively. With
  4030. * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
  4031. * pass header field name in lowercase. The application should
  4032. * maintain the references to them until
  4033. * :type:`nghttp2_on_frame_send_callback` or
  4034. * :type:`nghttp2_on_frame_not_send_callback` is called.
  4035. *
  4036. * The |promised_stream_user_data| is a pointer to an arbitrary data
  4037. * which is associated to the promised stream this frame will open and
  4038. * make it in reserved state. It is available using
  4039. * `nghttp2_session_get_stream_user_data()`. The application can
  4040. * access it in :type:`nghttp2_before_frame_send_callback` and
  4041. * :type:`nghttp2_on_frame_send_callback` of this frame.
  4042. *
  4043. * The client side is not allowed to use this function.
  4044. *
  4045. * To submit response headers and data, use
  4046. * `nghttp2_submit_response()`.
  4047. *
  4048. * This function returns assigned promised stream ID if it succeeds,
  4049. * or one of the following negative error codes:
  4050. *
  4051. * :enum:`NGHTTP2_ERR_NOMEM`
  4052. * Out of memory.
  4053. * :enum:`NGHTTP2_ERR_PROTO`
  4054. * This function was invoked when |session| is initialized as
  4055. * client.
  4056. * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
  4057. * No stream ID is available because maximum stream ID was
  4058. * reached.
  4059. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  4060. * The |stream_id| is 0; The |stream_id| does not designate stream
  4061. * that peer initiated.
  4062. * :enum:`NGHTTP2_ERR_STREAM_CLOSED`
  4063. * The stream was already closed; or the |stream_id| is invalid.
  4064. *
  4065. * .. warning::
  4066. *
  4067. * This function returns assigned promised stream ID if it succeeds.
  4068. * As of 1.16.0, stream object for pushed resource is created when
  4069. * this function succeeds. In that case, the application can submit
  4070. * push response for the promised frame.
  4071. *
  4072. * In 1.15.0 or prior versions, pushed stream is not opened yet when
  4073. * this function succeeds. The application must not submit frame to
  4074. * that stream ID before :type:`nghttp2_before_frame_send_callback`
  4075. * is called for this frame.
  4076. *
  4077. */
  4078. NGHTTP2_EXTERN int32_t nghttp2_submit_push_promise(
  4079. nghttp2_session *session, uint8_t flags, int32_t stream_id,
  4080. const nghttp2_nv *nva, size_t nvlen, void *promised_stream_user_data);
  4081. /**
  4082. * @function
  4083. *
  4084. * Submits PING frame. You don't have to send PING back when you
  4085. * received PING frame. The library automatically submits PING frame
  4086. * in this case.
  4087. *
  4088. * The |flags| is bitwise OR of 0 or more of the following value.
  4089. *
  4090. * * :enum:`NGHTTP2_FLAG_ACK`
  4091. *
  4092. * Unless `nghttp2_option_set_no_auto_ping_ack()` is used, the |flags|
  4093. * should be :enum:`NGHTTP2_FLAG_NONE`.
  4094. *
  4095. * If the |opaque_data| is non ``NULL``, then it should point to the 8
  4096. * bytes array of memory to specify opaque data to send with PING
  4097. * frame. If the |opaque_data| is ``NULL``, zero-cleared 8 bytes will
  4098. * be sent as opaque data.
  4099. *
  4100. * This function returns 0 if it succeeds, or one of the following
  4101. * negative error codes:
  4102. *
  4103. * :enum:`NGHTTP2_ERR_NOMEM`
  4104. * Out of memory.
  4105. */
  4106. NGHTTP2_EXTERN int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags,
  4107. const uint8_t *opaque_data);
  4108. /**
  4109. * @function
  4110. *
  4111. * Submits GOAWAY frame with the last stream ID |last_stream_id| and
  4112. * the error code |error_code|.
  4113. *
  4114. * The pre-defined error code is one of :enum:`nghttp2_error_code`.
  4115. *
  4116. * The |flags| is currently ignored and should be
  4117. * :enum:`NGHTTP2_FLAG_NONE`.
  4118. *
  4119. * The |last_stream_id| is peer's stream ID or 0. So if |session| is
  4120. * initialized as client, |last_stream_id| must be even or 0. If
  4121. * |session| is initialized as server, |last_stream_id| must be odd or
  4122. * 0.
  4123. *
  4124. * The HTTP/2 specification says last_stream_id must not be increased
  4125. * from the value previously sent. So the actual value sent as
  4126. * last_stream_id is the minimum value between the given
  4127. * |last_stream_id| and the last_stream_id previously sent to the
  4128. * peer.
  4129. *
  4130. * If the |opaque_data| is not ``NULL`` and |opaque_data_len| is not
  4131. * zero, those data will be sent as additional debug data. The
  4132. * library makes a copy of the memory region pointed by |opaque_data|
  4133. * with the length |opaque_data_len|, so the caller does not need to
  4134. * keep this memory after the return of this function. If the
  4135. * |opaque_data_len| is 0, the |opaque_data| could be ``NULL``.
  4136. *
  4137. * After successful transmission of GOAWAY, following things happen.
  4138. * All incoming streams having strictly more than |last_stream_id| are
  4139. * closed. All incoming HEADERS which starts new stream are simply
  4140. * ignored. After all active streams are handled, both
  4141. * `nghttp2_session_want_read()` and `nghttp2_session_want_write()`
  4142. * return 0 and the application can close session.
  4143. *
  4144. * This function returns 0 if it succeeds, or one of the following
  4145. * negative error codes:
  4146. *
  4147. * :enum:`NGHTTP2_ERR_NOMEM`
  4148. * Out of memory.
  4149. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  4150. * The |opaque_data_len| is too large; the |last_stream_id| is
  4151. * invalid.
  4152. */
  4153. NGHTTP2_EXTERN int nghttp2_submit_goaway(nghttp2_session *session,
  4154. uint8_t flags, int32_t last_stream_id,
  4155. uint32_t error_code,
  4156. const uint8_t *opaque_data,
  4157. size_t opaque_data_len);
  4158. /**
  4159. * @function
  4160. *
  4161. * Returns the last stream ID of a stream for which
  4162. * :type:`nghttp2_on_frame_recv_callback` was invoked most recently.
  4163. * The returned value can be used as last_stream_id parameter for
  4164. * `nghttp2_submit_goaway()` and
  4165. * `nghttp2_session_terminate_session2()`.
  4166. *
  4167. * This function always succeeds.
  4168. */
  4169. NGHTTP2_EXTERN int32_t
  4170. nghttp2_session_get_last_proc_stream_id(nghttp2_session *session);
  4171. /**
  4172. * @function
  4173. *
  4174. * Returns nonzero if new request can be sent from local endpoint.
  4175. *
  4176. * This function return 0 if request is not allowed for this session.
  4177. * There are several reasons why request is not allowed. Some of the
  4178. * reasons are: session is server; stream ID has been spent; GOAWAY
  4179. * has been sent or received.
  4180. *
  4181. * The application can call `nghttp2_submit_request()` without
  4182. * consulting this function. In that case, `nghttp2_submit_request()`
  4183. * may return error. Or, request is failed to sent, and
  4184. * :type:`nghttp2_on_stream_close_callback` is called.
  4185. */
  4186. NGHTTP2_EXTERN int
  4187. nghttp2_session_check_request_allowed(nghttp2_session *session);
  4188. /**
  4189. * @function
  4190. *
  4191. * Returns nonzero if |session| is initialized as server side session.
  4192. */
  4193. NGHTTP2_EXTERN int
  4194. nghttp2_session_check_server_session(nghttp2_session *session);
  4195. /**
  4196. * @function
  4197. *
  4198. * Submits WINDOW_UPDATE frame.
  4199. *
  4200. * The |flags| is currently ignored and should be
  4201. * :enum:`NGHTTP2_FLAG_NONE`.
  4202. *
  4203. * The |stream_id| is the stream ID to send this WINDOW_UPDATE. To
  4204. * send connection level WINDOW_UPDATE, specify 0 to |stream_id|.
  4205. *
  4206. * If the |window_size_increment| is positive, the WINDOW_UPDATE with
  4207. * that value as window_size_increment is queued. If the
  4208. * |window_size_increment| is larger than the received bytes from the
  4209. * remote endpoint, the local window size is increased by that
  4210. * difference. If the sole purpose is to increase the local window
  4211. * size, consider to use `nghttp2_session_set_local_window_size()`.
  4212. *
  4213. * If the |window_size_increment| is negative, the local window size
  4214. * is decreased by -|window_size_increment|. If automatic
  4215. * WINDOW_UPDATE is enabled
  4216. * (`nghttp2_option_set_no_auto_window_update()`), and the library
  4217. * decided that the WINDOW_UPDATE should be submitted, then
  4218. * WINDOW_UPDATE is queued with the current received bytes count. If
  4219. * the sole purpose is to decrease the local window size, consider to
  4220. * use `nghttp2_session_set_local_window_size()`.
  4221. *
  4222. * If the |window_size_increment| is 0, the function does nothing and
  4223. * returns 0.
  4224. *
  4225. * This function returns 0 if it succeeds, or one of the following
  4226. * negative error codes:
  4227. *
  4228. * :enum:`NGHTTP2_ERR_FLOW_CONTROL`
  4229. * The local window size overflow or gets negative.
  4230. * :enum:`NGHTTP2_ERR_NOMEM`
  4231. * Out of memory.
  4232. */
  4233. NGHTTP2_EXTERN int nghttp2_submit_window_update(nghttp2_session *session,
  4234. uint8_t flags,
  4235. int32_t stream_id,
  4236. int32_t window_size_increment);
  4237. /**
  4238. * @function
  4239. *
  4240. * Set local window size (local endpoints's window size) to the given
  4241. * |window_size| for the given stream denoted by |stream_id|. To
  4242. * change connection level window size, specify 0 to |stream_id|. To
  4243. * increase window size, this function may submit WINDOW_UPDATE frame
  4244. * to transmission queue.
  4245. *
  4246. * The |flags| is currently ignored and should be
  4247. * :enum:`NGHTTP2_FLAG_NONE`.
  4248. *
  4249. * This sounds similar to `nghttp2_submit_window_update()`, but there
  4250. * are 2 differences. The first difference is that this function
  4251. * takes the absolute value of window size to set, rather than the
  4252. * delta. To change the window size, this may be easier to use since
  4253. * the application just declares the intended window size, rather than
  4254. * calculating delta. The second difference is that
  4255. * `nghttp2_submit_window_update()` affects the received bytes count
  4256. * which has not acked yet. By the specification of
  4257. * `nghttp2_submit_window_update()`, to strictly increase the local
  4258. * window size, we have to submit delta including all received bytes
  4259. * count, which might not be desirable in some cases. On the other
  4260. * hand, this function does not affect the received bytes count. It
  4261. * just sets the local window size to the given value.
  4262. *
  4263. * This function returns 0 if it succeeds, or one of the following
  4264. * negative error codes:
  4265. *
  4266. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  4267. * The |stream_id| is negative.
  4268. * :enum:`NGHTTP2_ERR_NOMEM`
  4269. * Out of memory.
  4270. */
  4271. NGHTTP2_EXTERN int
  4272. nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags,
  4273. int32_t stream_id, int32_t window_size);
  4274. /**
  4275. * @function
  4276. *
  4277. * Submits extension frame.
  4278. *
  4279. * Application can pass arbitrary frame flags and stream ID in |flags|
  4280. * and |stream_id| respectively. The |payload| is opaque pointer, and
  4281. * it can be accessible though ``frame->ext.payload`` in
  4282. * :type:`nghttp2_pack_extension_callback`. The library will not own
  4283. * passed |payload| pointer.
  4284. *
  4285. * The application must set :type:`nghttp2_pack_extension_callback`
  4286. * using `nghttp2_session_callbacks_set_pack_extension_callback()`.
  4287. *
  4288. * The application should retain the memory pointed by |payload| until
  4289. * the transmission of extension frame is done (which is indicated by
  4290. * :type:`nghttp2_on_frame_send_callback`), or transmission fails
  4291. * (which is indicated by :type:`nghttp2_on_frame_not_send_callback`).
  4292. * If application does not touch this memory region after packing it
  4293. * into a wire format, application can free it inside
  4294. * :type:`nghttp2_pack_extension_callback`.
  4295. *
  4296. * The standard HTTP/2 frame cannot be sent with this function, so
  4297. * |type| must be strictly grater than 0x9. Otherwise, this function
  4298. * will fail with error code :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`.
  4299. *
  4300. * This function returns 0 if it succeeds, or one of the following
  4301. * negative error codes:
  4302. *
  4303. * :enum:`NGHTTP2_ERR_INVALID_STATE`
  4304. * If :type:`nghttp2_pack_extension_callback` is not set.
  4305. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  4306. * If |type| specifies standard HTTP/2 frame type. The frame
  4307. * types in the rage [0x0, 0x9], both inclusive, are standard
  4308. * HTTP/2 frame type, and cannot be sent using this function.
  4309. * :enum:`NGHTTP2_ERR_NOMEM`
  4310. * Out of memory
  4311. */
  4312. NGHTTP2_EXTERN int nghttp2_submit_extension(nghttp2_session *session,
  4313. uint8_t type, uint8_t flags,
  4314. int32_t stream_id, void *payload);
  4315. /**
  4316. * @struct
  4317. *
  4318. * The payload of ALTSVC frame. ALTSVC frame is a non-critical
  4319. * extension to HTTP/2. If this frame is received, and
  4320. * `nghttp2_option_set_user_recv_extension_type()` is not set, and
  4321. * `nghttp2_option_set_builtin_recv_extension_type()` is set for
  4322. * :enum:`NGHTTP2_ALTSVC`, ``nghttp2_extension.payload`` will point to
  4323. * this struct.
  4324. *
  4325. * It has the following members:
  4326. */
  4327. typedef struct {
  4328. /**
  4329. * The pointer to origin which this alternative service is
  4330. * associated with. This is not necessarily NULL-terminated.
  4331. */
  4332. uint8_t *origin;
  4333. /**
  4334. * The length of the |origin|.
  4335. */
  4336. size_t origin_len;
  4337. /**
  4338. * The pointer to Alt-Svc field value contained in ALTSVC frame.
  4339. * This is not necessarily NULL-terminated.
  4340. */
  4341. uint8_t *field_value;
  4342. /**
  4343. * The length of the |field_value|.
  4344. */
  4345. size_t field_value_len;
  4346. } nghttp2_ext_altsvc;
  4347. /**
  4348. * @function
  4349. *
  4350. * Submits ALTSVC frame.
  4351. *
  4352. * ALTSVC frame is a non-critical extension to HTTP/2, and defined in
  4353. * `RFC 7383 <https://tools.ietf.org/html/rfc7838#section-4>`_.
  4354. *
  4355. * The |flags| is currently ignored and should be
  4356. * :enum:`NGHTTP2_FLAG_NONE`.
  4357. *
  4358. * The |origin| points to the origin this alternative service is
  4359. * associated with. The |origin_len| is the length of the origin. If
  4360. * |stream_id| is 0, the origin must be specified. If |stream_id| is
  4361. * not zero, the origin must be empty (in other words, |origin_len|
  4362. * must be 0).
  4363. *
  4364. * The ALTSVC frame is only usable from server side. If this function
  4365. * is invoked with client side session, this function returns
  4366. * :enum:`NGHTTP2_ERR_INVALID_STATE`.
  4367. *
  4368. * This function returns 0 if it succeeds, or one of the following
  4369. * negative error codes:
  4370. *
  4371. * :enum:`NGHTTP2_ERR_NOMEM`
  4372. * Out of memory
  4373. * :enum:`NGHTTP2_ERR_INVALID_STATE`
  4374. * The function is called from client side session
  4375. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  4376. * The sum of |origin_len| and |field_value_len| is larger than
  4377. * 16382; or |origin_len| is 0 while |stream_id| is 0; or
  4378. * |origin_len| is not 0 while |stream_id| is not 0.
  4379. */
  4380. NGHTTP2_EXTERN int nghttp2_submit_altsvc(nghttp2_session *session,
  4381. uint8_t flags, int32_t stream_id,
  4382. const uint8_t *origin,
  4383. size_t origin_len,
  4384. const uint8_t *field_value,
  4385. size_t field_value_len);
  4386. /**
  4387. * @struct
  4388. *
  4389. * The single entry of an origin.
  4390. */
  4391. typedef struct {
  4392. /**
  4393. * The pointer to origin. No validation is made against this field
  4394. * by the library. This is not necessarily NULL-terminated.
  4395. */
  4396. uint8_t *origin;
  4397. /**
  4398. * The length of the |origin|.
  4399. */
  4400. size_t origin_len;
  4401. } nghttp2_origin_entry;
  4402. /**
  4403. * @struct
  4404. *
  4405. * The payload of ORIGIN frame. ORIGIN frame is a non-critical
  4406. * extension to HTTP/2 and defined by `RFC 8336
  4407. * <https://tools.ietf.org/html/rfc8336>`_.
  4408. *
  4409. * If this frame is received, and
  4410. * `nghttp2_option_set_user_recv_extension_type()` is not set, and
  4411. * `nghttp2_option_set_builtin_recv_extension_type()` is set for
  4412. * :enum:`NGHTTP2_ORIGIN`, ``nghttp2_extension.payload`` will point to
  4413. * this struct.
  4414. *
  4415. * It has the following members:
  4416. */
  4417. typedef struct {
  4418. /**
  4419. * The number of origins contained in |ov|.
  4420. */
  4421. size_t nov;
  4422. /**
  4423. * The pointer to the array of origins contained in ORIGIN frame.
  4424. */
  4425. nghttp2_origin_entry *ov;
  4426. } nghttp2_ext_origin;
  4427. /**
  4428. * @function
  4429. *
  4430. * Submits ORIGIN frame.
  4431. *
  4432. * ORIGIN frame is a non-critical extension to HTTP/2 and defined by
  4433. * `RFC 8336 <https://tools.ietf.org/html/rfc8336>`_.
  4434. *
  4435. * The |flags| is currently ignored and should be
  4436. * :enum:`NGHTTP2_FLAG_NONE`.
  4437. *
  4438. * The |ov| points to the array of origins. The |nov| specifies the
  4439. * number of origins included in |ov|. This function creates copies
  4440. * of all elements in |ov|.
  4441. *
  4442. * The ORIGIN frame is only usable by a server. If this function is
  4443. * invoked with client side session, this function returns
  4444. * :enum:`NGHTTP2_ERR_INVALID_STATE`.
  4445. *
  4446. * :enum:`NGHTTP2_ERR_NOMEM`
  4447. * Out of memory
  4448. * :enum:`NGHTTP2_ERR_INVALID_STATE`
  4449. * The function is called from client side session.
  4450. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
  4451. * There are too many origins, or an origin is too large to fit
  4452. * into a default frame payload.
  4453. */
  4454. NGHTTP2_EXTERN int nghttp2_submit_origin(nghttp2_session *session,
  4455. uint8_t flags,
  4456. const nghttp2_origin_entry *ov,
  4457. size_t nov);
  4458. /**
  4459. * @function
  4460. *
  4461. * Compares ``lhs->name`` of length ``lhs->namelen`` bytes and
  4462. * ``rhs->name`` of length ``rhs->namelen`` bytes. Returns negative
  4463. * integer if ``lhs->name`` is found to be less than ``rhs->name``; or
  4464. * returns positive integer if ``lhs->name`` is found to be greater
  4465. * than ``rhs->name``; or returns 0 otherwise.
  4466. */
  4467. NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs,
  4468. const nghttp2_nv *rhs);
  4469. /**
  4470. * @function
  4471. *
  4472. * A helper function for dealing with NPN in client side or ALPN in
  4473. * server side. The |in| contains peer's protocol list in preferable
  4474. * order. The format of |in| is length-prefixed and not
  4475. * null-terminated. For example, ``h2`` and
  4476. * ``http/1.1`` stored in |in| like this::
  4477. *
  4478. * in[0] = 2
  4479. * in[1..2] = "h2"
  4480. * in[3] = 8
  4481. * in[4..11] = "http/1.1"
  4482. * inlen = 12
  4483. *
  4484. * The selection algorithm is as follows:
  4485. *
  4486. * 1. If peer's list contains HTTP/2 protocol the library supports,
  4487. * it is selected and returns 1. The following step is not taken.
  4488. *
  4489. * 2. If peer's list contains ``http/1.1``, this function selects
  4490. * ``http/1.1`` and returns 0. The following step is not taken.
  4491. *
  4492. * 3. This function selects nothing and returns -1 (So called
  4493. * non-overlap case). In this case, |out| and |outlen| are left
  4494. * untouched.
  4495. *
  4496. * Selecting ``h2`` means that ``h2`` is written into |*out| and its
  4497. * length (which is 2) is assigned to |*outlen|.
  4498. *
  4499. * For ALPN, refer to https://tools.ietf.org/html/rfc7301
  4500. *
  4501. * See http://technotes.googlecode.com/git/nextprotoneg.html for more
  4502. * details about NPN.
  4503. *
  4504. * For NPN, to use this method you should do something like::
  4505. *
  4506. * static int select_next_proto_cb(SSL* ssl,
  4507. * unsigned char **out,
  4508. * unsigned char *outlen,
  4509. * const unsigned char *in,
  4510. * unsigned int inlen,
  4511. * void *arg)
  4512. * {
  4513. * int rv;
  4514. * rv = nghttp2_select_next_protocol(out, outlen, in, inlen);
  4515. * if (rv == -1) {
  4516. * return SSL_TLSEXT_ERR_NOACK;
  4517. * }
  4518. * if (rv == 1) {
  4519. * ((MyType*)arg)->http2_selected = 1;
  4520. * }
  4521. * return SSL_TLSEXT_ERR_OK;
  4522. * }
  4523. * ...
  4524. * SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, my_obj);
  4525. *
  4526. */
  4527. NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out,
  4528. unsigned char *outlen,
  4529. const unsigned char *in,
  4530. unsigned int inlen);
  4531. /**
  4532. * @function
  4533. *
  4534. * Returns a pointer to a nghttp2_info struct with version information
  4535. * about the run-time library in use. The |least_version| argument
  4536. * can be set to a 24 bit numerical value for the least accepted
  4537. * version number and if the condition is not met, this function will
  4538. * return a ``NULL``. Pass in 0 to skip the version checking.
  4539. */
  4540. NGHTTP2_EXTERN nghttp2_info *nghttp2_version(int least_version);
  4541. /**
  4542. * @function
  4543. *
  4544. * Returns nonzero if the :type:`nghttp2_error` library error code
  4545. * |lib_error| is fatal.
  4546. */
  4547. NGHTTP2_EXTERN int nghttp2_is_fatal(int lib_error_code);
  4548. /**
  4549. * @function
  4550. *
  4551. * Returns nonzero if HTTP header field name |name| of length |len| is
  4552. * valid according to http://tools.ietf.org/html/rfc7230#section-3.2
  4553. *
  4554. * Because this is a header field name in HTTP2, the upper cased alphabet
  4555. * is treated as error.
  4556. */
  4557. NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len);
  4558. /**
  4559. * @function
  4560. *
  4561. * Returns nonzero if HTTP header field value |value| of length |len|
  4562. * is valid according to
  4563. * http://tools.ietf.org/html/rfc7230#section-3.2
  4564. */
  4565. NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len);
  4566. /**
  4567. * @function
  4568. *
  4569. * Returns nonzero if the |value| which is supposed to the value of
  4570. * :authority or host header field is valid according to
  4571. * https://tools.ietf.org/html/rfc3986#section-3.2
  4572. *
  4573. * |value| is valid if it merely consists of the allowed characters.
  4574. * In particular, it does not check whether |value| follows the syntax
  4575. * of authority.
  4576. */
  4577. NGHTTP2_EXTERN int nghttp2_check_authority(const uint8_t *value, size_t len);
  4578. /* HPACK API */
  4579. struct nghttp2_hd_deflater;
  4580. /**
  4581. * @struct
  4582. *
  4583. * HPACK deflater object.
  4584. */
  4585. typedef struct nghttp2_hd_deflater nghttp2_hd_deflater;
  4586. /**
  4587. * @function
  4588. *
  4589. * Initializes |*deflater_ptr| for deflating name/values pairs.
  4590. *
  4591. * The |max_deflate_dynamic_table_size| is the upper bound of header
  4592. * table size the deflater will use.
  4593. *
  4594. * If this function fails, |*deflater_ptr| is left untouched.
  4595. *
  4596. * This function returns 0 if it succeeds, or one of the following
  4597. * negative error codes:
  4598. *
  4599. * :enum:`NGHTTP2_ERR_NOMEM`
  4600. * Out of memory.
  4601. */
  4602. NGHTTP2_EXTERN int
  4603. nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
  4604. size_t max_deflate_dynamic_table_size);
  4605. /**
  4606. * @function
  4607. *
  4608. * Like `nghttp2_hd_deflate_new()`, but with additional custom memory
  4609. * allocator specified in the |mem|.
  4610. *
  4611. * The |mem| can be ``NULL`` and the call is equivalent to
  4612. * `nghttp2_hd_deflate_new()`.
  4613. *
  4614. * This function does not take ownership |mem|. The application is
  4615. * responsible for freeing |mem|.
  4616. *
  4617. * The library code does not refer to |mem| pointer after this
  4618. * function returns, so the application can safely free it.
  4619. */
  4620. NGHTTP2_EXTERN int
  4621. nghttp2_hd_deflate_new2(nghttp2_hd_deflater **deflater_ptr,
  4622. size_t max_deflate_dynamic_table_size,
  4623. nghttp2_mem *mem);
  4624. /**
  4625. * @function
  4626. *
  4627. * Deallocates any resources allocated for |deflater|.
  4628. */
  4629. NGHTTP2_EXTERN void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater);
  4630. /**
  4631. * @function
  4632. *
  4633. * Changes header table size of the |deflater| to
  4634. * |settings_max_dynamic_table_size| bytes. This may trigger eviction
  4635. * in the dynamic table.
  4636. *
  4637. * The |settings_max_dynamic_table_size| should be the value received
  4638. * in SETTINGS_HEADER_TABLE_SIZE.
  4639. *
  4640. * The deflater never uses more memory than
  4641. * ``max_deflate_dynamic_table_size`` bytes specified in
  4642. * `nghttp2_hd_deflate_new()`. Therefore, if
  4643. * |settings_max_dynamic_table_size| >
  4644. * ``max_deflate_dynamic_table_size``, resulting maximum table size
  4645. * becomes ``max_deflate_dynamic_table_size``.
  4646. *
  4647. * This function returns 0 if it succeeds, or one of the following
  4648. * negative error codes:
  4649. *
  4650. * :enum:`NGHTTP2_ERR_NOMEM`
  4651. * Out of memory.
  4652. */
  4653. NGHTTP2_EXTERN int
  4654. nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,
  4655. size_t settings_max_dynamic_table_size);
  4656. /**
  4657. * @function
  4658. *
  4659. * Deflates the |nva|, which has the |nvlen| name/value pairs, into
  4660. * the |buf| of length |buflen|.
  4661. *
  4662. * If |buf| is not large enough to store the deflated header block,
  4663. * this function fails with :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`. The
  4664. * caller should use `nghttp2_hd_deflate_bound()` to know the upper
  4665. * bound of buffer size required to deflate given header name/value
  4666. * pairs.
  4667. *
  4668. * Once this function fails, subsequent call of this function always
  4669. * returns :enum:`NGHTTP2_ERR_HEADER_COMP`.
  4670. *
  4671. * After this function returns, it is safe to delete the |nva|.
  4672. *
  4673. * This function returns the number of bytes written to |buf| if it
  4674. * succeeds, or one of the following negative error codes:
  4675. *
  4676. * :enum:`NGHTTP2_ERR_NOMEM`
  4677. * Out of memory.
  4678. * :enum:`NGHTTP2_ERR_HEADER_COMP`
  4679. * Deflation process has failed.
  4680. * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`
  4681. * The provided |buflen| size is too small to hold the output.
  4682. */
  4683. NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
  4684. uint8_t *buf, size_t buflen,
  4685. const nghttp2_nv *nva,
  4686. size_t nvlen);
  4687. /**
  4688. * @function
  4689. *
  4690. * Deflates the |nva|, which has the |nvlen| name/value pairs, into
  4691. * the |veclen| size of buf vector |vec|. The each size of buffer
  4692. * must be set in len field of :type:`nghttp2_vec`. If and only if
  4693. * one chunk is filled up completely, next chunk will be used. If
  4694. * |vec| is not large enough to store the deflated header block, this
  4695. * function fails with :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller
  4696. * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
  4697. * buffer size required to deflate given header name/value pairs.
  4698. *
  4699. * Once this function fails, subsequent call of this function always
  4700. * returns :enum:`NGHTTP2_ERR_HEADER_COMP`.
  4701. *
  4702. * After this function returns, it is safe to delete the |nva|.
  4703. *
  4704. * This function returns the number of bytes written to |vec| if it
  4705. * succeeds, or one of the following negative error codes:
  4706. *
  4707. * :enum:`NGHTTP2_ERR_NOMEM`
  4708. * Out of memory.
  4709. * :enum:`NGHTTP2_ERR_HEADER_COMP`
  4710. * Deflation process has failed.
  4711. * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`
  4712. * The provided |buflen| size is too small to hold the output.
  4713. */
  4714. NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater,
  4715. const nghttp2_vec *vec,
  4716. size_t veclen,
  4717. const nghttp2_nv *nva,
  4718. size_t nvlen);
  4719. /**
  4720. * @function
  4721. *
  4722. * Returns an upper bound on the compressed size after deflation of
  4723. * |nva| of length |nvlen|.
  4724. */
  4725. NGHTTP2_EXTERN size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
  4726. const nghttp2_nv *nva,
  4727. size_t nvlen);
  4728. /**
  4729. * @function
  4730. *
  4731. * Returns the number of entries that header table of |deflater|
  4732. * contains. This is the sum of the number of static table and
  4733. * dynamic table, so the return value is at least 61.
  4734. */
  4735. NGHTTP2_EXTERN
  4736. size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater);
  4737. /**
  4738. * @function
  4739. *
  4740. * Returns the table entry denoted by |idx| from header table of
  4741. * |deflater|. The |idx| is 1-based, and idx=1 returns first entry of
  4742. * static table. idx=62 returns first entry of dynamic table if it
  4743. * exists. Specifying idx=0 is error, and this function returns NULL.
  4744. * If |idx| is strictly greater than the number of entries the tables
  4745. * contain, this function returns NULL.
  4746. */
  4747. NGHTTP2_EXTERN
  4748. const nghttp2_nv *
  4749. nghttp2_hd_deflate_get_table_entry(nghttp2_hd_deflater *deflater, size_t idx);
  4750. /**
  4751. * @function
  4752. *
  4753. * Returns the used dynamic table size, including the overhead 32
  4754. * bytes per entry described in RFC 7541.
  4755. */
  4756. NGHTTP2_EXTERN
  4757. size_t nghttp2_hd_deflate_get_dynamic_table_size(nghttp2_hd_deflater *deflater);
  4758. /**
  4759. * @function
  4760. *
  4761. * Returns the maximum dynamic table size.
  4762. */
  4763. NGHTTP2_EXTERN
  4764. size_t
  4765. nghttp2_hd_deflate_get_max_dynamic_table_size(nghttp2_hd_deflater *deflater);
  4766. struct nghttp2_hd_inflater;
  4767. /**
  4768. * @struct
  4769. *
  4770. * HPACK inflater object.
  4771. */
  4772. typedef struct nghttp2_hd_inflater nghttp2_hd_inflater;
  4773. /**
  4774. * @function
  4775. *
  4776. * Initializes |*inflater_ptr| for inflating name/values pairs.
  4777. *
  4778. * If this function fails, |*inflater_ptr| is left untouched.
  4779. *
  4780. * This function returns 0 if it succeeds, or one of the following
  4781. * negative error codes:
  4782. *
  4783. * :enum:`NGHTTP2_ERR_NOMEM`
  4784. * Out of memory.
  4785. */
  4786. NGHTTP2_EXTERN int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr);
  4787. /**
  4788. * @function
  4789. *
  4790. * Like `nghttp2_hd_inflate_new()`, but with additional custom memory
  4791. * allocator specified in the |mem|.
  4792. *
  4793. * The |mem| can be ``NULL`` and the call is equivalent to
  4794. * `nghttp2_hd_inflate_new()`.
  4795. *
  4796. * This function does not take ownership |mem|. The application is
  4797. * responsible for freeing |mem|.
  4798. *
  4799. * The library code does not refer to |mem| pointer after this
  4800. * function returns, so the application can safely free it.
  4801. */
  4802. NGHTTP2_EXTERN int nghttp2_hd_inflate_new2(nghttp2_hd_inflater **inflater_ptr,
  4803. nghttp2_mem *mem);
  4804. /**
  4805. * @function
  4806. *
  4807. * Deallocates any resources allocated for |inflater|.
  4808. */
  4809. NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater);
  4810. /**
  4811. * @function
  4812. *
  4813. * Changes header table size in the |inflater|. This may trigger
  4814. * eviction in the dynamic table.
  4815. *
  4816. * The |settings_max_dynamic_table_size| should be the value
  4817. * transmitted in SETTINGS_HEADER_TABLE_SIZE.
  4818. *
  4819. * This function must not be called while header block is being
  4820. * inflated. In other words, this function must be called after
  4821. * initialization of |inflater|, but before calling
  4822. * `nghttp2_hd_inflate_hd2()`, or after
  4823. * `nghttp2_hd_inflate_end_headers()`. Otherwise,
  4824. * `NGHTTP2_ERR_INVALID_STATE` was returned.
  4825. *
  4826. * This function returns 0 if it succeeds, or one of the following
  4827. * negative error codes:
  4828. *
  4829. * :enum:`NGHTTP2_ERR_NOMEM`
  4830. * Out of memory.
  4831. * :enum:`NGHTTP2_ERR_INVALID_STATE`
  4832. * The function is called while header block is being inflated.
  4833. * Probably, application missed to call
  4834. * `nghttp2_hd_inflate_end_headers()`.
  4835. */
  4836. NGHTTP2_EXTERN int
  4837. nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,
  4838. size_t settings_max_dynamic_table_size);
  4839. /**
  4840. * @enum
  4841. *
  4842. * The flags for header inflation.
  4843. */
  4844. typedef enum {
  4845. /**
  4846. * No flag set.
  4847. */
  4848. NGHTTP2_HD_INFLATE_NONE = 0,
  4849. /**
  4850. * Indicates all headers were inflated.
  4851. */
  4852. NGHTTP2_HD_INFLATE_FINAL = 0x01,
  4853. /**
  4854. * Indicates a header was emitted.
  4855. */
  4856. NGHTTP2_HD_INFLATE_EMIT = 0x02
  4857. } nghttp2_hd_inflate_flag;
  4858. /**
  4859. * @function
  4860. *
  4861. * .. warning::
  4862. *
  4863. * Deprecated. Use `nghttp2_hd_inflate_hd2()` instead.
  4864. *
  4865. * Inflates name/value block stored in |in| with length |inlen|. This
  4866. * function performs decompression. For each successful emission of
  4867. * header name/value pair, :enum:`NGHTTP2_HD_INFLATE_EMIT` is set in
  4868. * |*inflate_flags| and name/value pair is assigned to the |nv_out|
  4869. * and the function returns. The caller must not free the members of
  4870. * |nv_out|.
  4871. *
  4872. * The |nv_out| may include pointers to the memory region in the |in|.
  4873. * The caller must retain the |in| while the |nv_out| is used.
  4874. *
  4875. * The application should call this function repeatedly until the
  4876. * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
  4877. * return value is non-negative. This means the all input values are
  4878. * processed successfully. Then the application must call
  4879. * `nghttp2_hd_inflate_end_headers()` to prepare for the next header
  4880. * block input.
  4881. *
  4882. * The caller can feed complete compressed header block. It also can
  4883. * feed it in several chunks. The caller must set |in_final| to
  4884. * nonzero if the given input is the last block of the compressed
  4885. * header.
  4886. *
  4887. * This function returns the number of bytes processed if it succeeds,
  4888. * or one of the following negative error codes:
  4889. *
  4890. * :enum:`NGHTTP2_ERR_NOMEM`
  4891. * Out of memory.
  4892. * :enum:`NGHTTP2_ERR_HEADER_COMP`
  4893. * Inflation process has failed.
  4894. * :enum:`NGHTTP2_ERR_BUFFER_ERROR`
  4895. * The header field name or value is too large.
  4896. *
  4897. * Example follows::
  4898. *
  4899. * int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
  4900. * uint8_t *in, size_t inlen, int final)
  4901. * {
  4902. * ssize_t rv;
  4903. *
  4904. * for(;;) {
  4905. * nghttp2_nv nv;
  4906. * int inflate_flags = 0;
  4907. *
  4908. * rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags,
  4909. * in, inlen, final);
  4910. *
  4911. * if(rv < 0) {
  4912. * fprintf(stderr, "inflate failed with error code %zd", rv);
  4913. * return -1;
  4914. * }
  4915. *
  4916. * in += rv;
  4917. * inlen -= rv;
  4918. *
  4919. * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
  4920. * fwrite(nv.name, nv.namelen, 1, stderr);
  4921. * fprintf(stderr, ": ");
  4922. * fwrite(nv.value, nv.valuelen, 1, stderr);
  4923. * fprintf(stderr, "\n");
  4924. * }
  4925. * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
  4926. * nghttp2_hd_inflate_end_headers(hd_inflater);
  4927. * break;
  4928. * }
  4929. * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
  4930. * inlen == 0) {
  4931. * break;
  4932. * }
  4933. * }
  4934. *
  4935. * return 0;
  4936. * }
  4937. *
  4938. */
  4939. NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
  4940. nghttp2_nv *nv_out,
  4941. int *inflate_flags, uint8_t *in,
  4942. size_t inlen, int in_final);
  4943. /**
  4944. * @function
  4945. *
  4946. * Inflates name/value block stored in |in| with length |inlen|. This
  4947. * function performs decompression. For each successful emission of
  4948. * header name/value pair, :enum:`NGHTTP2_HD_INFLATE_EMIT` is set in
  4949. * |*inflate_flags| and name/value pair is assigned to the |nv_out|
  4950. * and the function returns. The caller must not free the members of
  4951. * |nv_out|.
  4952. *
  4953. * The |nv_out| may include pointers to the memory region in the |in|.
  4954. * The caller must retain the |in| while the |nv_out| is used.
  4955. *
  4956. * The application should call this function repeatedly until the
  4957. * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
  4958. * return value is non-negative. If that happens, all given input
  4959. * data (|inlen| bytes) are processed successfully. Then the
  4960. * application must call `nghttp2_hd_inflate_end_headers()` to prepare
  4961. * for the next header block input.
  4962. *
  4963. * In other words, if |in_final| is nonzero, and this function returns
  4964. * |inlen|, you can assert that :enum:`NGHTTP2_HD_INFLATE_FINAL` is
  4965. * set in |*inflate_flags|.
  4966. *
  4967. * The caller can feed complete compressed header block. It also can
  4968. * feed it in several chunks. The caller must set |in_final| to
  4969. * nonzero if the given input is the last block of the compressed
  4970. * header.
  4971. *
  4972. * This function returns the number of bytes processed if it succeeds,
  4973. * or one of the following negative error codes:
  4974. *
  4975. * :enum:`NGHTTP2_ERR_NOMEM`
  4976. * Out of memory.
  4977. * :enum:`NGHTTP2_ERR_HEADER_COMP`
  4978. * Inflation process has failed.
  4979. * :enum:`NGHTTP2_ERR_BUFFER_ERROR`
  4980. * The header field name or value is too large.
  4981. *
  4982. * Example follows::
  4983. *
  4984. * int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
  4985. * uint8_t *in, size_t inlen, int final)
  4986. * {
  4987. * ssize_t rv;
  4988. *
  4989. * for(;;) {
  4990. * nghttp2_nv nv;
  4991. * int inflate_flags = 0;
  4992. *
  4993. * rv = nghttp2_hd_inflate_hd2(hd_inflater, &nv, &inflate_flags,
  4994. * in, inlen, final);
  4995. *
  4996. * if(rv < 0) {
  4997. * fprintf(stderr, "inflate failed with error code %zd", rv);
  4998. * return -1;
  4999. * }
  5000. *
  5001. * in += rv;
  5002. * inlen -= rv;
  5003. *
  5004. * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
  5005. * fwrite(nv.name, nv.namelen, 1, stderr);
  5006. * fprintf(stderr, ": ");
  5007. * fwrite(nv.value, nv.valuelen, 1, stderr);
  5008. * fprintf(stderr, "\n");
  5009. * }
  5010. * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
  5011. * nghttp2_hd_inflate_end_headers(hd_inflater);
  5012. * break;
  5013. * }
  5014. * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
  5015. * inlen == 0) {
  5016. * break;
  5017. * }
  5018. * }
  5019. *
  5020. * return 0;
  5021. * }
  5022. *
  5023. */
  5024. NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater,
  5025. nghttp2_nv *nv_out,
  5026. int *inflate_flags,
  5027. const uint8_t *in, size_t inlen,
  5028. int in_final);
  5029. /**
  5030. * @function
  5031. *
  5032. * Signals the end of decompression for one header block.
  5033. *
  5034. * This function returns 0 if it succeeds. Currently this function
  5035. * always succeeds.
  5036. */
  5037. NGHTTP2_EXTERN int
  5038. nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);
  5039. /**
  5040. * @function
  5041. *
  5042. * Returns the number of entries that header table of |inflater|
  5043. * contains. This is the sum of the number of static table and
  5044. * dynamic table, so the return value is at least 61.
  5045. */
  5046. NGHTTP2_EXTERN
  5047. size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater);
  5048. /**
  5049. * @function
  5050. *
  5051. * Returns the table entry denoted by |idx| from header table of
  5052. * |inflater|. The |idx| is 1-based, and idx=1 returns first entry of
  5053. * static table. idx=62 returns first entry of dynamic table if it
  5054. * exists. Specifying idx=0 is error, and this function returns NULL.
  5055. * If |idx| is strictly greater than the number of entries the tables
  5056. * contain, this function returns NULL.
  5057. */
  5058. NGHTTP2_EXTERN
  5059. const nghttp2_nv *
  5060. nghttp2_hd_inflate_get_table_entry(nghttp2_hd_inflater *inflater, size_t idx);
  5061. /**
  5062. * @function
  5063. *
  5064. * Returns the used dynamic table size, including the overhead 32
  5065. * bytes per entry described in RFC 7541.
  5066. */
  5067. NGHTTP2_EXTERN
  5068. size_t nghttp2_hd_inflate_get_dynamic_table_size(nghttp2_hd_inflater *inflater);
  5069. /**
  5070. * @function
  5071. *
  5072. * Returns the maximum dynamic table size.
  5073. */
  5074. NGHTTP2_EXTERN
  5075. size_t
  5076. nghttp2_hd_inflate_get_max_dynamic_table_size(nghttp2_hd_inflater *inflater);
  5077. struct nghttp2_stream;
  5078. /**
  5079. * @struct
  5080. *
  5081. * The structure to represent HTTP/2 stream. The details of this
  5082. * structure are intentionally hidden from the public API.
  5083. */
  5084. typedef struct nghttp2_stream nghttp2_stream;
  5085. /**
  5086. * @function
  5087. *
  5088. * Returns pointer to :type:`nghttp2_stream` object denoted by
  5089. * |stream_id|. If stream was not found, returns NULL.
  5090. *
  5091. * Returns imaginary root stream (see
  5092. * `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|.
  5093. *
  5094. * Unless |stream_id| == 0, the returned pointer is valid until next
  5095. * call of `nghttp2_session_send()`, `nghttp2_session_mem_send()`,
  5096. * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv()`.
  5097. */
  5098. NGHTTP2_EXTERN nghttp2_stream *
  5099. nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id);
  5100. /**
  5101. * @enum
  5102. *
  5103. * State of stream as described in RFC 7540.
  5104. */
  5105. typedef enum {
  5106. /**
  5107. * idle state.
  5108. */
  5109. NGHTTP2_STREAM_STATE_IDLE = 1,
  5110. /**
  5111. * open state.
  5112. */
  5113. NGHTTP2_STREAM_STATE_OPEN,
  5114. /**
  5115. * reserved (local) state.
  5116. */
  5117. NGHTTP2_STREAM_STATE_RESERVED_LOCAL,
  5118. /**
  5119. * reserved (remote) state.
  5120. */
  5121. NGHTTP2_STREAM_STATE_RESERVED_REMOTE,
  5122. /**
  5123. * half closed (local) state.
  5124. */
  5125. NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL,
  5126. /**
  5127. * half closed (remote) state.
  5128. */
  5129. NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE,
  5130. /**
  5131. * closed state.
  5132. */
  5133. NGHTTP2_STREAM_STATE_CLOSED
  5134. } nghttp2_stream_proto_state;
  5135. /**
  5136. * @function
  5137. *
  5138. * Returns state of |stream|. The root stream retrieved by
  5139. * `nghttp2_session_get_root_stream()` will have stream state
  5140. * :enum:`NGHTTP2_STREAM_STATE_IDLE`.
  5141. */
  5142. NGHTTP2_EXTERN nghttp2_stream_proto_state
  5143. nghttp2_stream_get_state(nghttp2_stream *stream);
  5144. /**
  5145. * @function
  5146. *
  5147. * Returns root of dependency tree, which is imaginary stream with
  5148. * stream ID 0. The returned pointer is valid until |session| is
  5149. * freed by `nghttp2_session_del()`.
  5150. */
  5151. NGHTTP2_EXTERN nghttp2_stream *
  5152. nghttp2_session_get_root_stream(nghttp2_session *session);
  5153. /**
  5154. * @function
  5155. *
  5156. * Returns the parent stream of |stream| in dependency tree. Returns
  5157. * NULL if there is no such stream.
  5158. */
  5159. NGHTTP2_EXTERN nghttp2_stream *
  5160. nghttp2_stream_get_parent(nghttp2_stream *stream);
  5161. NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream);
  5162. /**
  5163. * @function
  5164. *
  5165. * Returns the next sibling stream of |stream| in dependency tree.
  5166. * Returns NULL if there is no such stream.
  5167. */
  5168. NGHTTP2_EXTERN nghttp2_stream *
  5169. nghttp2_stream_get_next_sibling(nghttp2_stream *stream);
  5170. /**
  5171. * @function
  5172. *
  5173. * Returns the previous sibling stream of |stream| in dependency tree.
  5174. * Returns NULL if there is no such stream.
  5175. */
  5176. NGHTTP2_EXTERN nghttp2_stream *
  5177. nghttp2_stream_get_previous_sibling(nghttp2_stream *stream);
  5178. /**
  5179. * @function
  5180. *
  5181. * Returns the first child stream of |stream| in dependency tree.
  5182. * Returns NULL if there is no such stream.
  5183. */
  5184. NGHTTP2_EXTERN nghttp2_stream *
  5185. nghttp2_stream_get_first_child(nghttp2_stream *stream);
  5186. /**
  5187. * @function
  5188. *
  5189. * Returns dependency weight to the parent stream of |stream|.
  5190. */
  5191. NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream);
  5192. /**
  5193. * @function
  5194. *
  5195. * Returns the sum of the weight for |stream|'s children.
  5196. */
  5197. NGHTTP2_EXTERN int32_t
  5198. nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream);
  5199. /**
  5200. * @functypedef
  5201. *
  5202. * Callback function invoked when the library outputs debug logging.
  5203. * The function is called with arguments suitable for ``vfprintf(3)``
  5204. *
  5205. * The debug output is only enabled if the library is built with
  5206. * ``DEBUGBUILD`` macro defined.
  5207. */
  5208. typedef void (*nghttp2_debug_vprintf_callback)(const char *format,
  5209. va_list args);
  5210. /**
  5211. * @function
  5212. *
  5213. * Sets a debug output callback called by the library when built with
  5214. * ``DEBUGBUILD`` macro defined. If this option is not used, debug
  5215. * log is written into standard error output.
  5216. *
  5217. * For builds without ``DEBUGBUILD`` macro defined, this function is
  5218. * noop.
  5219. *
  5220. * Note that building with ``DEBUGBUILD`` may cause significant
  5221. * performance penalty to libnghttp2 because of extra processing. It
  5222. * should be used for debugging purpose only.
  5223. *
  5224. * .. Warning::
  5225. *
  5226. * Building with ``DEBUGBUILD`` may cause significant performance
  5227. * penalty to libnghttp2 because of extra processing. It should be
  5228. * used for debugging purpose only. We write this two times because
  5229. * this is important.
  5230. */
  5231. NGHTTP2_EXTERN void nghttp2_set_debug_vprintf_callback(
  5232. nghttp2_debug_vprintf_callback debug_vprintf_callback);
  5233. #ifdef __cplusplus
  5234. }
  5235. #endif
  5236. #endif /* NGHTTP2_H */