nghttp2.h 244 KB

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