nghttp2.h 204 KB

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