test.c 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518
  1. /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to
  5. * deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  7. * sell copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  19. * IN THE SOFTWARE.
  20. */
  21. #include "http_parser.h"
  22. #include <stdlib.h>
  23. #include <assert.h>
  24. #include <stdio.h>
  25. #include <stdlib.h> /* rand */
  26. #include <string.h>
  27. #include <stdarg.h>
  28. #if defined(__APPLE__)
  29. # undef strlncpy
  30. #endif /* defined(__APPLE__) */
  31. #undef TRUE
  32. #define TRUE 1
  33. #undef FALSE
  34. #define FALSE 0
  35. #define MAX_HEADERS 13
  36. #define MAX_ELEMENT_SIZE 2048
  37. #define MAX_CHUNKS 16
  38. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  39. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
  40. static http_parser parser;
  41. struct message {
  42. const char *name; // for debugging purposes
  43. const char *raw;
  44. enum http_parser_type type;
  45. enum http_method method;
  46. int status_code;
  47. char response_status[MAX_ELEMENT_SIZE];
  48. char request_path[MAX_ELEMENT_SIZE];
  49. char request_url[MAX_ELEMENT_SIZE];
  50. char fragment[MAX_ELEMENT_SIZE];
  51. char query_string[MAX_ELEMENT_SIZE];
  52. char body[MAX_ELEMENT_SIZE];
  53. size_t body_size;
  54. const char *host;
  55. const char *userinfo;
  56. uint16_t port;
  57. int num_headers;
  58. enum { NONE=0, FIELD, VALUE } last_header_element;
  59. char headers [MAX_HEADERS][2][MAX_ELEMENT_SIZE];
  60. int should_keep_alive;
  61. int num_chunks;
  62. int num_chunks_complete;
  63. int chunk_lengths[MAX_CHUNKS];
  64. const char *upgrade; // upgraded body
  65. unsigned short http_major;
  66. unsigned short http_minor;
  67. int message_begin_cb_called;
  68. int headers_complete_cb_called;
  69. int message_complete_cb_called;
  70. int status_cb_called;
  71. int message_complete_on_eof;
  72. int body_is_final;
  73. };
  74. static int currently_parsing_eof;
  75. static struct message messages[5];
  76. static int num_messages;
  77. static http_parser_settings *current_pause_parser;
  78. /* * R E Q U E S T S * */
  79. const struct message requests[] =
  80. #define CURL_GET 0
  81. { {.name= "curl get"
  82. ,.type= HTTP_REQUEST
  83. ,.raw= "GET /test HTTP/1.1\r\n"
  84. "User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1\r\n"
  85. "Host: 0.0.0.0=5000\r\n"
  86. "Accept: */*\r\n"
  87. "\r\n"
  88. ,.should_keep_alive= TRUE
  89. ,.message_complete_on_eof= FALSE
  90. ,.http_major= 1
  91. ,.http_minor= 1
  92. ,.method= HTTP_GET
  93. ,.query_string= ""
  94. ,.fragment= ""
  95. ,.request_path= "/test"
  96. ,.request_url= "/test"
  97. ,.num_headers= 3
  98. ,.headers=
  99. { { "User-Agent", "curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1" }
  100. , { "Host", "0.0.0.0=5000" }
  101. , { "Accept", "*/*" }
  102. }
  103. ,.body= ""
  104. }
  105. #define FIREFOX_GET 1
  106. , {.name= "firefox get"
  107. ,.type= HTTP_REQUEST
  108. ,.raw= "GET /favicon.ico HTTP/1.1\r\n"
  109. "Host: 0.0.0.0=5000\r\n"
  110. "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0\r\n"
  111. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
  112. "Accept-Language: en-us,en;q=0.5\r\n"
  113. "Accept-Encoding: gzip,deflate\r\n"
  114. "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"
  115. "Keep-Alive: 300\r\n"
  116. "Connection: keep-alive\r\n"
  117. "\r\n"
  118. ,.should_keep_alive= TRUE
  119. ,.message_complete_on_eof= FALSE
  120. ,.http_major= 1
  121. ,.http_minor= 1
  122. ,.method= HTTP_GET
  123. ,.query_string= ""
  124. ,.fragment= ""
  125. ,.request_path= "/favicon.ico"
  126. ,.request_url= "/favicon.ico"
  127. ,.num_headers= 8
  128. ,.headers=
  129. { { "Host", "0.0.0.0=5000" }
  130. , { "User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0" }
  131. , { "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" }
  132. , { "Accept-Language", "en-us,en;q=0.5" }
  133. , { "Accept-Encoding", "gzip,deflate" }
  134. , { "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7" }
  135. , { "Keep-Alive", "300" }
  136. , { "Connection", "keep-alive" }
  137. }
  138. ,.body= ""
  139. }
  140. #define DUMBLUCK 2
  141. , {.name= "dumbluck"
  142. ,.type= HTTP_REQUEST
  143. ,.raw= "GET /dumbluck HTTP/1.1\r\n"
  144. "aaaaaaaaaaaaa:++++++++++\r\n"
  145. "\r\n"
  146. ,.should_keep_alive= TRUE
  147. ,.message_complete_on_eof= FALSE
  148. ,.http_major= 1
  149. ,.http_minor= 1
  150. ,.method= HTTP_GET
  151. ,.query_string= ""
  152. ,.fragment= ""
  153. ,.request_path= "/dumbluck"
  154. ,.request_url= "/dumbluck"
  155. ,.num_headers= 1
  156. ,.headers=
  157. { { "aaaaaaaaaaaaa", "++++++++++" }
  158. }
  159. ,.body= ""
  160. }
  161. #define FRAGMENT_IN_URI 3
  162. , {.name= "fragment in url"
  163. ,.type= HTTP_REQUEST
  164. ,.raw= "GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1\r\n"
  165. "\r\n"
  166. ,.should_keep_alive= TRUE
  167. ,.message_complete_on_eof= FALSE
  168. ,.http_major= 1
  169. ,.http_minor= 1
  170. ,.method= HTTP_GET
  171. ,.query_string= "page=1"
  172. ,.fragment= "posts-17408"
  173. ,.request_path= "/forums/1/topics/2375"
  174. /* XXX request url does include fragment? */
  175. ,.request_url= "/forums/1/topics/2375?page=1#posts-17408"
  176. ,.num_headers= 0
  177. ,.body= ""
  178. }
  179. #define GET_NO_HEADERS_NO_BODY 4
  180. , {.name= "get no headers no body"
  181. ,.type= HTTP_REQUEST
  182. ,.raw= "GET /get_no_headers_no_body/world HTTP/1.1\r\n"
  183. "\r\n"
  184. ,.should_keep_alive= TRUE
  185. ,.message_complete_on_eof= FALSE /* would need Connection: close */
  186. ,.http_major= 1
  187. ,.http_minor= 1
  188. ,.method= HTTP_GET
  189. ,.query_string= ""
  190. ,.fragment= ""
  191. ,.request_path= "/get_no_headers_no_body/world"
  192. ,.request_url= "/get_no_headers_no_body/world"
  193. ,.num_headers= 0
  194. ,.body= ""
  195. }
  196. #define GET_ONE_HEADER_NO_BODY 5
  197. , {.name= "get one header no body"
  198. ,.type= HTTP_REQUEST
  199. ,.raw= "GET /get_one_header_no_body HTTP/1.1\r\n"
  200. "Accept: */*\r\n"
  201. "\r\n"
  202. ,.should_keep_alive= TRUE
  203. ,.message_complete_on_eof= FALSE /* would need Connection: close */
  204. ,.http_major= 1
  205. ,.http_minor= 1
  206. ,.method= HTTP_GET
  207. ,.query_string= ""
  208. ,.fragment= ""
  209. ,.request_path= "/get_one_header_no_body"
  210. ,.request_url= "/get_one_header_no_body"
  211. ,.num_headers= 1
  212. ,.headers=
  213. { { "Accept" , "*/*" }
  214. }
  215. ,.body= ""
  216. }
  217. #define GET_FUNKY_CONTENT_LENGTH 6
  218. , {.name= "get funky content length body hello"
  219. ,.type= HTTP_REQUEST
  220. ,.raw= "GET /get_funky_content_length_body_hello HTTP/1.0\r\n"
  221. "conTENT-Length: 5\r\n"
  222. "\r\n"
  223. "HELLO"
  224. ,.should_keep_alive= FALSE
  225. ,.message_complete_on_eof= FALSE
  226. ,.http_major= 1
  227. ,.http_minor= 0
  228. ,.method= HTTP_GET
  229. ,.query_string= ""
  230. ,.fragment= ""
  231. ,.request_path= "/get_funky_content_length_body_hello"
  232. ,.request_url= "/get_funky_content_length_body_hello"
  233. ,.num_headers= 1
  234. ,.headers=
  235. { { "conTENT-Length" , "5" }
  236. }
  237. ,.body= "HELLO"
  238. }
  239. #define POST_IDENTITY_BODY_WORLD 7
  240. , {.name= "post identity body world"
  241. ,.type= HTTP_REQUEST
  242. ,.raw= "POST /post_identity_body_world?q=search#hey HTTP/1.1\r\n"
  243. "Accept: */*\r\n"
  244. "Transfer-Encoding: identity\r\n"
  245. "Content-Length: 5\r\n"
  246. "\r\n"
  247. "World"
  248. ,.should_keep_alive= TRUE
  249. ,.message_complete_on_eof= FALSE
  250. ,.http_major= 1
  251. ,.http_minor= 1
  252. ,.method= HTTP_POST
  253. ,.query_string= "q=search"
  254. ,.fragment= "hey"
  255. ,.request_path= "/post_identity_body_world"
  256. ,.request_url= "/post_identity_body_world?q=search#hey"
  257. ,.num_headers= 3
  258. ,.headers=
  259. { { "Accept", "*/*" }
  260. , { "Transfer-Encoding", "identity" }
  261. , { "Content-Length", "5" }
  262. }
  263. ,.body= "World"
  264. }
  265. #define POST_CHUNKED_ALL_YOUR_BASE 8
  266. , {.name= "post - chunked body: all your base are belong to us"
  267. ,.type= HTTP_REQUEST
  268. ,.raw= "POST /post_chunked_all_your_base HTTP/1.1\r\n"
  269. "Transfer-Encoding: chunked\r\n"
  270. "\r\n"
  271. "1e\r\nall your base are belong to us\r\n"
  272. "0\r\n"
  273. "\r\n"
  274. ,.should_keep_alive= TRUE
  275. ,.message_complete_on_eof= FALSE
  276. ,.http_major= 1
  277. ,.http_minor= 1
  278. ,.method= HTTP_POST
  279. ,.query_string= ""
  280. ,.fragment= ""
  281. ,.request_path= "/post_chunked_all_your_base"
  282. ,.request_url= "/post_chunked_all_your_base"
  283. ,.num_headers= 1
  284. ,.headers=
  285. { { "Transfer-Encoding" , "chunked" }
  286. }
  287. ,.body= "all your base are belong to us"
  288. ,.num_chunks_complete= 2
  289. ,.chunk_lengths= { 0x1e }
  290. }
  291. #define TWO_CHUNKS_MULT_ZERO_END 9
  292. , {.name= "two chunks ; triple zero ending"
  293. ,.type= HTTP_REQUEST
  294. ,.raw= "POST /two_chunks_mult_zero_end HTTP/1.1\r\n"
  295. "Transfer-Encoding: chunked\r\n"
  296. "\r\n"
  297. "5\r\nhello\r\n"
  298. "6\r\n world\r\n"
  299. "000\r\n"
  300. "\r\n"
  301. ,.should_keep_alive= TRUE
  302. ,.message_complete_on_eof= FALSE
  303. ,.http_major= 1
  304. ,.http_minor= 1
  305. ,.method= HTTP_POST
  306. ,.query_string= ""
  307. ,.fragment= ""
  308. ,.request_path= "/two_chunks_mult_zero_end"
  309. ,.request_url= "/two_chunks_mult_zero_end"
  310. ,.num_headers= 1
  311. ,.headers=
  312. { { "Transfer-Encoding", "chunked" }
  313. }
  314. ,.body= "hello world"
  315. ,.num_chunks_complete= 3
  316. ,.chunk_lengths= { 5, 6 }
  317. }
  318. #define CHUNKED_W_TRAILING_HEADERS 10
  319. , {.name= "chunked with trailing headers. blech."
  320. ,.type= HTTP_REQUEST
  321. ,.raw= "POST /chunked_w_trailing_headers HTTP/1.1\r\n"
  322. "Transfer-Encoding: chunked\r\n"
  323. "\r\n"
  324. "5\r\nhello\r\n"
  325. "6\r\n world\r\n"
  326. "0\r\n"
  327. "Vary: *\r\n"
  328. "Content-Type: text/plain\r\n"
  329. "\r\n"
  330. ,.should_keep_alive= TRUE
  331. ,.message_complete_on_eof= FALSE
  332. ,.http_major= 1
  333. ,.http_minor= 1
  334. ,.method= HTTP_POST
  335. ,.query_string= ""
  336. ,.fragment= ""
  337. ,.request_path= "/chunked_w_trailing_headers"
  338. ,.request_url= "/chunked_w_trailing_headers"
  339. ,.num_headers= 3
  340. ,.headers=
  341. { { "Transfer-Encoding", "chunked" }
  342. , { "Vary", "*" }
  343. , { "Content-Type", "text/plain" }
  344. }
  345. ,.body= "hello world"
  346. ,.num_chunks_complete= 3
  347. ,.chunk_lengths= { 5, 6 }
  348. }
  349. #define CHUNKED_W_NONSENSE_AFTER_LENGTH 11
  350. , {.name= "with nonsense after the length"
  351. ,.type= HTTP_REQUEST
  352. ,.raw= "POST /chunked_w_nonsense_after_length HTTP/1.1\r\n"
  353. "Transfer-Encoding: chunked\r\n"
  354. "\r\n"
  355. "5; ilovew3;whattheluck=aretheseparametersfor\r\nhello\r\n"
  356. "6; blahblah; blah\r\n world\r\n"
  357. "0\r\n"
  358. "\r\n"
  359. ,.should_keep_alive= TRUE
  360. ,.message_complete_on_eof= FALSE
  361. ,.http_major= 1
  362. ,.http_minor= 1
  363. ,.method= HTTP_POST
  364. ,.query_string= ""
  365. ,.fragment= ""
  366. ,.request_path= "/chunked_w_nonsense_after_length"
  367. ,.request_url= "/chunked_w_nonsense_after_length"
  368. ,.num_headers= 1
  369. ,.headers=
  370. { { "Transfer-Encoding", "chunked" }
  371. }
  372. ,.body= "hello world"
  373. ,.num_chunks_complete= 3
  374. ,.chunk_lengths= { 5, 6 }
  375. }
  376. #define WITH_QUOTES 12
  377. , {.name= "with quotes"
  378. ,.type= HTTP_REQUEST
  379. ,.raw= "GET /with_\"stupid\"_quotes?foo=\"bar\" HTTP/1.1\r\n\r\n"
  380. ,.should_keep_alive= TRUE
  381. ,.message_complete_on_eof= FALSE
  382. ,.http_major= 1
  383. ,.http_minor= 1
  384. ,.method= HTTP_GET
  385. ,.query_string= "foo=\"bar\""
  386. ,.fragment= ""
  387. ,.request_path= "/with_\"stupid\"_quotes"
  388. ,.request_url= "/with_\"stupid\"_quotes?foo=\"bar\""
  389. ,.num_headers= 0
  390. ,.headers= { }
  391. ,.body= ""
  392. }
  393. #define APACHEBENCH_GET 13
  394. /* The server receiving this request SHOULD NOT wait for EOF
  395. * to know that content-length == 0.
  396. * How to represent this in a unit test? message_complete_on_eof
  397. * Compare with NO_CONTENT_LENGTH_RESPONSE.
  398. */
  399. , {.name = "apachebench get"
  400. ,.type= HTTP_REQUEST
  401. ,.raw= "GET /test HTTP/1.0\r\n"
  402. "Host: 0.0.0.0:5000\r\n"
  403. "User-Agent: ApacheBench/2.3\r\n"
  404. "Accept: */*\r\n\r\n"
  405. ,.should_keep_alive= FALSE
  406. ,.message_complete_on_eof= FALSE
  407. ,.http_major= 1
  408. ,.http_minor= 0
  409. ,.method= HTTP_GET
  410. ,.query_string= ""
  411. ,.fragment= ""
  412. ,.request_path= "/test"
  413. ,.request_url= "/test"
  414. ,.num_headers= 3
  415. ,.headers= { { "Host", "0.0.0.0:5000" }
  416. , { "User-Agent", "ApacheBench/2.3" }
  417. , { "Accept", "*/*" }
  418. }
  419. ,.body= ""
  420. }
  421. #define QUERY_URL_WITH_QUESTION_MARK_GET 14
  422. /* Some clients include '?' characters in query strings.
  423. */
  424. , {.name = "query url with question mark"
  425. ,.type= HTTP_REQUEST
  426. ,.raw= "GET /test.cgi?foo=bar?baz HTTP/1.1\r\n\r\n"
  427. ,.should_keep_alive= TRUE
  428. ,.message_complete_on_eof= FALSE
  429. ,.http_major= 1
  430. ,.http_minor= 1
  431. ,.method= HTTP_GET
  432. ,.query_string= "foo=bar?baz"
  433. ,.fragment= ""
  434. ,.request_path= "/test.cgi"
  435. ,.request_url= "/test.cgi?foo=bar?baz"
  436. ,.num_headers= 0
  437. ,.headers= {}
  438. ,.body= ""
  439. }
  440. #define PREFIX_NEWLINE_GET 15
  441. /* Some clients, especially after a POST in a keep-alive connection,
  442. * will send an extra CRLF before the next request
  443. */
  444. , {.name = "newline prefix get"
  445. ,.type= HTTP_REQUEST
  446. ,.raw= "\r\nGET /test HTTP/1.1\r\n\r\n"
  447. ,.should_keep_alive= TRUE
  448. ,.message_complete_on_eof= FALSE
  449. ,.http_major= 1
  450. ,.http_minor= 1
  451. ,.method= HTTP_GET
  452. ,.query_string= ""
  453. ,.fragment= ""
  454. ,.request_path= "/test"
  455. ,.request_url= "/test"
  456. ,.num_headers= 0
  457. ,.headers= { }
  458. ,.body= ""
  459. }
  460. #define UPGRADE_REQUEST 16
  461. , {.name = "upgrade request"
  462. ,.type= HTTP_REQUEST
  463. ,.raw= "GET /demo HTTP/1.1\r\n"
  464. "Host: example.com\r\n"
  465. "Connection: Upgrade\r\n"
  466. "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n"
  467. "Sec-WebSocket-Protocol: sample\r\n"
  468. "Upgrade: WebSocket\r\n"
  469. "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n"
  470. "Origin: http://example.com\r\n"
  471. "\r\n"
  472. "Hot diggity dogg"
  473. ,.should_keep_alive= TRUE
  474. ,.message_complete_on_eof= FALSE
  475. ,.http_major= 1
  476. ,.http_minor= 1
  477. ,.method= HTTP_GET
  478. ,.query_string= ""
  479. ,.fragment= ""
  480. ,.request_path= "/demo"
  481. ,.request_url= "/demo"
  482. ,.num_headers= 7
  483. ,.upgrade="Hot diggity dogg"
  484. ,.headers= { { "Host", "example.com" }
  485. , { "Connection", "Upgrade" }
  486. , { "Sec-WebSocket-Key2", "12998 5 Y3 1 .P00" }
  487. , { "Sec-WebSocket-Protocol", "sample" }
  488. , { "Upgrade", "WebSocket" }
  489. , { "Sec-WebSocket-Key1", "4 @1 46546xW%0l 1 5" }
  490. , { "Origin", "http://example.com" }
  491. }
  492. ,.body= ""
  493. }
  494. #define CONNECT_REQUEST 17
  495. , {.name = "connect request"
  496. ,.type= HTTP_REQUEST
  497. ,.raw= "CONNECT 0-home0.netscape.com:443 HTTP/1.0\r\n"
  498. "User-agent: Mozilla/1.1N\r\n"
  499. "Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n"
  500. "\r\n"
  501. "some data\r\n"
  502. "and yet even more data"
  503. ,.should_keep_alive= FALSE
  504. ,.message_complete_on_eof= FALSE
  505. ,.http_major= 1
  506. ,.http_minor= 0
  507. ,.method= HTTP_CONNECT
  508. ,.query_string= ""
  509. ,.fragment= ""
  510. ,.request_path= ""
  511. ,.request_url= "0-home0.netscape.com:443"
  512. ,.num_headers= 2
  513. ,.upgrade="some data\r\nand yet even more data"
  514. ,.headers= { { "User-agent", "Mozilla/1.1N" }
  515. , { "Proxy-authorization", "basic aGVsbG86d29ybGQ=" }
  516. }
  517. ,.body= ""
  518. }
  519. #define REPORT_REQ 18
  520. , {.name= "report request"
  521. ,.type= HTTP_REQUEST
  522. ,.raw= "REPORT /test HTTP/1.1\r\n"
  523. "\r\n"
  524. ,.should_keep_alive= TRUE
  525. ,.message_complete_on_eof= FALSE
  526. ,.http_major= 1
  527. ,.http_minor= 1
  528. ,.method= HTTP_REPORT
  529. ,.query_string= ""
  530. ,.fragment= ""
  531. ,.request_path= "/test"
  532. ,.request_url= "/test"
  533. ,.num_headers= 0
  534. ,.headers= {}
  535. ,.body= ""
  536. }
  537. #define NO_HTTP_VERSION 19
  538. , {.name= "request with no http version"
  539. ,.type= HTTP_REQUEST
  540. ,.raw= "GET /\r\n"
  541. "\r\n"
  542. ,.should_keep_alive= FALSE
  543. ,.message_complete_on_eof= FALSE
  544. ,.http_major= 0
  545. ,.http_minor= 9
  546. ,.method= HTTP_GET
  547. ,.query_string= ""
  548. ,.fragment= ""
  549. ,.request_path= "/"
  550. ,.request_url= "/"
  551. ,.num_headers= 0
  552. ,.headers= {}
  553. ,.body= ""
  554. }
  555. #define MSEARCH_REQ 20
  556. , {.name= "m-search request"
  557. ,.type= HTTP_REQUEST
  558. ,.raw= "M-SEARCH * HTTP/1.1\r\n"
  559. "HOST: 239.255.255.250:1900\r\n"
  560. "MAN: \"ssdp:discover\"\r\n"
  561. "ST: \"ssdp:all\"\r\n"
  562. "\r\n"
  563. ,.should_keep_alive= TRUE
  564. ,.message_complete_on_eof= FALSE
  565. ,.http_major= 1
  566. ,.http_minor= 1
  567. ,.method= HTTP_MSEARCH
  568. ,.query_string= ""
  569. ,.fragment= ""
  570. ,.request_path= "*"
  571. ,.request_url= "*"
  572. ,.num_headers= 3
  573. ,.headers= { { "HOST", "239.255.255.250:1900" }
  574. , { "MAN", "\"ssdp:discover\"" }
  575. , { "ST", "\"ssdp:all\"" }
  576. }
  577. ,.body= ""
  578. }
  579. #define LINE_FOLDING_IN_HEADER 21
  580. , {.name= "line folding in header value"
  581. ,.type= HTTP_REQUEST
  582. ,.raw= "GET / HTTP/1.1\r\n"
  583. "Line1: abc\r\n"
  584. "\tdef\r\n"
  585. " ghi\r\n"
  586. "\t\tjkl\r\n"
  587. " mno \r\n"
  588. "\t \tqrs\r\n"
  589. "Line2: \t line2\t\r\n"
  590. "Line3:\r\n"
  591. " line3\r\n"
  592. "Line4: \r\n"
  593. " \r\n"
  594. "Connection:\r\n"
  595. " close\r\n"
  596. "\r\n"
  597. ,.should_keep_alive= FALSE
  598. ,.message_complete_on_eof= FALSE
  599. ,.http_major= 1
  600. ,.http_minor= 1
  601. ,.method= HTTP_GET
  602. ,.query_string= ""
  603. ,.fragment= ""
  604. ,.request_path= "/"
  605. ,.request_url= "/"
  606. ,.num_headers= 5
  607. ,.headers= { { "Line1", "abc\tdef ghi\t\tjkl mno \t \tqrs" }
  608. , { "Line2", "line2\t" }
  609. , { "Line3", "line3" }
  610. , { "Line4", "" }
  611. , { "Connection", "close" },
  612. }
  613. ,.body= ""
  614. }
  615. #define QUERY_TERMINATED_HOST 22
  616. , {.name= "host terminated by a query string"
  617. ,.type= HTTP_REQUEST
  618. ,.raw= "GET http://hypnotoad.org?hail=all HTTP/1.1\r\n"
  619. "\r\n"
  620. ,.should_keep_alive= TRUE
  621. ,.message_complete_on_eof= FALSE
  622. ,.http_major= 1
  623. ,.http_minor= 1
  624. ,.method= HTTP_GET
  625. ,.query_string= "hail=all"
  626. ,.fragment= ""
  627. ,.request_path= ""
  628. ,.request_url= "http://hypnotoad.org?hail=all"
  629. ,.host= "hypnotoad.org"
  630. ,.num_headers= 0
  631. ,.headers= { }
  632. ,.body= ""
  633. }
  634. #define QUERY_TERMINATED_HOSTPORT 23
  635. , {.name= "host:port terminated by a query string"
  636. ,.type= HTTP_REQUEST
  637. ,.raw= "GET http://hypnotoad.org:1234?hail=all HTTP/1.1\r\n"
  638. "\r\n"
  639. ,.should_keep_alive= TRUE
  640. ,.message_complete_on_eof= FALSE
  641. ,.http_major= 1
  642. ,.http_minor= 1
  643. ,.method= HTTP_GET
  644. ,.query_string= "hail=all"
  645. ,.fragment= ""
  646. ,.request_path= ""
  647. ,.request_url= "http://hypnotoad.org:1234?hail=all"
  648. ,.host= "hypnotoad.org"
  649. ,.port= 1234
  650. ,.num_headers= 0
  651. ,.headers= { }
  652. ,.body= ""
  653. }
  654. #define SPACE_TERMINATED_HOSTPORT 24
  655. , {.name= "host:port terminated by a space"
  656. ,.type= HTTP_REQUEST
  657. ,.raw= "GET http://hypnotoad.org:1234 HTTP/1.1\r\n"
  658. "\r\n"
  659. ,.should_keep_alive= TRUE
  660. ,.message_complete_on_eof= FALSE
  661. ,.http_major= 1
  662. ,.http_minor= 1
  663. ,.method= HTTP_GET
  664. ,.query_string= ""
  665. ,.fragment= ""
  666. ,.request_path= ""
  667. ,.request_url= "http://hypnotoad.org:1234"
  668. ,.host= "hypnotoad.org"
  669. ,.port= 1234
  670. ,.num_headers= 0
  671. ,.headers= { }
  672. ,.body= ""
  673. }
  674. #define PATCH_REQ 25
  675. , {.name = "PATCH request"
  676. ,.type= HTTP_REQUEST
  677. ,.raw= "PATCH /file.txt HTTP/1.1\r\n"
  678. "Host: www.example.com\r\n"
  679. "Content-Type: application/example\r\n"
  680. "If-Match: \"e0023aa4e\"\r\n"
  681. "Content-Length: 10\r\n"
  682. "\r\n"
  683. "cccccccccc"
  684. ,.should_keep_alive= TRUE
  685. ,.message_complete_on_eof= FALSE
  686. ,.http_major= 1
  687. ,.http_minor= 1
  688. ,.method= HTTP_PATCH
  689. ,.query_string= ""
  690. ,.fragment= ""
  691. ,.request_path= "/file.txt"
  692. ,.request_url= "/file.txt"
  693. ,.num_headers= 4
  694. ,.headers= { { "Host", "www.example.com" }
  695. , { "Content-Type", "application/example" }
  696. , { "If-Match", "\"e0023aa4e\"" }
  697. , { "Content-Length", "10" }
  698. }
  699. ,.body= "cccccccccc"
  700. }
  701. #define CONNECT_CAPS_REQUEST 26
  702. , {.name = "connect caps request"
  703. ,.type= HTTP_REQUEST
  704. ,.raw= "CONNECT HOME0.NETSCAPE.COM:443 HTTP/1.0\r\n"
  705. "User-agent: Mozilla/1.1N\r\n"
  706. "Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n"
  707. "\r\n"
  708. ,.should_keep_alive= FALSE
  709. ,.message_complete_on_eof= FALSE
  710. ,.http_major= 1
  711. ,.http_minor= 0
  712. ,.method= HTTP_CONNECT
  713. ,.query_string= ""
  714. ,.fragment= ""
  715. ,.request_path= ""
  716. ,.request_url= "HOME0.NETSCAPE.COM:443"
  717. ,.num_headers= 2
  718. ,.upgrade=""
  719. ,.headers= { { "User-agent", "Mozilla/1.1N" }
  720. , { "Proxy-authorization", "basic aGVsbG86d29ybGQ=" }
  721. }
  722. ,.body= ""
  723. }
  724. #if !HTTP_PARSER_STRICT
  725. #define UTF8_PATH_REQ 27
  726. , {.name= "utf-8 path request"
  727. ,.type= HTTP_REQUEST
  728. ,.raw= "GET /δ¶/δt/pope?q=1#narf HTTP/1.1\r\n"
  729. "Host: github.com\r\n"
  730. "\r\n"
  731. ,.should_keep_alive= TRUE
  732. ,.message_complete_on_eof= FALSE
  733. ,.http_major= 1
  734. ,.http_minor= 1
  735. ,.method= HTTP_GET
  736. ,.query_string= "q=1"
  737. ,.fragment= "narf"
  738. ,.request_path= "/δ¶/δt/pope"
  739. ,.request_url= "/δ¶/δt/pope?q=1#narf"
  740. ,.num_headers= 1
  741. ,.headers= { {"Host", "github.com" }
  742. }
  743. ,.body= ""
  744. }
  745. #define HOSTNAME_UNDERSCORE 28
  746. , {.name = "hostname underscore"
  747. ,.type= HTTP_REQUEST
  748. ,.raw= "CONNECT home_0.netscape.com:443 HTTP/1.0\r\n"
  749. "User-agent: Mozilla/1.1N\r\n"
  750. "Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n"
  751. "\r\n"
  752. ,.should_keep_alive= FALSE
  753. ,.message_complete_on_eof= FALSE
  754. ,.http_major= 1
  755. ,.http_minor= 0
  756. ,.method= HTTP_CONNECT
  757. ,.query_string= ""
  758. ,.fragment= ""
  759. ,.request_path= ""
  760. ,.request_url= "home_0.netscape.com:443"
  761. ,.num_headers= 2
  762. ,.upgrade=""
  763. ,.headers= { { "User-agent", "Mozilla/1.1N" }
  764. , { "Proxy-authorization", "basic aGVsbG86d29ybGQ=" }
  765. }
  766. ,.body= ""
  767. }
  768. #endif /* !HTTP_PARSER_STRICT */
  769. /* see https://github.com/ry/http-parser/issues/47 */
  770. #define EAT_TRAILING_CRLF_NO_CONNECTION_CLOSE 29
  771. , {.name = "eat CRLF between requests, no \"Connection: close\" header"
  772. ,.raw= "POST / HTTP/1.1\r\n"
  773. "Host: www.example.com\r\n"
  774. "Content-Type: application/x-www-form-urlencoded\r\n"
  775. "Content-Length: 4\r\n"
  776. "\r\n"
  777. "q=42\r\n" /* note the trailing CRLF */
  778. ,.should_keep_alive= TRUE
  779. ,.message_complete_on_eof= FALSE
  780. ,.http_major= 1
  781. ,.http_minor= 1
  782. ,.method= HTTP_POST
  783. ,.query_string= ""
  784. ,.fragment= ""
  785. ,.request_path= "/"
  786. ,.request_url= "/"
  787. ,.num_headers= 3
  788. ,.upgrade= 0
  789. ,.headers= { { "Host", "www.example.com" }
  790. , { "Content-Type", "application/x-www-form-urlencoded" }
  791. , { "Content-Length", "4" }
  792. }
  793. ,.body= "q=42"
  794. }
  795. /* see https://github.com/ry/http-parser/issues/47 */
  796. #define EAT_TRAILING_CRLF_WITH_CONNECTION_CLOSE 30
  797. , {.name = "eat CRLF between requests even if \"Connection: close\" is set"
  798. ,.raw= "POST / HTTP/1.1\r\n"
  799. "Host: www.example.com\r\n"
  800. "Content-Type: application/x-www-form-urlencoded\r\n"
  801. "Content-Length: 4\r\n"
  802. "Connection: close\r\n"
  803. "\r\n"
  804. "q=42\r\n" /* note the trailing CRLF */
  805. ,.should_keep_alive= FALSE
  806. ,.message_complete_on_eof= FALSE /* input buffer isn't empty when on_message_complete is called */
  807. ,.http_major= 1
  808. ,.http_minor= 1
  809. ,.method= HTTP_POST
  810. ,.query_string= ""
  811. ,.fragment= ""
  812. ,.request_path= "/"
  813. ,.request_url= "/"
  814. ,.num_headers= 4
  815. ,.upgrade= 0
  816. ,.headers= { { "Host", "www.example.com" }
  817. , { "Content-Type", "application/x-www-form-urlencoded" }
  818. , { "Content-Length", "4" }
  819. , { "Connection", "close" }
  820. }
  821. ,.body= "q=42"
  822. }
  823. #define PURGE_REQ 31
  824. , {.name = "PURGE request"
  825. ,.type= HTTP_REQUEST
  826. ,.raw= "PURGE /file.txt HTTP/1.1\r\n"
  827. "Host: www.example.com\r\n"
  828. "\r\n"
  829. ,.should_keep_alive= TRUE
  830. ,.message_complete_on_eof= FALSE
  831. ,.http_major= 1
  832. ,.http_minor= 1
  833. ,.method= HTTP_PURGE
  834. ,.query_string= ""
  835. ,.fragment= ""
  836. ,.request_path= "/file.txt"
  837. ,.request_url= "/file.txt"
  838. ,.num_headers= 1
  839. ,.headers= { { "Host", "www.example.com" } }
  840. ,.body= ""
  841. }
  842. #define SEARCH_REQ 32
  843. , {.name = "SEARCH request"
  844. ,.type= HTTP_REQUEST
  845. ,.raw= "SEARCH / HTTP/1.1\r\n"
  846. "Host: www.example.com\r\n"
  847. "\r\n"
  848. ,.should_keep_alive= TRUE
  849. ,.message_complete_on_eof= FALSE
  850. ,.http_major= 1
  851. ,.http_minor= 1
  852. ,.method= HTTP_SEARCH
  853. ,.query_string= ""
  854. ,.fragment= ""
  855. ,.request_path= "/"
  856. ,.request_url= "/"
  857. ,.num_headers= 1
  858. ,.headers= { { "Host", "www.example.com" } }
  859. ,.body= ""
  860. }
  861. #define PROXY_WITH_BASIC_AUTH 33
  862. , {.name= "host:port and basic_auth"
  863. ,.type= HTTP_REQUEST
  864. ,.raw= "GET http://a%12:b!&*$@hypnotoad.org:1234/toto HTTP/1.1\r\n"
  865. "\r\n"
  866. ,.should_keep_alive= TRUE
  867. ,.message_complete_on_eof= FALSE
  868. ,.http_major= 1
  869. ,.http_minor= 1
  870. ,.method= HTTP_GET
  871. ,.fragment= ""
  872. ,.request_path= "/toto"
  873. ,.request_url= "http://a%12:b!&*$@hypnotoad.org:1234/toto"
  874. ,.host= "hypnotoad.org"
  875. ,.userinfo= "a%12:b!&*$"
  876. ,.port= 1234
  877. ,.num_headers= 0
  878. ,.headers= { }
  879. ,.body= ""
  880. }
  881. #define LINE_FOLDING_IN_HEADER_WITH_LF 34
  882. , {.name= "line folding in header value"
  883. ,.type= HTTP_REQUEST
  884. ,.raw= "GET / HTTP/1.1\n"
  885. "Line1: abc\n"
  886. "\tdef\n"
  887. " ghi\n"
  888. "\t\tjkl\n"
  889. " mno \n"
  890. "\t \tqrs\n"
  891. "Line2: \t line2\t\n"
  892. "Line3:\n"
  893. " line3\n"
  894. "Line4: \n"
  895. " \n"
  896. "Connection:\n"
  897. " close\n"
  898. "\n"
  899. ,.should_keep_alive= FALSE
  900. ,.message_complete_on_eof= FALSE
  901. ,.http_major= 1
  902. ,.http_minor= 1
  903. ,.method= HTTP_GET
  904. ,.query_string= ""
  905. ,.fragment= ""
  906. ,.request_path= "/"
  907. ,.request_url= "/"
  908. ,.num_headers= 5
  909. ,.headers= { { "Line1", "abc\tdef ghi\t\tjkl mno \t \tqrs" }
  910. , { "Line2", "line2\t" }
  911. , { "Line3", "line3" }
  912. , { "Line4", "" }
  913. , { "Connection", "close" },
  914. }
  915. ,.body= ""
  916. }
  917. #define CONNECTION_MULTI 35
  918. , {.name = "multiple connection header values with folding"
  919. ,.type= HTTP_REQUEST
  920. ,.raw= "GET /demo HTTP/1.1\r\n"
  921. "Host: example.com\r\n"
  922. "Connection: Something,\r\n"
  923. " Upgrade, ,Keep-Alive\r\n"
  924. "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n"
  925. "Sec-WebSocket-Protocol: sample\r\n"
  926. "Upgrade: WebSocket\r\n"
  927. "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n"
  928. "Origin: http://example.com\r\n"
  929. "\r\n"
  930. "Hot diggity dogg"
  931. ,.should_keep_alive= TRUE
  932. ,.message_complete_on_eof= FALSE
  933. ,.http_major= 1
  934. ,.http_minor= 1
  935. ,.method= HTTP_GET
  936. ,.query_string= ""
  937. ,.fragment= ""
  938. ,.request_path= "/demo"
  939. ,.request_url= "/demo"
  940. ,.num_headers= 7
  941. ,.upgrade="Hot diggity dogg"
  942. ,.headers= { { "Host", "example.com" }
  943. , { "Connection", "Something, Upgrade, ,Keep-Alive" }
  944. , { "Sec-WebSocket-Key2", "12998 5 Y3 1 .P00" }
  945. , { "Sec-WebSocket-Protocol", "sample" }
  946. , { "Upgrade", "WebSocket" }
  947. , { "Sec-WebSocket-Key1", "4 @1 46546xW%0l 1 5" }
  948. , { "Origin", "http://example.com" }
  949. }
  950. ,.body= ""
  951. }
  952. #define CONNECTION_MULTI_LWS 36
  953. , {.name = "multiple connection header values with folding and lws"
  954. ,.type= HTTP_REQUEST
  955. ,.raw= "GET /demo HTTP/1.1\r\n"
  956. "Connection: keep-alive, upgrade\r\n"
  957. "Upgrade: WebSocket\r\n"
  958. "\r\n"
  959. "Hot diggity dogg"
  960. ,.should_keep_alive= TRUE
  961. ,.message_complete_on_eof= FALSE
  962. ,.http_major= 1
  963. ,.http_minor= 1
  964. ,.method= HTTP_GET
  965. ,.query_string= ""
  966. ,.fragment= ""
  967. ,.request_path= "/demo"
  968. ,.request_url= "/demo"
  969. ,.num_headers= 2
  970. ,.upgrade="Hot diggity dogg"
  971. ,.headers= { { "Connection", "keep-alive, upgrade" }
  972. , { "Upgrade", "WebSocket" }
  973. }
  974. ,.body= ""
  975. }
  976. #define CONNECTION_MULTI_LWS_CRLF 37
  977. , {.name = "multiple connection header values with folding and lws"
  978. ,.type= HTTP_REQUEST
  979. ,.raw= "GET /demo HTTP/1.1\r\n"
  980. "Connection: keep-alive, \r\n upgrade\r\n"
  981. "Upgrade: WebSocket\r\n"
  982. "\r\n"
  983. "Hot diggity dogg"
  984. ,.should_keep_alive= TRUE
  985. ,.message_complete_on_eof= FALSE
  986. ,.http_major= 1
  987. ,.http_minor= 1
  988. ,.method= HTTP_GET
  989. ,.query_string= ""
  990. ,.fragment= ""
  991. ,.request_path= "/demo"
  992. ,.request_url= "/demo"
  993. ,.num_headers= 2
  994. ,.upgrade="Hot diggity dogg"
  995. ,.headers= { { "Connection", "keep-alive, upgrade" }
  996. , { "Upgrade", "WebSocket" }
  997. }
  998. ,.body= ""
  999. }
  1000. #define UPGRADE_POST_REQUEST 38
  1001. , {.name = "upgrade post request"
  1002. ,.type= HTTP_REQUEST
  1003. ,.raw= "POST /demo HTTP/1.1\r\n"
  1004. "Host: example.com\r\n"
  1005. "Connection: Upgrade\r\n"
  1006. "Upgrade: HTTP/2.0\r\n"
  1007. "Content-Length: 15\r\n"
  1008. "\r\n"
  1009. "sweet post body"
  1010. "Hot diggity dogg"
  1011. ,.should_keep_alive= TRUE
  1012. ,.message_complete_on_eof= FALSE
  1013. ,.http_major= 1
  1014. ,.http_minor= 1
  1015. ,.method= HTTP_POST
  1016. ,.request_path= "/demo"
  1017. ,.request_url= "/demo"
  1018. ,.num_headers= 4
  1019. ,.upgrade="Hot diggity dogg"
  1020. ,.headers= { { "Host", "example.com" }
  1021. , { "Connection", "Upgrade" }
  1022. , { "Upgrade", "HTTP/2.0" }
  1023. , { "Content-Length", "15" }
  1024. }
  1025. ,.body= "sweet post body"
  1026. }
  1027. #define CONNECT_WITH_BODY_REQUEST 39
  1028. , {.name = "connect with body request"
  1029. ,.type= HTTP_REQUEST
  1030. ,.raw= "CONNECT foo.bar.com:443 HTTP/1.0\r\n"
  1031. "User-agent: Mozilla/1.1N\r\n"
  1032. "Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n"
  1033. "Content-Length: 10\r\n"
  1034. "\r\n"
  1035. "blarfcicle"
  1036. ,.should_keep_alive= FALSE
  1037. ,.message_complete_on_eof= FALSE
  1038. ,.http_major= 1
  1039. ,.http_minor= 0
  1040. ,.method= HTTP_CONNECT
  1041. ,.request_url= "foo.bar.com:443"
  1042. ,.num_headers= 3
  1043. ,.upgrade="blarfcicle"
  1044. ,.headers= { { "User-agent", "Mozilla/1.1N" }
  1045. , { "Proxy-authorization", "basic aGVsbG86d29ybGQ=" }
  1046. , { "Content-Length", "10" }
  1047. }
  1048. ,.body= ""
  1049. }
  1050. /* Examples from the Internet draft for LINK/UNLINK methods:
  1051. * https://tools.ietf.org/id/draft-snell-link-method-01.html#rfc.section.5
  1052. */
  1053. #define LINK_REQUEST 40
  1054. , {.name = "link request"
  1055. ,.type= HTTP_REQUEST
  1056. ,.raw= "LINK /images/my_dog.jpg HTTP/1.1\r\n"
  1057. "Host: example.com\r\n"
  1058. "Link: <http://example.com/profiles/joe>; rel=\"tag\"\r\n"
  1059. "Link: <http://example.com/profiles/sally>; rel=\"tag\"\r\n"
  1060. "\r\n"
  1061. ,.should_keep_alive= TRUE
  1062. ,.message_complete_on_eof= FALSE
  1063. ,.http_major= 1
  1064. ,.http_minor= 1
  1065. ,.method= HTTP_LINK
  1066. ,.request_path= "/images/my_dog.jpg"
  1067. ,.request_url= "/images/my_dog.jpg"
  1068. ,.query_string= ""
  1069. ,.fragment= ""
  1070. ,.num_headers= 3
  1071. ,.headers= { { "Host", "example.com" }
  1072. , { "Link", "<http://example.com/profiles/joe>; rel=\"tag\"" }
  1073. , { "Link", "<http://example.com/profiles/sally>; rel=\"tag\"" }
  1074. }
  1075. ,.body= ""
  1076. }
  1077. #define UNLINK_REQUEST 41
  1078. , {.name = "unlink request"
  1079. ,.type= HTTP_REQUEST
  1080. ,.raw= "UNLINK /images/my_dog.jpg HTTP/1.1\r\n"
  1081. "Host: example.com\r\n"
  1082. "Link: <http://example.com/profiles/sally>; rel=\"tag\"\r\n"
  1083. "\r\n"
  1084. ,.should_keep_alive= TRUE
  1085. ,.message_complete_on_eof= FALSE
  1086. ,.http_major= 1
  1087. ,.http_minor= 1
  1088. ,.method= HTTP_UNLINK
  1089. ,.request_path= "/images/my_dog.jpg"
  1090. ,.request_url= "/images/my_dog.jpg"
  1091. ,.query_string= ""
  1092. ,.fragment= ""
  1093. ,.num_headers= 2
  1094. ,.headers= { { "Host", "example.com" }
  1095. , { "Link", "<http://example.com/profiles/sally>; rel=\"tag\"" }
  1096. }
  1097. ,.body= ""
  1098. }
  1099. #define SOURCE_REQUEST 42
  1100. , {.name = "source request"
  1101. ,.type= HTTP_REQUEST
  1102. ,.raw= "SOURCE /music/sweet/music HTTP/1.1\r\n"
  1103. "Host: example.com\r\n"
  1104. "\r\n"
  1105. ,.should_keep_alive= TRUE
  1106. ,.message_complete_on_eof= FALSE
  1107. ,.http_major= 1
  1108. ,.http_minor= 1
  1109. ,.method= HTTP_SOURCE
  1110. ,.request_path= "/music/sweet/music"
  1111. ,.request_url= "/music/sweet/music"
  1112. ,.query_string= ""
  1113. ,.fragment= ""
  1114. ,.num_headers= 1
  1115. ,.headers= { { "Host", "example.com" } }
  1116. ,.body= ""
  1117. }
  1118. #define SOURCE_ICE_REQUEST 42
  1119. , {.name = "source request"
  1120. ,.type= HTTP_REQUEST
  1121. ,.raw= "SOURCE /music/sweet/music ICE/1.0\r\n"
  1122. "Host: example.com\r\n"
  1123. "\r\n"
  1124. ,.should_keep_alive= FALSE
  1125. ,.message_complete_on_eof= FALSE
  1126. ,.http_major= 1
  1127. ,.http_minor= 0
  1128. ,.method= HTTP_SOURCE
  1129. ,.request_path= "/music/sweet/music"
  1130. ,.request_url= "/music/sweet/music"
  1131. ,.query_string= ""
  1132. ,.fragment= ""
  1133. ,.num_headers= 1
  1134. ,.headers= { { "Host", "example.com" } }
  1135. ,.body= ""
  1136. }
  1137. };
  1138. /* * R E S P O N S E S * */
  1139. const struct message responses[] =
  1140. #define GOOGLE_301 0
  1141. { {.name= "google 301"
  1142. ,.type= HTTP_RESPONSE
  1143. ,.raw= "HTTP/1.1 301 Moved Permanently\r\n"
  1144. "Location: http://www.google.com/\r\n"
  1145. "Content-Type: text/html; charset=UTF-8\r\n"
  1146. "Date: Sun, 26 Apr 2009 11:11:49 GMT\r\n"
  1147. "Expires: Tue, 26 May 2009 11:11:49 GMT\r\n"
  1148. "X-$PrototypeBI-Version: 1.6.0.3\r\n" /* $ char in header field */
  1149. "Cache-Control: public, max-age=2592000\r\n"
  1150. "Server: gws\r\n"
  1151. "Content-Length: 219 \r\n"
  1152. "\r\n"
  1153. "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"
  1154. "<TITLE>301 Moved</TITLE></HEAD><BODY>\n"
  1155. "<H1>301 Moved</H1>\n"
  1156. "The document has moved\n"
  1157. "<A HREF=\"http://www.google.com/\">here</A>.\r\n"
  1158. "</BODY></HTML>\r\n"
  1159. ,.should_keep_alive= TRUE
  1160. ,.message_complete_on_eof= FALSE
  1161. ,.http_major= 1
  1162. ,.http_minor= 1
  1163. ,.status_code= 301
  1164. ,.response_status= "Moved Permanently"
  1165. ,.num_headers= 8
  1166. ,.headers=
  1167. { { "Location", "http://www.google.com/" }
  1168. , { "Content-Type", "text/html; charset=UTF-8" }
  1169. , { "Date", "Sun, 26 Apr 2009 11:11:49 GMT" }
  1170. , { "Expires", "Tue, 26 May 2009 11:11:49 GMT" }
  1171. , { "X-$PrototypeBI-Version", "1.6.0.3" }
  1172. , { "Cache-Control", "public, max-age=2592000" }
  1173. , { "Server", "gws" }
  1174. , { "Content-Length", "219 " }
  1175. }
  1176. ,.body= "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"
  1177. "<TITLE>301 Moved</TITLE></HEAD><BODY>\n"
  1178. "<H1>301 Moved</H1>\n"
  1179. "The document has moved\n"
  1180. "<A HREF=\"http://www.google.com/\">here</A>.\r\n"
  1181. "</BODY></HTML>\r\n"
  1182. }
  1183. #define NO_CONTENT_LENGTH_RESPONSE 1
  1184. /* The client should wait for the server's EOF. That is, when content-length
  1185. * is not specified, and "Connection: close", the end of body is specified
  1186. * by the EOF.
  1187. * Compare with APACHEBENCH_GET
  1188. */
  1189. , {.name= "no content-length response"
  1190. ,.type= HTTP_RESPONSE
  1191. ,.raw= "HTTP/1.1 200 OK\r\n"
  1192. "Date: Tue, 04 Aug 2009 07:59:32 GMT\r\n"
  1193. "Server: Apache\r\n"
  1194. "X-Powered-By: Servlet/2.5 JSP/2.1\r\n"
  1195. "Content-Type: text/xml; charset=utf-8\r\n"
  1196. "Connection: close\r\n"
  1197. "\r\n"
  1198. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1199. "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
  1200. " <SOAP-ENV:Body>\n"
  1201. " <SOAP-ENV:Fault>\n"
  1202. " <faultcode>SOAP-ENV:Client</faultcode>\n"
  1203. " <faultstring>Client Error</faultstring>\n"
  1204. " </SOAP-ENV:Fault>\n"
  1205. " </SOAP-ENV:Body>\n"
  1206. "</SOAP-ENV:Envelope>"
  1207. ,.should_keep_alive= FALSE
  1208. ,.message_complete_on_eof= TRUE
  1209. ,.http_major= 1
  1210. ,.http_minor= 1
  1211. ,.status_code= 200
  1212. ,.response_status= "OK"
  1213. ,.num_headers= 5
  1214. ,.headers=
  1215. { { "Date", "Tue, 04 Aug 2009 07:59:32 GMT" }
  1216. , { "Server", "Apache" }
  1217. , { "X-Powered-By", "Servlet/2.5 JSP/2.1" }
  1218. , { "Content-Type", "text/xml; charset=utf-8" }
  1219. , { "Connection", "close" }
  1220. }
  1221. ,.body= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1222. "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
  1223. " <SOAP-ENV:Body>\n"
  1224. " <SOAP-ENV:Fault>\n"
  1225. " <faultcode>SOAP-ENV:Client</faultcode>\n"
  1226. " <faultstring>Client Error</faultstring>\n"
  1227. " </SOAP-ENV:Fault>\n"
  1228. " </SOAP-ENV:Body>\n"
  1229. "</SOAP-ENV:Envelope>"
  1230. }
  1231. #define NO_HEADERS_NO_BODY_404 2
  1232. , {.name= "404 no headers no body"
  1233. ,.type= HTTP_RESPONSE
  1234. ,.raw= "HTTP/1.1 404 Not Found\r\n\r\n"
  1235. ,.should_keep_alive= FALSE
  1236. ,.message_complete_on_eof= TRUE
  1237. ,.http_major= 1
  1238. ,.http_minor= 1
  1239. ,.status_code= 404
  1240. ,.response_status= "Not Found"
  1241. ,.num_headers= 0
  1242. ,.headers= {}
  1243. ,.body_size= 0
  1244. ,.body= ""
  1245. }
  1246. #define NO_REASON_PHRASE 3
  1247. , {.name= "301 no response phrase"
  1248. ,.type= HTTP_RESPONSE
  1249. ,.raw= "HTTP/1.1 301\r\n\r\n"
  1250. ,.should_keep_alive = FALSE
  1251. ,.message_complete_on_eof= TRUE
  1252. ,.http_major= 1
  1253. ,.http_minor= 1
  1254. ,.status_code= 301
  1255. ,.response_status= ""
  1256. ,.num_headers= 0
  1257. ,.headers= {}
  1258. ,.body= ""
  1259. }
  1260. #define TRAILING_SPACE_ON_CHUNKED_BODY 4
  1261. , {.name="200 trailing space on chunked body"
  1262. ,.type= HTTP_RESPONSE
  1263. ,.raw= "HTTP/1.1 200 OK\r\n"
  1264. "Content-Type: text/plain\r\n"
  1265. "Transfer-Encoding: chunked\r\n"
  1266. "\r\n"
  1267. "25 \r\n"
  1268. "This is the data in the first chunk\r\n"
  1269. "\r\n"
  1270. "1C\r\n"
  1271. "and this is the second one\r\n"
  1272. "\r\n"
  1273. "0 \r\n"
  1274. "\r\n"
  1275. ,.should_keep_alive= TRUE
  1276. ,.message_complete_on_eof= FALSE
  1277. ,.http_major= 1
  1278. ,.http_minor= 1
  1279. ,.status_code= 200
  1280. ,.response_status= "OK"
  1281. ,.num_headers= 2
  1282. ,.headers=
  1283. { {"Content-Type", "text/plain" }
  1284. , {"Transfer-Encoding", "chunked" }
  1285. }
  1286. ,.body_size = 37+28
  1287. ,.body =
  1288. "This is the data in the first chunk\r\n"
  1289. "and this is the second one\r\n"
  1290. ,.num_chunks_complete= 3
  1291. ,.chunk_lengths= { 0x25, 0x1c }
  1292. }
  1293. #define NO_CARRIAGE_RET 5
  1294. , {.name="no carriage ret"
  1295. ,.type= HTTP_RESPONSE
  1296. ,.raw= "HTTP/1.1 200 OK\n"
  1297. "Content-Type: text/html; charset=utf-8\n"
  1298. "Connection: close\n"
  1299. "\n"
  1300. "these headers are from http://news.ycombinator.com/"
  1301. ,.should_keep_alive= FALSE
  1302. ,.message_complete_on_eof= TRUE
  1303. ,.http_major= 1
  1304. ,.http_minor= 1
  1305. ,.status_code= 200
  1306. ,.response_status= "OK"
  1307. ,.num_headers= 2
  1308. ,.headers=
  1309. { {"Content-Type", "text/html; charset=utf-8" }
  1310. , {"Connection", "close" }
  1311. }
  1312. ,.body= "these headers are from http://news.ycombinator.com/"
  1313. }
  1314. #define PROXY_CONNECTION 6
  1315. , {.name="proxy connection"
  1316. ,.type= HTTP_RESPONSE
  1317. ,.raw= "HTTP/1.1 200 OK\r\n"
  1318. "Content-Type: text/html; charset=UTF-8\r\n"
  1319. "Content-Length: 11\r\n"
  1320. "Proxy-Connection: close\r\n"
  1321. "Date: Thu, 31 Dec 2009 20:55:48 +0000\r\n"
  1322. "\r\n"
  1323. "hello world"
  1324. ,.should_keep_alive= FALSE
  1325. ,.message_complete_on_eof= FALSE
  1326. ,.http_major= 1
  1327. ,.http_minor= 1
  1328. ,.status_code= 200
  1329. ,.response_status= "OK"
  1330. ,.num_headers= 4
  1331. ,.headers=
  1332. { {"Content-Type", "text/html; charset=UTF-8" }
  1333. , {"Content-Length", "11" }
  1334. , {"Proxy-Connection", "close" }
  1335. , {"Date", "Thu, 31 Dec 2009 20:55:48 +0000"}
  1336. }
  1337. ,.body= "hello world"
  1338. }
  1339. #define UNDERSTORE_HEADER_KEY 7
  1340. // shown by
  1341. // curl -o /dev/null -v "http://ad.doubleclick.net/pfadx/DARTSHELLCONFIGXML;dcmt=text/xml;"
  1342. , {.name="underscore header key"
  1343. ,.type= HTTP_RESPONSE
  1344. ,.raw= "HTTP/1.1 200 OK\r\n"
  1345. "Server: DCLK-AdSvr\r\n"
  1346. "Content-Type: text/xml\r\n"
  1347. "Content-Length: 0\r\n"
  1348. "DCLK_imp: v7;x;114750856;0-0;0;17820020;0/0;21603567/21621457/1;;~okv=;dcmt=text/xml;;~cs=o\r\n\r\n"
  1349. ,.should_keep_alive= TRUE
  1350. ,.message_complete_on_eof= FALSE
  1351. ,.http_major= 1
  1352. ,.http_minor= 1
  1353. ,.status_code= 200
  1354. ,.response_status= "OK"
  1355. ,.num_headers= 4
  1356. ,.headers=
  1357. { {"Server", "DCLK-AdSvr" }
  1358. , {"Content-Type", "text/xml" }
  1359. , {"Content-Length", "0" }
  1360. , {"DCLK_imp", "v7;x;114750856;0-0;0;17820020;0/0;21603567/21621457/1;;~okv=;dcmt=text/xml;;~cs=o" }
  1361. }
  1362. ,.body= ""
  1363. }
  1364. #define BONJOUR_MADAME_FR 8
  1365. /* The client should not merge two headers fields when the first one doesn't
  1366. * have a value.
  1367. */
  1368. , {.name= "bonjourmadame.fr"
  1369. ,.type= HTTP_RESPONSE
  1370. ,.raw= "HTTP/1.0 301 Moved Permanently\r\n"
  1371. "Date: Thu, 03 Jun 2010 09:56:32 GMT\r\n"
  1372. "Server: Apache/2.2.3 (Red Hat)\r\n"
  1373. "Cache-Control: public\r\n"
  1374. "Pragma: \r\n"
  1375. "Location: http://www.bonjourmadame.fr/\r\n"
  1376. "Vary: Accept-Encoding\r\n"
  1377. "Content-Length: 0\r\n"
  1378. "Content-Type: text/html; charset=UTF-8\r\n"
  1379. "Connection: keep-alive\r\n"
  1380. "\r\n"
  1381. ,.should_keep_alive= TRUE
  1382. ,.message_complete_on_eof= FALSE
  1383. ,.http_major= 1
  1384. ,.http_minor= 0
  1385. ,.status_code= 301
  1386. ,.response_status= "Moved Permanently"
  1387. ,.num_headers= 9
  1388. ,.headers=
  1389. { { "Date", "Thu, 03 Jun 2010 09:56:32 GMT" }
  1390. , { "Server", "Apache/2.2.3 (Red Hat)" }
  1391. , { "Cache-Control", "public" }
  1392. , { "Pragma", "" }
  1393. , { "Location", "http://www.bonjourmadame.fr/" }
  1394. , { "Vary", "Accept-Encoding" }
  1395. , { "Content-Length", "0" }
  1396. , { "Content-Type", "text/html; charset=UTF-8" }
  1397. , { "Connection", "keep-alive" }
  1398. }
  1399. ,.body= ""
  1400. }
  1401. #define RES_FIELD_UNDERSCORE 9
  1402. /* Should handle spaces in header fields */
  1403. , {.name= "field underscore"
  1404. ,.type= HTTP_RESPONSE
  1405. ,.raw= "HTTP/1.1 200 OK\r\n"
  1406. "Date: Tue, 28 Sep 2010 01:14:13 GMT\r\n"
  1407. "Server: Apache\r\n"
  1408. "Cache-Control: no-cache, must-revalidate\r\n"
  1409. "Expires: Mon, 26 Jul 1997 05:00:00 GMT\r\n"
  1410. ".et-Cookie: PlaxoCS=1274804622353690521; path=/; domain=.plaxo.com\r\n"
  1411. "Vary: Accept-Encoding\r\n"
  1412. "_eep-Alive: timeout=45\r\n" /* semantic value ignored */
  1413. "_onnection: Keep-Alive\r\n" /* semantic value ignored */
  1414. "Transfer-Encoding: chunked\r\n"
  1415. "Content-Type: text/html\r\n"
  1416. "Connection: close\r\n"
  1417. "\r\n"
  1418. "0\r\n\r\n"
  1419. ,.should_keep_alive= FALSE
  1420. ,.message_complete_on_eof= FALSE
  1421. ,.http_major= 1
  1422. ,.http_minor= 1
  1423. ,.status_code= 200
  1424. ,.response_status= "OK"
  1425. ,.num_headers= 11
  1426. ,.headers=
  1427. { { "Date", "Tue, 28 Sep 2010 01:14:13 GMT" }
  1428. , { "Server", "Apache" }
  1429. , { "Cache-Control", "no-cache, must-revalidate" }
  1430. , { "Expires", "Mon, 26 Jul 1997 05:00:00 GMT" }
  1431. , { ".et-Cookie", "PlaxoCS=1274804622353690521; path=/; domain=.plaxo.com" }
  1432. , { "Vary", "Accept-Encoding" }
  1433. , { "_eep-Alive", "timeout=45" }
  1434. , { "_onnection", "Keep-Alive" }
  1435. , { "Transfer-Encoding", "chunked" }
  1436. , { "Content-Type", "text/html" }
  1437. , { "Connection", "close" }
  1438. }
  1439. ,.body= ""
  1440. ,.num_chunks_complete= 1
  1441. ,.chunk_lengths= {}
  1442. }
  1443. #define NON_ASCII_IN_STATUS_LINE 10
  1444. /* Should handle non-ASCII in status line */
  1445. , {.name= "non-ASCII in status line"
  1446. ,.type= HTTP_RESPONSE
  1447. ,.raw= "HTTP/1.1 500 Oriëntatieprobleem\r\n"
  1448. "Date: Fri, 5 Nov 2010 23:07:12 GMT+2\r\n"
  1449. "Content-Length: 0\r\n"
  1450. "Connection: close\r\n"
  1451. "\r\n"
  1452. ,.should_keep_alive= FALSE
  1453. ,.message_complete_on_eof= FALSE
  1454. ,.http_major= 1
  1455. ,.http_minor= 1
  1456. ,.status_code= 500
  1457. ,.response_status= "Oriëntatieprobleem"
  1458. ,.num_headers= 3
  1459. ,.headers=
  1460. { { "Date", "Fri, 5 Nov 2010 23:07:12 GMT+2" }
  1461. , { "Content-Length", "0" }
  1462. , { "Connection", "close" }
  1463. }
  1464. ,.body= ""
  1465. }
  1466. #define HTTP_VERSION_0_9 11
  1467. /* Should handle HTTP/0.9 */
  1468. , {.name= "http version 0.9"
  1469. ,.type= HTTP_RESPONSE
  1470. ,.raw= "HTTP/0.9 200 OK\r\n"
  1471. "\r\n"
  1472. ,.should_keep_alive= FALSE
  1473. ,.message_complete_on_eof= TRUE
  1474. ,.http_major= 0
  1475. ,.http_minor= 9
  1476. ,.status_code= 200
  1477. ,.response_status= "OK"
  1478. ,.num_headers= 0
  1479. ,.headers=
  1480. {}
  1481. ,.body= ""
  1482. }
  1483. #define NO_CONTENT_LENGTH_NO_TRANSFER_ENCODING_RESPONSE 12
  1484. /* The client should wait for the server's EOF. That is, when neither
  1485. * content-length nor transfer-encoding is specified, the end of body
  1486. * is specified by the EOF.
  1487. */
  1488. , {.name= "neither content-length nor transfer-encoding response"
  1489. ,.type= HTTP_RESPONSE
  1490. ,.raw= "HTTP/1.1 200 OK\r\n"
  1491. "Content-Type: text/plain\r\n"
  1492. "\r\n"
  1493. "hello world"
  1494. ,.should_keep_alive= FALSE
  1495. ,.message_complete_on_eof= TRUE
  1496. ,.http_major= 1
  1497. ,.http_minor= 1
  1498. ,.status_code= 200
  1499. ,.response_status= "OK"
  1500. ,.num_headers= 1
  1501. ,.headers=
  1502. { { "Content-Type", "text/plain" }
  1503. }
  1504. ,.body= "hello world"
  1505. }
  1506. #define NO_BODY_HTTP10_KA_200 13
  1507. , {.name= "HTTP/1.0 with keep-alive and EOF-terminated 200 status"
  1508. ,.type= HTTP_RESPONSE
  1509. ,.raw= "HTTP/1.0 200 OK\r\n"
  1510. "Connection: keep-alive\r\n"
  1511. "\r\n"
  1512. ,.should_keep_alive= FALSE
  1513. ,.message_complete_on_eof= TRUE
  1514. ,.http_major= 1
  1515. ,.http_minor= 0
  1516. ,.status_code= 200
  1517. ,.response_status= "OK"
  1518. ,.num_headers= 1
  1519. ,.headers=
  1520. { { "Connection", "keep-alive" }
  1521. }
  1522. ,.body_size= 0
  1523. ,.body= ""
  1524. }
  1525. #define NO_BODY_HTTP10_KA_204 14
  1526. , {.name= "HTTP/1.0 with keep-alive and a 204 status"
  1527. ,.type= HTTP_RESPONSE
  1528. ,.raw= "HTTP/1.0 204 No content\r\n"
  1529. "Connection: keep-alive\r\n"
  1530. "\r\n"
  1531. ,.should_keep_alive= TRUE
  1532. ,.message_complete_on_eof= FALSE
  1533. ,.http_major= 1
  1534. ,.http_minor= 0
  1535. ,.status_code= 204
  1536. ,.response_status= "No content"
  1537. ,.num_headers= 1
  1538. ,.headers=
  1539. { { "Connection", "keep-alive" }
  1540. }
  1541. ,.body_size= 0
  1542. ,.body= ""
  1543. }
  1544. #define NO_BODY_HTTP11_KA_200 15
  1545. , {.name= "HTTP/1.1 with an EOF-terminated 200 status"
  1546. ,.type= HTTP_RESPONSE
  1547. ,.raw= "HTTP/1.1 200 OK\r\n"
  1548. "\r\n"
  1549. ,.should_keep_alive= FALSE
  1550. ,.message_complete_on_eof= TRUE
  1551. ,.http_major= 1
  1552. ,.http_minor= 1
  1553. ,.status_code= 200
  1554. ,.response_status= "OK"
  1555. ,.num_headers= 0
  1556. ,.headers={}
  1557. ,.body_size= 0
  1558. ,.body= ""
  1559. }
  1560. #define NO_BODY_HTTP11_KA_204 16
  1561. , {.name= "HTTP/1.1 with a 204 status"
  1562. ,.type= HTTP_RESPONSE
  1563. ,.raw= "HTTP/1.1 204 No content\r\n"
  1564. "\r\n"
  1565. ,.should_keep_alive= TRUE
  1566. ,.message_complete_on_eof= FALSE
  1567. ,.http_major= 1
  1568. ,.http_minor= 1
  1569. ,.status_code= 204
  1570. ,.response_status= "No content"
  1571. ,.num_headers= 0
  1572. ,.headers={}
  1573. ,.body_size= 0
  1574. ,.body= ""
  1575. }
  1576. #define NO_BODY_HTTP11_NOKA_204 17
  1577. , {.name= "HTTP/1.1 with a 204 status and keep-alive disabled"
  1578. ,.type= HTTP_RESPONSE
  1579. ,.raw= "HTTP/1.1 204 No content\r\n"
  1580. "Connection: close\r\n"
  1581. "\r\n"
  1582. ,.should_keep_alive= FALSE
  1583. ,.message_complete_on_eof= FALSE
  1584. ,.http_major= 1
  1585. ,.http_minor= 1
  1586. ,.status_code= 204
  1587. ,.response_status= "No content"
  1588. ,.num_headers= 1
  1589. ,.headers=
  1590. { { "Connection", "close" }
  1591. }
  1592. ,.body_size= 0
  1593. ,.body= ""
  1594. }
  1595. #define NO_BODY_HTTP11_KA_CHUNKED_200 18
  1596. , {.name= "HTTP/1.1 with chunked endocing and a 200 response"
  1597. ,.type= HTTP_RESPONSE
  1598. ,.raw= "HTTP/1.1 200 OK\r\n"
  1599. "Transfer-Encoding: chunked\r\n"
  1600. "\r\n"
  1601. "0\r\n"
  1602. "\r\n"
  1603. ,.should_keep_alive= TRUE
  1604. ,.message_complete_on_eof= FALSE
  1605. ,.http_major= 1
  1606. ,.http_minor= 1
  1607. ,.status_code= 200
  1608. ,.response_status= "OK"
  1609. ,.num_headers= 1
  1610. ,.headers=
  1611. { { "Transfer-Encoding", "chunked" }
  1612. }
  1613. ,.body_size= 0
  1614. ,.body= ""
  1615. ,.num_chunks_complete= 1
  1616. }
  1617. #if !HTTP_PARSER_STRICT
  1618. #define SPACE_IN_FIELD_RES 19
  1619. /* Should handle spaces in header fields */
  1620. , {.name= "field space"
  1621. ,.type= HTTP_RESPONSE
  1622. ,.raw= "HTTP/1.1 200 OK\r\n"
  1623. "Server: Microsoft-IIS/6.0\r\n"
  1624. "X-Powered-By: ASP.NET\r\n"
  1625. "en-US Content-Type: text/xml\r\n" /* this is the problem */
  1626. "Content-Type: text/xml\r\n"
  1627. "Content-Length: 16\r\n"
  1628. "Date: Fri, 23 Jul 2010 18:45:38 GMT\r\n"
  1629. "Connection: keep-alive\r\n"
  1630. "\r\n"
  1631. "<xml>hello</xml>" /* fake body */
  1632. ,.should_keep_alive= TRUE
  1633. ,.message_complete_on_eof= FALSE
  1634. ,.http_major= 1
  1635. ,.http_minor= 1
  1636. ,.status_code= 200
  1637. ,.response_status= "OK"
  1638. ,.num_headers= 7
  1639. ,.headers=
  1640. { { "Server", "Microsoft-IIS/6.0" }
  1641. , { "X-Powered-By", "ASP.NET" }
  1642. , { "en-US Content-Type", "text/xml" }
  1643. , { "Content-Type", "text/xml" }
  1644. , { "Content-Length", "16" }
  1645. , { "Date", "Fri, 23 Jul 2010 18:45:38 GMT" }
  1646. , { "Connection", "keep-alive" }
  1647. }
  1648. ,.body= "<xml>hello</xml>"
  1649. }
  1650. #endif /* !HTTP_PARSER_STRICT */
  1651. #define AMAZON_COM 20
  1652. , {.name= "amazon.com"
  1653. ,.type= HTTP_RESPONSE
  1654. ,.raw= "HTTP/1.1 301 MovedPermanently\r\n"
  1655. "Date: Wed, 15 May 2013 17:06:33 GMT\r\n"
  1656. "Server: Server\r\n"
  1657. "x-amz-id-1: 0GPHKXSJQ826RK7GZEB2\r\n"
  1658. "p3p: policyref=\"http://www.amazon.com/w3c/p3p.xml\",CP=\"CAO DSP LAW CUR ADM IVAo IVDo CONo OTPo OUR DELi PUBi OTRi BUS PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA HEA PRE LOC GOV OTC \"\r\n"
  1659. "x-amz-id-2: STN69VZxIFSz9YJLbz1GDbxpbjG6Qjmmq5E3DxRhOUw+Et0p4hr7c/Q8qNcx4oAD\r\n"
  1660. "Location: http://www.amazon.com/Dan-Brown/e/B000AP9DSU/ref=s9_pop_gw_al1?_encoding=UTF8&refinementId=618073011&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=0SHYY5BZXN3KR20BNFAY&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846\r\n"
  1661. "Vary: Accept-Encoding,User-Agent\r\n"
  1662. "Content-Type: text/html; charset=ISO-8859-1\r\n"
  1663. "Transfer-Encoding: chunked\r\n"
  1664. "\r\n"
  1665. "1\r\n"
  1666. "\n\r\n"
  1667. "0\r\n"
  1668. "\r\n"
  1669. ,.should_keep_alive= TRUE
  1670. ,.message_complete_on_eof= FALSE
  1671. ,.http_major= 1
  1672. ,.http_minor= 1
  1673. ,.status_code= 301
  1674. ,.response_status= "MovedPermanently"
  1675. ,.num_headers= 9
  1676. ,.headers= { { "Date", "Wed, 15 May 2013 17:06:33 GMT" }
  1677. , { "Server", "Server" }
  1678. , { "x-amz-id-1", "0GPHKXSJQ826RK7GZEB2" }
  1679. , { "p3p", "policyref=\"http://www.amazon.com/w3c/p3p.xml\",CP=\"CAO DSP LAW CUR ADM IVAo IVDo CONo OTPo OUR DELi PUBi OTRi BUS PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA HEA PRE LOC GOV OTC \"" }
  1680. , { "x-amz-id-2", "STN69VZxIFSz9YJLbz1GDbxpbjG6Qjmmq5E3DxRhOUw+Et0p4hr7c/Q8qNcx4oAD" }
  1681. , { "Location", "http://www.amazon.com/Dan-Brown/e/B000AP9DSU/ref=s9_pop_gw_al1?_encoding=UTF8&refinementId=618073011&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=0SHYY5BZXN3KR20BNFAY&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846" }
  1682. , { "Vary", "Accept-Encoding,User-Agent" }
  1683. , { "Content-Type", "text/html; charset=ISO-8859-1" }
  1684. , { "Transfer-Encoding", "chunked" }
  1685. }
  1686. ,.body= "\n"
  1687. ,.num_chunks_complete= 2
  1688. ,.chunk_lengths= { 1 }
  1689. }
  1690. #define EMPTY_REASON_PHRASE_AFTER_SPACE 20
  1691. , {.name= "empty reason phrase after space"
  1692. ,.type= HTTP_RESPONSE
  1693. ,.raw= "HTTP/1.1 200 \r\n"
  1694. "\r\n"
  1695. ,.should_keep_alive= FALSE
  1696. ,.message_complete_on_eof= TRUE
  1697. ,.http_major= 1
  1698. ,.http_minor= 1
  1699. ,.status_code= 200
  1700. ,.response_status= ""
  1701. ,.num_headers= 0
  1702. ,.headers= {}
  1703. ,.body= ""
  1704. }
  1705. #define CONTENT_LENGTH_X 21
  1706. , {.name= "Content-Length-X"
  1707. ,.type= HTTP_RESPONSE
  1708. ,.raw= "HTTP/1.1 200 OK\r\n"
  1709. "Content-Length-X: 0\r\n"
  1710. "Transfer-Encoding: chunked\r\n"
  1711. "\r\n"
  1712. "2\r\n"
  1713. "OK\r\n"
  1714. "0\r\n"
  1715. "\r\n"
  1716. ,.should_keep_alive= TRUE
  1717. ,.message_complete_on_eof= FALSE
  1718. ,.http_major= 1
  1719. ,.http_minor= 1
  1720. ,.status_code= 200
  1721. ,.response_status= "OK"
  1722. ,.num_headers= 2
  1723. ,.headers= { { "Content-Length-X", "0" }
  1724. , { "Transfer-Encoding", "chunked" }
  1725. }
  1726. ,.body= "OK"
  1727. ,.num_chunks_complete= 2
  1728. ,.chunk_lengths= { 2 }
  1729. }
  1730. #define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER 22
  1731. , {.name= "HTTP 101 response with Upgrade header"
  1732. ,.type= HTTP_RESPONSE
  1733. ,.raw= "HTTP/1.1 101 Switching Protocols\r\n"
  1734. "Connection: upgrade\r\n"
  1735. "Upgrade: h2c\r\n"
  1736. "\r\n"
  1737. "proto"
  1738. ,.should_keep_alive= TRUE
  1739. ,.message_complete_on_eof= FALSE
  1740. ,.http_major= 1
  1741. ,.http_minor= 1
  1742. ,.status_code= 101
  1743. ,.response_status= "Switching Protocols"
  1744. ,.upgrade= "proto"
  1745. ,.num_headers= 2
  1746. ,.headers=
  1747. { { "Connection", "upgrade" }
  1748. , { "Upgrade", "h2c" }
  1749. }
  1750. }
  1751. #define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER_AND_CONTENT_LENGTH 23
  1752. , {.name= "HTTP 101 response with Upgrade and Content-Length header"
  1753. ,.type= HTTP_RESPONSE
  1754. ,.raw= "HTTP/1.1 101 Switching Protocols\r\n"
  1755. "Connection: upgrade\r\n"
  1756. "Upgrade: h2c\r\n"
  1757. "Content-Length: 4\r\n"
  1758. "\r\n"
  1759. "body"
  1760. "proto"
  1761. ,.should_keep_alive= TRUE
  1762. ,.message_complete_on_eof= FALSE
  1763. ,.http_major= 1
  1764. ,.http_minor= 1
  1765. ,.status_code= 101
  1766. ,.response_status= "Switching Protocols"
  1767. ,.body= "body"
  1768. ,.upgrade= "proto"
  1769. ,.num_headers= 3
  1770. ,.headers=
  1771. { { "Connection", "upgrade" }
  1772. , { "Upgrade", "h2c" }
  1773. , { "Content-Length", "4" }
  1774. }
  1775. }
  1776. #define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER_AND_TRANSFER_ENCODING 24
  1777. , {.name= "HTTP 101 response with Upgrade and Transfer-Encoding header"
  1778. ,.type= HTTP_RESPONSE
  1779. ,.raw= "HTTP/1.1 101 Switching Protocols\r\n"
  1780. "Connection: upgrade\r\n"
  1781. "Upgrade: h2c\r\n"
  1782. "Transfer-Encoding: chunked\r\n"
  1783. "\r\n"
  1784. "2\r\n"
  1785. "bo\r\n"
  1786. "2\r\n"
  1787. "dy\r\n"
  1788. "0\r\n"
  1789. "\r\n"
  1790. "proto"
  1791. ,.should_keep_alive= TRUE
  1792. ,.message_complete_on_eof= FALSE
  1793. ,.http_major= 1
  1794. ,.http_minor= 1
  1795. ,.status_code= 101
  1796. ,.response_status= "Switching Protocols"
  1797. ,.body= "body"
  1798. ,.upgrade= "proto"
  1799. ,.num_headers= 3
  1800. ,.headers=
  1801. { { "Connection", "upgrade" }
  1802. , { "Upgrade", "h2c" }
  1803. , { "Transfer-Encoding", "chunked" }
  1804. }
  1805. ,.num_chunks_complete= 3
  1806. ,.chunk_lengths= { 2, 2 }
  1807. }
  1808. #define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER 25
  1809. , {.name= "HTTP 200 response with Upgrade header"
  1810. ,.type= HTTP_RESPONSE
  1811. ,.raw= "HTTP/1.1 200 OK\r\n"
  1812. "Connection: upgrade\r\n"
  1813. "Upgrade: h2c\r\n"
  1814. "\r\n"
  1815. "body"
  1816. ,.should_keep_alive= FALSE
  1817. ,.message_complete_on_eof= TRUE
  1818. ,.http_major= 1
  1819. ,.http_minor= 1
  1820. ,.status_code= 200
  1821. ,.response_status= "OK"
  1822. ,.body= "body"
  1823. ,.upgrade= NULL
  1824. ,.num_headers= 2
  1825. ,.headers=
  1826. { { "Connection", "upgrade" }
  1827. , { "Upgrade", "h2c" }
  1828. }
  1829. }
  1830. #define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER_AND_CONTENT_LENGTH 26
  1831. , {.name= "HTTP 200 response with Upgrade and Content-Length header"
  1832. ,.type= HTTP_RESPONSE
  1833. ,.raw= "HTTP/1.1 200 OK\r\n"
  1834. "Connection: upgrade\r\n"
  1835. "Upgrade: h2c\r\n"
  1836. "Content-Length: 4\r\n"
  1837. "\r\n"
  1838. "body"
  1839. ,.should_keep_alive= TRUE
  1840. ,.message_complete_on_eof= FALSE
  1841. ,.http_major= 1
  1842. ,.http_minor= 1
  1843. ,.status_code= 200
  1844. ,.response_status= "OK"
  1845. ,.num_headers= 3
  1846. ,.body= "body"
  1847. ,.upgrade= NULL
  1848. ,.headers=
  1849. { { "Connection", "upgrade" }
  1850. , { "Upgrade", "h2c" }
  1851. , { "Content-Length", "4" }
  1852. }
  1853. }
  1854. #define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER_AND_TRANSFER_ENCODING 27
  1855. , {.name= "HTTP 200 response with Upgrade and Transfer-Encoding header"
  1856. ,.type= HTTP_RESPONSE
  1857. ,.raw= "HTTP/1.1 200 OK\r\n"
  1858. "Connection: upgrade\r\n"
  1859. "Upgrade: h2c\r\n"
  1860. "Transfer-Encoding: chunked\r\n"
  1861. "\r\n"
  1862. "2\r\n"
  1863. "bo\r\n"
  1864. "2\r\n"
  1865. "dy\r\n"
  1866. "0\r\n"
  1867. "\r\n"
  1868. ,.should_keep_alive= TRUE
  1869. ,.message_complete_on_eof= FALSE
  1870. ,.http_major= 1
  1871. ,.http_minor= 1
  1872. ,.status_code= 200
  1873. ,.response_status= "OK"
  1874. ,.num_headers= 3
  1875. ,.body= "body"
  1876. ,.upgrade= NULL
  1877. ,.headers=
  1878. { { "Connection", "upgrade" }
  1879. , { "Upgrade", "h2c" }
  1880. , { "Transfer-Encoding", "chunked" }
  1881. }
  1882. ,.num_chunks_complete= 3
  1883. ,.chunk_lengths= { 2, 2 }
  1884. }
  1885. };
  1886. /* strnlen() is a POSIX.2008 addition. Can't rely on it being available so
  1887. * define it ourselves.
  1888. */
  1889. size_t
  1890. strnlen(const char *s, size_t maxlen)
  1891. {
  1892. const char *p;
  1893. p = memchr(s, '\0', maxlen);
  1894. if (p == NULL)
  1895. return maxlen;
  1896. return p - s;
  1897. }
  1898. size_t
  1899. strlncat(char *dst, size_t len, const char *src, size_t n)
  1900. {
  1901. size_t slen;
  1902. size_t dlen;
  1903. size_t rlen;
  1904. size_t ncpy;
  1905. slen = strnlen(src, n);
  1906. dlen = strnlen(dst, len);
  1907. if (dlen < len) {
  1908. rlen = len - dlen;
  1909. ncpy = slen < rlen ? slen : (rlen - 1);
  1910. memcpy(dst + dlen, src, ncpy);
  1911. dst[dlen + ncpy] = '\0';
  1912. }
  1913. assert(len > slen + dlen);
  1914. return slen + dlen;
  1915. }
  1916. size_t
  1917. strlncpy(char *dst, size_t len, const char *src, size_t n)
  1918. {
  1919. size_t slen;
  1920. size_t ncpy;
  1921. slen = strnlen(src, n);
  1922. if (len > 0) {
  1923. ncpy = slen < len ? slen : (len - 1);
  1924. memcpy(dst, src, ncpy);
  1925. dst[ncpy] = '\0';
  1926. }
  1927. assert(len > slen);
  1928. return slen;
  1929. }
  1930. int
  1931. request_url_cb (http_parser *p, const char *buf, size_t len)
  1932. {
  1933. assert(p == &parser);
  1934. strlncat(messages[num_messages].request_url,
  1935. sizeof(messages[num_messages].request_url),
  1936. buf,
  1937. len);
  1938. return 0;
  1939. }
  1940. int
  1941. header_field_cb (http_parser *p, const char *buf, size_t len)
  1942. {
  1943. assert(p == &parser);
  1944. struct message *m = &messages[num_messages];
  1945. if (m->last_header_element != FIELD)
  1946. m->num_headers++;
  1947. strlncat(m->headers[m->num_headers-1][0],
  1948. sizeof(m->headers[m->num_headers-1][0]),
  1949. buf,
  1950. len);
  1951. m->last_header_element = FIELD;
  1952. return 0;
  1953. }
  1954. int
  1955. header_value_cb (http_parser *p, const char *buf, size_t len)
  1956. {
  1957. assert(p == &parser);
  1958. struct message *m = &messages[num_messages];
  1959. strlncat(m->headers[m->num_headers-1][1],
  1960. sizeof(m->headers[m->num_headers-1][1]),
  1961. buf,
  1962. len);
  1963. m->last_header_element = VALUE;
  1964. return 0;
  1965. }
  1966. void
  1967. check_body_is_final (const http_parser *p)
  1968. {
  1969. if (messages[num_messages].body_is_final) {
  1970. fprintf(stderr, "\n\n *** Error http_body_is_final() should return 1 "
  1971. "on last on_body callback call "
  1972. "but it doesn't! ***\n\n");
  1973. assert(0);
  1974. abort();
  1975. }
  1976. messages[num_messages].body_is_final = http_body_is_final(p);
  1977. }
  1978. int
  1979. body_cb (http_parser *p, const char *buf, size_t len)
  1980. {
  1981. assert(p == &parser);
  1982. strlncat(messages[num_messages].body,
  1983. sizeof(messages[num_messages].body),
  1984. buf,
  1985. len);
  1986. messages[num_messages].body_size += len;
  1987. check_body_is_final(p);
  1988. // printf("body_cb: '%s'\n", requests[num_messages].body);
  1989. return 0;
  1990. }
  1991. int
  1992. count_body_cb (http_parser *p, const char *buf, size_t len)
  1993. {
  1994. assert(p == &parser);
  1995. assert(buf);
  1996. messages[num_messages].body_size += len;
  1997. check_body_is_final(p);
  1998. return 0;
  1999. }
  2000. int
  2001. message_begin_cb (http_parser *p)
  2002. {
  2003. assert(p == &parser);
  2004. assert(!messages[num_messages].message_begin_cb_called);
  2005. messages[num_messages].message_begin_cb_called = TRUE;
  2006. return 0;
  2007. }
  2008. int
  2009. headers_complete_cb (http_parser *p)
  2010. {
  2011. assert(p == &parser);
  2012. messages[num_messages].method = parser.method;
  2013. messages[num_messages].status_code = parser.status_code;
  2014. messages[num_messages].http_major = parser.http_major;
  2015. messages[num_messages].http_minor = parser.http_minor;
  2016. messages[num_messages].headers_complete_cb_called = TRUE;
  2017. messages[num_messages].should_keep_alive = http_should_keep_alive(&parser);
  2018. return 0;
  2019. }
  2020. int
  2021. message_complete_cb (http_parser *p)
  2022. {
  2023. assert(p == &parser);
  2024. if (messages[num_messages].should_keep_alive !=
  2025. http_should_keep_alive(&parser))
  2026. {
  2027. fprintf(stderr, "\n\n *** Error http_should_keep_alive() should have same "
  2028. "value in both on_message_complete and on_headers_complete "
  2029. "but it doesn't! ***\n\n");
  2030. assert(0);
  2031. abort();
  2032. }
  2033. if (messages[num_messages].body_size &&
  2034. http_body_is_final(p) &&
  2035. !messages[num_messages].body_is_final)
  2036. {
  2037. fprintf(stderr, "\n\n *** Error http_body_is_final() should return 1 "
  2038. "on last on_body callback call "
  2039. "but it doesn't! ***\n\n");
  2040. assert(0);
  2041. abort();
  2042. }
  2043. messages[num_messages].message_complete_cb_called = TRUE;
  2044. messages[num_messages].message_complete_on_eof = currently_parsing_eof;
  2045. num_messages++;
  2046. return 0;
  2047. }
  2048. int
  2049. response_status_cb (http_parser *p, const char *buf, size_t len)
  2050. {
  2051. assert(p == &parser);
  2052. messages[num_messages].status_cb_called = TRUE;
  2053. strlncat(messages[num_messages].response_status,
  2054. sizeof(messages[num_messages].response_status),
  2055. buf,
  2056. len);
  2057. return 0;
  2058. }
  2059. int
  2060. chunk_header_cb (http_parser *p)
  2061. {
  2062. assert(p == &parser);
  2063. int chunk_idx = messages[num_messages].num_chunks;
  2064. messages[num_messages].num_chunks++;
  2065. if (chunk_idx < MAX_CHUNKS) {
  2066. messages[num_messages].chunk_lengths[chunk_idx] = p->content_length;
  2067. }
  2068. return 0;
  2069. }
  2070. int
  2071. chunk_complete_cb (http_parser *p)
  2072. {
  2073. assert(p == &parser);
  2074. /* Here we want to verify that each chunk_header_cb is matched by a
  2075. * chunk_complete_cb, so not only should the total number of calls to
  2076. * both callbacks be the same, but they also should be interleaved
  2077. * properly */
  2078. assert(messages[num_messages].num_chunks ==
  2079. messages[num_messages].num_chunks_complete + 1);
  2080. messages[num_messages].num_chunks_complete++;
  2081. return 0;
  2082. }
  2083. /* These dontcall_* callbacks exist so that we can verify that when we're
  2084. * paused, no additional callbacks are invoked */
  2085. int
  2086. dontcall_message_begin_cb (http_parser *p)
  2087. {
  2088. if (p) { } // gcc
  2089. fprintf(stderr, "\n\n*** on_message_begin() called on paused parser ***\n\n");
  2090. abort();
  2091. }
  2092. int
  2093. dontcall_header_field_cb (http_parser *p, const char *buf, size_t len)
  2094. {
  2095. if (p || buf || len) { } // gcc
  2096. fprintf(stderr, "\n\n*** on_header_field() called on paused parser ***\n\n");
  2097. abort();
  2098. }
  2099. int
  2100. dontcall_header_value_cb (http_parser *p, const char *buf, size_t len)
  2101. {
  2102. if (p || buf || len) { } // gcc
  2103. fprintf(stderr, "\n\n*** on_header_value() called on paused parser ***\n\n");
  2104. abort();
  2105. }
  2106. int
  2107. dontcall_request_url_cb (http_parser *p, const char *buf, size_t len)
  2108. {
  2109. if (p || buf || len) { } // gcc
  2110. fprintf(stderr, "\n\n*** on_request_url() called on paused parser ***\n\n");
  2111. abort();
  2112. }
  2113. int
  2114. dontcall_body_cb (http_parser *p, const char *buf, size_t len)
  2115. {
  2116. if (p || buf || len) { } // gcc
  2117. fprintf(stderr, "\n\n*** on_body_cb() called on paused parser ***\n\n");
  2118. abort();
  2119. }
  2120. int
  2121. dontcall_headers_complete_cb (http_parser *p)
  2122. {
  2123. if (p) { } // gcc
  2124. fprintf(stderr, "\n\n*** on_headers_complete() called on paused "
  2125. "parser ***\n\n");
  2126. abort();
  2127. }
  2128. int
  2129. dontcall_message_complete_cb (http_parser *p)
  2130. {
  2131. if (p) { } // gcc
  2132. fprintf(stderr, "\n\n*** on_message_complete() called on paused "
  2133. "parser ***\n\n");
  2134. abort();
  2135. }
  2136. int
  2137. dontcall_response_status_cb (http_parser *p, const char *buf, size_t len)
  2138. {
  2139. if (p || buf || len) { } // gcc
  2140. fprintf(stderr, "\n\n*** on_status() called on paused parser ***\n\n");
  2141. abort();
  2142. }
  2143. int
  2144. dontcall_chunk_header_cb (http_parser *p)
  2145. {
  2146. if (p) { } // gcc
  2147. fprintf(stderr, "\n\n*** on_chunk_header() called on paused parser ***\n\n");
  2148. exit(1);
  2149. }
  2150. int
  2151. dontcall_chunk_complete_cb (http_parser *p)
  2152. {
  2153. if (p) { } // gcc
  2154. fprintf(stderr, "\n\n*** on_chunk_complete() "
  2155. "called on paused parser ***\n\n");
  2156. exit(1);
  2157. }
  2158. static http_parser_settings settings_dontcall =
  2159. {.on_message_begin = dontcall_message_begin_cb
  2160. ,.on_header_field = dontcall_header_field_cb
  2161. ,.on_header_value = dontcall_header_value_cb
  2162. ,.on_url = dontcall_request_url_cb
  2163. ,.on_status = dontcall_response_status_cb
  2164. ,.on_body = dontcall_body_cb
  2165. ,.on_headers_complete = dontcall_headers_complete_cb
  2166. ,.on_message_complete = dontcall_message_complete_cb
  2167. ,.on_chunk_header = dontcall_chunk_header_cb
  2168. ,.on_chunk_complete = dontcall_chunk_complete_cb
  2169. };
  2170. /* These pause_* callbacks always pause the parser and just invoke the regular
  2171. * callback that tracks content. Before returning, we overwrite the parser
  2172. * settings to point to the _dontcall variety so that we can verify that
  2173. * the pause actually did, you know, pause. */
  2174. int
  2175. pause_message_begin_cb (http_parser *p)
  2176. {
  2177. http_parser_pause(p, 1);
  2178. *current_pause_parser = settings_dontcall;
  2179. return message_begin_cb(p);
  2180. }
  2181. int
  2182. pause_header_field_cb (http_parser *p, const char *buf, size_t len)
  2183. {
  2184. http_parser_pause(p, 1);
  2185. *current_pause_parser = settings_dontcall;
  2186. return header_field_cb(p, buf, len);
  2187. }
  2188. int
  2189. pause_header_value_cb (http_parser *p, const char *buf, size_t len)
  2190. {
  2191. http_parser_pause(p, 1);
  2192. *current_pause_parser = settings_dontcall;
  2193. return header_value_cb(p, buf, len);
  2194. }
  2195. int
  2196. pause_request_url_cb (http_parser *p, const char *buf, size_t len)
  2197. {
  2198. http_parser_pause(p, 1);
  2199. *current_pause_parser = settings_dontcall;
  2200. return request_url_cb(p, buf, len);
  2201. }
  2202. int
  2203. pause_body_cb (http_parser *p, const char *buf, size_t len)
  2204. {
  2205. http_parser_pause(p, 1);
  2206. *current_pause_parser = settings_dontcall;
  2207. return body_cb(p, buf, len);
  2208. }
  2209. int
  2210. pause_headers_complete_cb (http_parser *p)
  2211. {
  2212. http_parser_pause(p, 1);
  2213. *current_pause_parser = settings_dontcall;
  2214. return headers_complete_cb(p);
  2215. }
  2216. int
  2217. pause_message_complete_cb (http_parser *p)
  2218. {
  2219. http_parser_pause(p, 1);
  2220. *current_pause_parser = settings_dontcall;
  2221. return message_complete_cb(p);
  2222. }
  2223. int
  2224. pause_response_status_cb (http_parser *p, const char *buf, size_t len)
  2225. {
  2226. http_parser_pause(p, 1);
  2227. *current_pause_parser = settings_dontcall;
  2228. return response_status_cb(p, buf, len);
  2229. }
  2230. int
  2231. pause_chunk_header_cb (http_parser *p)
  2232. {
  2233. http_parser_pause(p, 1);
  2234. *current_pause_parser = settings_dontcall;
  2235. return chunk_header_cb(p);
  2236. }
  2237. int
  2238. pause_chunk_complete_cb (http_parser *p)
  2239. {
  2240. http_parser_pause(p, 1);
  2241. *current_pause_parser = settings_dontcall;
  2242. return chunk_complete_cb(p);
  2243. }
  2244. int
  2245. connect_headers_complete_cb (http_parser *p)
  2246. {
  2247. headers_complete_cb(p);
  2248. return 1;
  2249. }
  2250. int
  2251. connect_message_complete_cb (http_parser *p)
  2252. {
  2253. messages[num_messages].should_keep_alive = http_should_keep_alive(&parser);
  2254. return message_complete_cb(p);
  2255. }
  2256. static http_parser_settings settings_pause =
  2257. {.on_message_begin = pause_message_begin_cb
  2258. ,.on_header_field = pause_header_field_cb
  2259. ,.on_header_value = pause_header_value_cb
  2260. ,.on_url = pause_request_url_cb
  2261. ,.on_status = pause_response_status_cb
  2262. ,.on_body = pause_body_cb
  2263. ,.on_headers_complete = pause_headers_complete_cb
  2264. ,.on_message_complete = pause_message_complete_cb
  2265. ,.on_chunk_header = pause_chunk_header_cb
  2266. ,.on_chunk_complete = pause_chunk_complete_cb
  2267. };
  2268. static http_parser_settings settings =
  2269. {.on_message_begin = message_begin_cb
  2270. ,.on_header_field = header_field_cb
  2271. ,.on_header_value = header_value_cb
  2272. ,.on_url = request_url_cb
  2273. ,.on_status = response_status_cb
  2274. ,.on_body = body_cb
  2275. ,.on_headers_complete = headers_complete_cb
  2276. ,.on_message_complete = message_complete_cb
  2277. ,.on_chunk_header = chunk_header_cb
  2278. ,.on_chunk_complete = chunk_complete_cb
  2279. };
  2280. static http_parser_settings settings_count_body =
  2281. {.on_message_begin = message_begin_cb
  2282. ,.on_header_field = header_field_cb
  2283. ,.on_header_value = header_value_cb
  2284. ,.on_url = request_url_cb
  2285. ,.on_status = response_status_cb
  2286. ,.on_body = count_body_cb
  2287. ,.on_headers_complete = headers_complete_cb
  2288. ,.on_message_complete = message_complete_cb
  2289. ,.on_chunk_header = chunk_header_cb
  2290. ,.on_chunk_complete = chunk_complete_cb
  2291. };
  2292. static http_parser_settings settings_connect =
  2293. {.on_message_begin = message_begin_cb
  2294. ,.on_header_field = header_field_cb
  2295. ,.on_header_value = header_value_cb
  2296. ,.on_url = request_url_cb
  2297. ,.on_status = response_status_cb
  2298. ,.on_body = dontcall_body_cb
  2299. ,.on_headers_complete = connect_headers_complete_cb
  2300. ,.on_message_complete = connect_message_complete_cb
  2301. ,.on_chunk_header = chunk_header_cb
  2302. ,.on_chunk_complete = chunk_complete_cb
  2303. };
  2304. static http_parser_settings settings_null =
  2305. {.on_message_begin = 0
  2306. ,.on_header_field = 0
  2307. ,.on_header_value = 0
  2308. ,.on_url = 0
  2309. ,.on_status = 0
  2310. ,.on_body = 0
  2311. ,.on_headers_complete = 0
  2312. ,.on_message_complete = 0
  2313. ,.on_chunk_header = 0
  2314. ,.on_chunk_complete = 0
  2315. };
  2316. void
  2317. parser_init (enum http_parser_type type)
  2318. {
  2319. num_messages = 0;
  2320. http_parser_init(&parser, type);
  2321. memset(&messages, 0, sizeof messages);
  2322. }
  2323. size_t parse (const char *buf, size_t len)
  2324. {
  2325. size_t nparsed;
  2326. currently_parsing_eof = (len == 0);
  2327. nparsed = http_parser_execute(&parser, &settings, buf, len);
  2328. return nparsed;
  2329. }
  2330. size_t parse_count_body (const char *buf, size_t len)
  2331. {
  2332. size_t nparsed;
  2333. currently_parsing_eof = (len == 0);
  2334. nparsed = http_parser_execute(&parser, &settings_count_body, buf, len);
  2335. return nparsed;
  2336. }
  2337. size_t parse_pause (const char *buf, size_t len)
  2338. {
  2339. size_t nparsed;
  2340. http_parser_settings s = settings_pause;
  2341. currently_parsing_eof = (len == 0);
  2342. current_pause_parser = &s;
  2343. nparsed = http_parser_execute(&parser, current_pause_parser, buf, len);
  2344. return nparsed;
  2345. }
  2346. size_t parse_connect (const char *buf, size_t len)
  2347. {
  2348. size_t nparsed;
  2349. currently_parsing_eof = (len == 0);
  2350. nparsed = http_parser_execute(&parser, &settings_connect, buf, len);
  2351. return nparsed;
  2352. }
  2353. static inline int
  2354. check_str_eq (const struct message *m,
  2355. const char *prop,
  2356. const char *expected,
  2357. const char *found) {
  2358. if ((expected == NULL) != (found == NULL)) {
  2359. printf("\n*** Error: %s in '%s' ***\n\n", prop, m->name);
  2360. printf("expected %s\n", (expected == NULL) ? "NULL" : expected);
  2361. printf(" found %s\n", (found == NULL) ? "NULL" : found);
  2362. return 0;
  2363. }
  2364. if (expected != NULL && 0 != strcmp(expected, found)) {
  2365. printf("\n*** Error: %s in '%s' ***\n\n", prop, m->name);
  2366. printf("expected '%s'\n", expected);
  2367. printf(" found '%s'\n", found);
  2368. return 0;
  2369. }
  2370. return 1;
  2371. }
  2372. static inline int
  2373. check_num_eq (const struct message *m,
  2374. const char *prop,
  2375. int expected,
  2376. int found) {
  2377. if (expected != found) {
  2378. printf("\n*** Error: %s in '%s' ***\n\n", prop, m->name);
  2379. printf("expected %d\n", expected);
  2380. printf(" found %d\n", found);
  2381. return 0;
  2382. }
  2383. return 1;
  2384. }
  2385. #define MESSAGE_CHECK_STR_EQ(expected, found, prop) \
  2386. if (!check_str_eq(expected, #prop, expected->prop, found->prop)) return 0
  2387. #define MESSAGE_CHECK_NUM_EQ(expected, found, prop) \
  2388. if (!check_num_eq(expected, #prop, expected->prop, found->prop)) return 0
  2389. #define MESSAGE_CHECK_URL_EQ(u, expected, found, prop, fn) \
  2390. do { \
  2391. char ubuf[256]; \
  2392. \
  2393. if ((u)->field_set & (1 << (fn))) { \
  2394. memcpy(ubuf, (found)->request_url + (u)->field_data[(fn)].off, \
  2395. (u)->field_data[(fn)].len); \
  2396. ubuf[(u)->field_data[(fn)].len] = '\0'; \
  2397. } else { \
  2398. ubuf[0] = '\0'; \
  2399. } \
  2400. \
  2401. check_str_eq(expected, #prop, expected->prop, ubuf); \
  2402. } while(0)
  2403. int
  2404. message_eq (int index, int connect, const struct message *expected)
  2405. {
  2406. int i;
  2407. struct message *m = &messages[index];
  2408. MESSAGE_CHECK_NUM_EQ(expected, m, http_major);
  2409. MESSAGE_CHECK_NUM_EQ(expected, m, http_minor);
  2410. if (expected->type == HTTP_REQUEST) {
  2411. MESSAGE_CHECK_NUM_EQ(expected, m, method);
  2412. } else {
  2413. MESSAGE_CHECK_NUM_EQ(expected, m, status_code);
  2414. MESSAGE_CHECK_STR_EQ(expected, m, response_status);
  2415. assert(m->status_cb_called);
  2416. }
  2417. if (!connect) {
  2418. MESSAGE_CHECK_NUM_EQ(expected, m, should_keep_alive);
  2419. MESSAGE_CHECK_NUM_EQ(expected, m, message_complete_on_eof);
  2420. }
  2421. assert(m->message_begin_cb_called);
  2422. assert(m->headers_complete_cb_called);
  2423. assert(m->message_complete_cb_called);
  2424. MESSAGE_CHECK_STR_EQ(expected, m, request_url);
  2425. /* Check URL components; we can't do this w/ CONNECT since it doesn't
  2426. * send us a well-formed URL.
  2427. */
  2428. if (*m->request_url && m->method != HTTP_CONNECT) {
  2429. struct http_parser_url u;
  2430. if (http_parser_parse_url(m->request_url, strlen(m->request_url), 0, &u)) {
  2431. fprintf(stderr, "\n\n*** failed to parse URL %s ***\n\n",
  2432. m->request_url);
  2433. abort();
  2434. }
  2435. if (expected->host) {
  2436. MESSAGE_CHECK_URL_EQ(&u, expected, m, host, UF_HOST);
  2437. }
  2438. if (expected->userinfo) {
  2439. MESSAGE_CHECK_URL_EQ(&u, expected, m, userinfo, UF_USERINFO);
  2440. }
  2441. m->port = (u.field_set & (1 << UF_PORT)) ?
  2442. u.port : 0;
  2443. MESSAGE_CHECK_URL_EQ(&u, expected, m, query_string, UF_QUERY);
  2444. MESSAGE_CHECK_URL_EQ(&u, expected, m, fragment, UF_FRAGMENT);
  2445. MESSAGE_CHECK_URL_EQ(&u, expected, m, request_path, UF_PATH);
  2446. MESSAGE_CHECK_NUM_EQ(expected, m, port);
  2447. }
  2448. if (connect) {
  2449. check_num_eq(m, "body_size", 0, m->body_size);
  2450. } else if (expected->body_size) {
  2451. MESSAGE_CHECK_NUM_EQ(expected, m, body_size);
  2452. } else {
  2453. MESSAGE_CHECK_STR_EQ(expected, m, body);
  2454. }
  2455. if (connect) {
  2456. check_num_eq(m, "num_chunks_complete", 0, m->num_chunks_complete);
  2457. } else {
  2458. assert(m->num_chunks == m->num_chunks_complete);
  2459. MESSAGE_CHECK_NUM_EQ(expected, m, num_chunks_complete);
  2460. for (i = 0; i < m->num_chunks && i < MAX_CHUNKS; i++) {
  2461. MESSAGE_CHECK_NUM_EQ(expected, m, chunk_lengths[i]);
  2462. }
  2463. }
  2464. MESSAGE_CHECK_NUM_EQ(expected, m, num_headers);
  2465. int r;
  2466. for (i = 0; i < m->num_headers; i++) {
  2467. r = check_str_eq(expected, "header field", expected->headers[i][0], m->headers[i][0]);
  2468. if (!r) return 0;
  2469. r = check_str_eq(expected, "header value", expected->headers[i][1], m->headers[i][1]);
  2470. if (!r) return 0;
  2471. }
  2472. if (!connect) {
  2473. MESSAGE_CHECK_STR_EQ(expected, m, upgrade);
  2474. }
  2475. return 1;
  2476. }
  2477. /* Given a sequence of varargs messages, return the number of them that the
  2478. * parser should successfully parse, taking into account that upgraded
  2479. * messages prevent all subsequent messages from being parsed.
  2480. */
  2481. size_t
  2482. count_parsed_messages(const size_t nmsgs, ...) {
  2483. size_t i;
  2484. va_list ap;
  2485. va_start(ap, nmsgs);
  2486. for (i = 0; i < nmsgs; i++) {
  2487. struct message *m = va_arg(ap, struct message *);
  2488. if (m->upgrade) {
  2489. va_end(ap);
  2490. return i + 1;
  2491. }
  2492. }
  2493. va_end(ap);
  2494. return nmsgs;
  2495. }
  2496. /* Given a sequence of bytes and the number of these that we were able to
  2497. * parse, verify that upgrade bodies are correct.
  2498. */
  2499. void
  2500. upgrade_message_fix(char *body, const size_t nread, const size_t nmsgs, ...) {
  2501. va_list ap;
  2502. size_t i;
  2503. size_t off = 0;
  2504. va_start(ap, nmsgs);
  2505. for (i = 0; i < nmsgs; i++) {
  2506. struct message *m = va_arg(ap, struct message *);
  2507. off += strlen(m->raw);
  2508. if (m->upgrade) {
  2509. off -= strlen(m->upgrade);
  2510. /* Check the portion of the response after its specified upgrade */
  2511. if (!check_str_eq(m, "upgrade", body + off, body + nread)) {
  2512. abort();
  2513. }
  2514. /* Fix up the response so that message_eq() will verify the beginning
  2515. * of the upgrade */
  2516. *(body + nread + strlen(m->upgrade)) = '\0';
  2517. messages[num_messages -1 ].upgrade = body + nread;
  2518. va_end(ap);
  2519. return;
  2520. }
  2521. }
  2522. va_end(ap);
  2523. printf("\n\n*** Error: expected a message with upgrade ***\n");
  2524. abort();
  2525. }
  2526. static void
  2527. print_error (const char *raw, size_t error_location)
  2528. {
  2529. fprintf(stderr, "\n*** %s ***\n\n",
  2530. http_errno_description(HTTP_PARSER_ERRNO(&parser)));
  2531. int this_line = 0, char_len = 0;
  2532. size_t i, j, len = strlen(raw), error_location_line = 0;
  2533. for (i = 0; i < len; i++) {
  2534. if (i == error_location) this_line = 1;
  2535. switch (raw[i]) {
  2536. case '\r':
  2537. char_len = 2;
  2538. fprintf(stderr, "\\r");
  2539. break;
  2540. case '\n':
  2541. fprintf(stderr, "\\n\n");
  2542. if (this_line) goto print;
  2543. error_location_line = 0;
  2544. continue;
  2545. default:
  2546. char_len = 1;
  2547. fputc(raw[i], stderr);
  2548. break;
  2549. }
  2550. if (!this_line) error_location_line += char_len;
  2551. }
  2552. fprintf(stderr, "[eof]\n");
  2553. print:
  2554. for (j = 0; j < error_location_line; j++) {
  2555. fputc(' ', stderr);
  2556. }
  2557. fprintf(stderr, "^\n\nerror location: %u\n", (unsigned int)error_location);
  2558. }
  2559. void
  2560. test_preserve_data (void)
  2561. {
  2562. char my_data[] = "application-specific data";
  2563. http_parser parser;
  2564. parser.data = my_data;
  2565. http_parser_init(&parser, HTTP_REQUEST);
  2566. if (parser.data != my_data) {
  2567. printf("\n*** parser.data not preserved accross http_parser_init ***\n\n");
  2568. abort();
  2569. }
  2570. }
  2571. struct url_test {
  2572. const char *name;
  2573. const char *url;
  2574. int is_connect;
  2575. struct http_parser_url u;
  2576. int rv;
  2577. };
  2578. const struct url_test url_tests[] =
  2579. { {.name="proxy request"
  2580. ,.url="http://hostname/"
  2581. ,.is_connect=0
  2582. ,.u=
  2583. {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PATH)
  2584. ,.port=0
  2585. ,.field_data=
  2586. {{ 0, 4 } /* UF_SCHEMA */
  2587. ,{ 7, 8 } /* UF_HOST */
  2588. ,{ 0, 0 } /* UF_PORT */
  2589. ,{ 15, 1 } /* UF_PATH */
  2590. ,{ 0, 0 } /* UF_QUERY */
  2591. ,{ 0, 0 } /* UF_FRAGMENT */
  2592. ,{ 0, 0 } /* UF_USERINFO */
  2593. }
  2594. }
  2595. ,.rv=0
  2596. }
  2597. , {.name="proxy request with port"
  2598. ,.url="http://hostname:444/"
  2599. ,.is_connect=0
  2600. ,.u=
  2601. {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PORT) | (1 << UF_PATH)
  2602. ,.port=444
  2603. ,.field_data=
  2604. {{ 0, 4 } /* UF_SCHEMA */
  2605. ,{ 7, 8 } /* UF_HOST */
  2606. ,{ 16, 3 } /* UF_PORT */
  2607. ,{ 19, 1 } /* UF_PATH */
  2608. ,{ 0, 0 } /* UF_QUERY */
  2609. ,{ 0, 0 } /* UF_FRAGMENT */
  2610. ,{ 0, 0 } /* UF_USERINFO */
  2611. }
  2612. }
  2613. ,.rv=0
  2614. }
  2615. , {.name="CONNECT request"
  2616. ,.url="hostname:443"
  2617. ,.is_connect=1
  2618. ,.u=
  2619. {.field_set=(1 << UF_HOST) | (1 << UF_PORT)
  2620. ,.port=443
  2621. ,.field_data=
  2622. {{ 0, 0 } /* UF_SCHEMA */
  2623. ,{ 0, 8 } /* UF_HOST */
  2624. ,{ 9, 3 } /* UF_PORT */
  2625. ,{ 0, 0 } /* UF_PATH */
  2626. ,{ 0, 0 } /* UF_QUERY */
  2627. ,{ 0, 0 } /* UF_FRAGMENT */
  2628. ,{ 0, 0 } /* UF_USERINFO */
  2629. }
  2630. }
  2631. ,.rv=0
  2632. }
  2633. , {.name="CONNECT request but not connect"
  2634. ,.url="hostname:443"
  2635. ,.is_connect=0
  2636. ,.rv=1
  2637. }
  2638. , {.name="proxy ipv6 request"
  2639. ,.url="http://[1:2::3:4]/"
  2640. ,.is_connect=0
  2641. ,.u=
  2642. {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PATH)
  2643. ,.port=0
  2644. ,.field_data=
  2645. {{ 0, 4 } /* UF_SCHEMA */
  2646. ,{ 8, 8 } /* UF_HOST */
  2647. ,{ 0, 0 } /* UF_PORT */
  2648. ,{ 17, 1 } /* UF_PATH */
  2649. ,{ 0, 0 } /* UF_QUERY */
  2650. ,{ 0, 0 } /* UF_FRAGMENT */
  2651. ,{ 0, 0 } /* UF_USERINFO */
  2652. }
  2653. }
  2654. ,.rv=0
  2655. }
  2656. , {.name="proxy ipv6 request with port"
  2657. ,.url="http://[1:2::3:4]:67/"
  2658. ,.is_connect=0
  2659. ,.u=
  2660. {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PORT) | (1 << UF_PATH)
  2661. ,.port=67
  2662. ,.field_data=
  2663. {{ 0, 4 } /* UF_SCHEMA */
  2664. ,{ 8, 8 } /* UF_HOST */
  2665. ,{ 18, 2 } /* UF_PORT */
  2666. ,{ 20, 1 } /* UF_PATH */
  2667. ,{ 0, 0 } /* UF_QUERY */
  2668. ,{ 0, 0 } /* UF_FRAGMENT */
  2669. ,{ 0, 0 } /* UF_USERINFO */
  2670. }
  2671. }
  2672. ,.rv=0
  2673. }
  2674. , {.name="CONNECT ipv6 address"
  2675. ,.url="[1:2::3:4]:443"
  2676. ,.is_connect=1
  2677. ,.u=
  2678. {.field_set=(1 << UF_HOST) | (1 << UF_PORT)
  2679. ,.port=443
  2680. ,.field_data=
  2681. {{ 0, 0 } /* UF_SCHEMA */
  2682. ,{ 1, 8 } /* UF_HOST */
  2683. ,{ 11, 3 } /* UF_PORT */
  2684. ,{ 0, 0 } /* UF_PATH */
  2685. ,{ 0, 0 } /* UF_QUERY */
  2686. ,{ 0, 0 } /* UF_FRAGMENT */
  2687. ,{ 0, 0 } /* UF_USERINFO */
  2688. }
  2689. }
  2690. ,.rv=0
  2691. }
  2692. , {.name="ipv4 in ipv6 address"
  2693. ,.url="http://[2001:0000:0000:0000:0000:0000:1.9.1.1]/"
  2694. ,.is_connect=0
  2695. ,.u=
  2696. {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PATH)
  2697. ,.port=0
  2698. ,.field_data=
  2699. {{ 0, 4 } /* UF_SCHEMA */
  2700. ,{ 8, 37 } /* UF_HOST */
  2701. ,{ 0, 0 } /* UF_PORT */
  2702. ,{ 46, 1 } /* UF_PATH */
  2703. ,{ 0, 0 } /* UF_QUERY */
  2704. ,{ 0, 0 } /* UF_FRAGMENT */
  2705. ,{ 0, 0 } /* UF_USERINFO */
  2706. }
  2707. }
  2708. ,.rv=0
  2709. }
  2710. , {.name="extra ? in query string"
  2711. ,.url="http://a.tbcdn.cn/p/fp/2010c/??fp-header-min.css,fp-base-min.css,"
  2712. "fp-channel-min.css,fp-product-min.css,fp-mall-min.css,fp-category-min.css,"
  2713. "fp-sub-min.css,fp-gdp4p-min.css,fp-css3-min.css,fp-misc-min.css?t=20101022.css"
  2714. ,.is_connect=0
  2715. ,.u=
  2716. {.field_set=(1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_QUERY)
  2717. ,.port=0
  2718. ,.field_data=
  2719. {{ 0, 4 } /* UF_SCHEMA */
  2720. ,{ 7, 10 } /* UF_HOST */
  2721. ,{ 0, 0 } /* UF_PORT */
  2722. ,{ 17, 12 } /* UF_PATH */
  2723. ,{ 30,187 } /* UF_QUERY */
  2724. ,{ 0, 0 } /* UF_FRAGMENT */
  2725. ,{ 0, 0 } /* UF_USERINFO */
  2726. }
  2727. }
  2728. ,.rv=0
  2729. }
  2730. , {.name="space URL encoded"
  2731. ,.url="/toto.html?toto=a%20b"
  2732. ,.is_connect=0
  2733. ,.u=
  2734. {.field_set= (1<<UF_PATH) | (1<<UF_QUERY)
  2735. ,.port=0
  2736. ,.field_data=
  2737. {{ 0, 0 } /* UF_SCHEMA */
  2738. ,{ 0, 0 } /* UF_HOST */
  2739. ,{ 0, 0 } /* UF_PORT */
  2740. ,{ 0, 10 } /* UF_PATH */
  2741. ,{ 11, 10 } /* UF_QUERY */
  2742. ,{ 0, 0 } /* UF_FRAGMENT */
  2743. ,{ 0, 0 } /* UF_USERINFO */
  2744. }
  2745. }
  2746. ,.rv=0
  2747. }
  2748. , {.name="URL fragment"
  2749. ,.url="/toto.html#titi"
  2750. ,.is_connect=0
  2751. ,.u=
  2752. {.field_set= (1<<UF_PATH) | (1<<UF_FRAGMENT)
  2753. ,.port=0
  2754. ,.field_data=
  2755. {{ 0, 0 } /* UF_SCHEMA */
  2756. ,{ 0, 0 } /* UF_HOST */
  2757. ,{ 0, 0 } /* UF_PORT */
  2758. ,{ 0, 10 } /* UF_PATH */
  2759. ,{ 0, 0 } /* UF_QUERY */
  2760. ,{ 11, 4 } /* UF_FRAGMENT */
  2761. ,{ 0, 0 } /* UF_USERINFO */
  2762. }
  2763. }
  2764. ,.rv=0
  2765. }
  2766. , {.name="complex URL fragment"
  2767. ,.url="http://www.webmasterworld.com/r.cgi?f=21&d=8405&url="
  2768. "http://www.example.com/index.html?foo=bar&hello=world#midpage"
  2769. ,.is_connect=0
  2770. ,.u=
  2771. {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_QUERY) |\
  2772. (1<<UF_FRAGMENT)
  2773. ,.port=0
  2774. ,.field_data=
  2775. {{ 0, 4 } /* UF_SCHEMA */
  2776. ,{ 7, 22 } /* UF_HOST */
  2777. ,{ 0, 0 } /* UF_PORT */
  2778. ,{ 29, 6 } /* UF_PATH */
  2779. ,{ 36, 69 } /* UF_QUERY */
  2780. ,{106, 7 } /* UF_FRAGMENT */
  2781. ,{ 0, 0 } /* UF_USERINFO */
  2782. }
  2783. }
  2784. ,.rv=0
  2785. }
  2786. , {.name="complex URL from node js url parser doc"
  2787. ,.url="http://host.com:8080/p/a/t/h?query=string#hash"
  2788. ,.is_connect=0
  2789. ,.u=
  2790. {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PORT) | (1<<UF_PATH) |\
  2791. (1<<UF_QUERY) | (1<<UF_FRAGMENT)
  2792. ,.port=8080
  2793. ,.field_data=
  2794. {{ 0, 4 } /* UF_SCHEMA */
  2795. ,{ 7, 8 } /* UF_HOST */
  2796. ,{ 16, 4 } /* UF_PORT */
  2797. ,{ 20, 8 } /* UF_PATH */
  2798. ,{ 29, 12 } /* UF_QUERY */
  2799. ,{ 42, 4 } /* UF_FRAGMENT */
  2800. ,{ 0, 0 } /* UF_USERINFO */
  2801. }
  2802. }
  2803. ,.rv=0
  2804. }
  2805. , {.name="complex URL with basic auth from node js url parser doc"
  2806. ,.url="http://a:b@host.com:8080/p/a/t/h?query=string#hash"
  2807. ,.is_connect=0
  2808. ,.u=
  2809. {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PORT) | (1<<UF_PATH) |\
  2810. (1<<UF_QUERY) | (1<<UF_FRAGMENT) | (1<<UF_USERINFO)
  2811. ,.port=8080
  2812. ,.field_data=
  2813. {{ 0, 4 } /* UF_SCHEMA */
  2814. ,{ 11, 8 } /* UF_HOST */
  2815. ,{ 20, 4 } /* UF_PORT */
  2816. ,{ 24, 8 } /* UF_PATH */
  2817. ,{ 33, 12 } /* UF_QUERY */
  2818. ,{ 46, 4 } /* UF_FRAGMENT */
  2819. ,{ 7, 3 } /* UF_USERINFO */
  2820. }
  2821. }
  2822. ,.rv=0
  2823. }
  2824. , {.name="double @"
  2825. ,.url="http://a:b@@hostname:443/"
  2826. ,.is_connect=0
  2827. ,.rv=1
  2828. }
  2829. , {.name="proxy empty host"
  2830. ,.url="http://:443/"
  2831. ,.is_connect=0
  2832. ,.rv=1
  2833. }
  2834. , {.name="proxy empty port"
  2835. ,.url="http://hostname:/"
  2836. ,.is_connect=0
  2837. ,.rv=1
  2838. }
  2839. , {.name="CONNECT with basic auth"
  2840. ,.url="a:b@hostname:443"
  2841. ,.is_connect=1
  2842. ,.rv=1
  2843. }
  2844. , {.name="CONNECT empty host"
  2845. ,.url=":443"
  2846. ,.is_connect=1
  2847. ,.rv=1
  2848. }
  2849. , {.name="CONNECT empty port"
  2850. ,.url="hostname:"
  2851. ,.is_connect=1
  2852. ,.rv=1
  2853. }
  2854. , {.name="CONNECT with extra bits"
  2855. ,.url="hostname:443/"
  2856. ,.is_connect=1
  2857. ,.rv=1
  2858. }
  2859. , {.name="space in URL"
  2860. ,.url="/foo bar/"
  2861. ,.rv=1 /* s_dead */
  2862. }
  2863. , {.name="proxy basic auth with space url encoded"
  2864. ,.url="http://a%20:b@host.com/"
  2865. ,.is_connect=0
  2866. ,.u=
  2867. {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_USERINFO)
  2868. ,.port=0
  2869. ,.field_data=
  2870. {{ 0, 4 } /* UF_SCHEMA */
  2871. ,{ 14, 8 } /* UF_HOST */
  2872. ,{ 0, 0 } /* UF_PORT */
  2873. ,{ 22, 1 } /* UF_PATH */
  2874. ,{ 0, 0 } /* UF_QUERY */
  2875. ,{ 0, 0 } /* UF_FRAGMENT */
  2876. ,{ 7, 6 } /* UF_USERINFO */
  2877. }
  2878. }
  2879. ,.rv=0
  2880. }
  2881. , {.name="carriage return in URL"
  2882. ,.url="/foo\rbar/"
  2883. ,.rv=1 /* s_dead */
  2884. }
  2885. , {.name="proxy double : in URL"
  2886. ,.url="http://hostname::443/"
  2887. ,.rv=1 /* s_dead */
  2888. }
  2889. , {.name="proxy basic auth with double :"
  2890. ,.url="http://a::b@host.com/"
  2891. ,.is_connect=0
  2892. ,.u=
  2893. {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_USERINFO)
  2894. ,.port=0
  2895. ,.field_data=
  2896. {{ 0, 4 } /* UF_SCHEMA */
  2897. ,{ 12, 8 } /* UF_HOST */
  2898. ,{ 0, 0 } /* UF_PORT */
  2899. ,{ 20, 1 } /* UF_PATH */
  2900. ,{ 0, 0 } /* UF_QUERY */
  2901. ,{ 0, 0 } /* UF_FRAGMENT */
  2902. ,{ 7, 4 } /* UF_USERINFO */
  2903. }
  2904. }
  2905. ,.rv=0
  2906. }
  2907. , {.name="line feed in URL"
  2908. ,.url="/foo\nbar/"
  2909. ,.rv=1 /* s_dead */
  2910. }
  2911. , {.name="proxy empty basic auth"
  2912. ,.url="http://@hostname/fo"
  2913. ,.u=
  2914. {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH)
  2915. ,.port=0
  2916. ,.field_data=
  2917. {{ 0, 4 } /* UF_SCHEMA */
  2918. ,{ 8, 8 } /* UF_HOST */
  2919. ,{ 0, 0 } /* UF_PORT */
  2920. ,{ 16, 3 } /* UF_PATH */
  2921. ,{ 0, 0 } /* UF_QUERY */
  2922. ,{ 0, 0 } /* UF_FRAGMENT */
  2923. ,{ 0, 0 } /* UF_USERINFO */
  2924. }
  2925. }
  2926. ,.rv=0
  2927. }
  2928. , {.name="proxy line feed in hostname"
  2929. ,.url="http://host\name/fo"
  2930. ,.rv=1 /* s_dead */
  2931. }
  2932. , {.name="proxy % in hostname"
  2933. ,.url="http://host%name/fo"
  2934. ,.rv=1 /* s_dead */
  2935. }
  2936. , {.name="proxy ; in hostname"
  2937. ,.url="http://host;ame/fo"
  2938. ,.rv=1 /* s_dead */
  2939. }
  2940. , {.name="proxy basic auth with unreservedchars"
  2941. ,.url="http://a!;-_!=+$@host.com/"
  2942. ,.is_connect=0
  2943. ,.u=
  2944. {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_USERINFO)
  2945. ,.port=0
  2946. ,.field_data=
  2947. {{ 0, 4 } /* UF_SCHEMA */
  2948. ,{ 17, 8 } /* UF_HOST */
  2949. ,{ 0, 0 } /* UF_PORT */
  2950. ,{ 25, 1 } /* UF_PATH */
  2951. ,{ 0, 0 } /* UF_QUERY */
  2952. ,{ 0, 0 } /* UF_FRAGMENT */
  2953. ,{ 7, 9 } /* UF_USERINFO */
  2954. }
  2955. }
  2956. ,.rv=0
  2957. }
  2958. , {.name="proxy only empty basic auth"
  2959. ,.url="http://@/fo"
  2960. ,.rv=1 /* s_dead */
  2961. }
  2962. , {.name="proxy only basic auth"
  2963. ,.url="http://toto@/fo"
  2964. ,.rv=1 /* s_dead */
  2965. }
  2966. , {.name="proxy emtpy hostname"
  2967. ,.url="http:///fo"
  2968. ,.rv=1 /* s_dead */
  2969. }
  2970. , {.name="proxy = in URL"
  2971. ,.url="http://host=ame/fo"
  2972. ,.rv=1 /* s_dead */
  2973. }
  2974. , {.name="ipv6 address with Zone ID"
  2975. ,.url="http://[fe80::a%25eth0]/"
  2976. ,.is_connect=0
  2977. ,.u=
  2978. {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH)
  2979. ,.port=0
  2980. ,.field_data=
  2981. {{ 0, 4 } /* UF_SCHEMA */
  2982. ,{ 8, 14 } /* UF_HOST */
  2983. ,{ 0, 0 } /* UF_PORT */
  2984. ,{ 23, 1 } /* UF_PATH */
  2985. ,{ 0, 0 } /* UF_QUERY */
  2986. ,{ 0, 0 } /* UF_FRAGMENT */
  2987. ,{ 0, 0 } /* UF_USERINFO */
  2988. }
  2989. }
  2990. ,.rv=0
  2991. }
  2992. , {.name="ipv6 address with Zone ID, but '%' is not percent-encoded"
  2993. ,.url="http://[fe80::a%eth0]/"
  2994. ,.is_connect=0
  2995. ,.u=
  2996. {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH)
  2997. ,.port=0
  2998. ,.field_data=
  2999. {{ 0, 4 } /* UF_SCHEMA */
  3000. ,{ 8, 12 } /* UF_HOST */
  3001. ,{ 0, 0 } /* UF_PORT */
  3002. ,{ 21, 1 } /* UF_PATH */
  3003. ,{ 0, 0 } /* UF_QUERY */
  3004. ,{ 0, 0 } /* UF_FRAGMENT */
  3005. ,{ 0, 0 } /* UF_USERINFO */
  3006. }
  3007. }
  3008. ,.rv=0
  3009. }
  3010. , {.name="ipv6 address ending with '%'"
  3011. ,.url="http://[fe80::a%]/"
  3012. ,.rv=1 /* s_dead */
  3013. }
  3014. , {.name="ipv6 address with Zone ID including bad character"
  3015. ,.url="http://[fe80::a%$HOME]/"
  3016. ,.rv=1 /* s_dead */
  3017. }
  3018. , {.name="just ipv6 Zone ID"
  3019. ,.url="http://[%eth0]/"
  3020. ,.rv=1 /* s_dead */
  3021. }
  3022. , {.name="empty url"
  3023. ,.url=""
  3024. ,.is_connect=0
  3025. ,.rv=1
  3026. }
  3027. , {.name="NULL url"
  3028. ,.url=NULL
  3029. ,.is_connect=0
  3030. ,.rv=1
  3031. }
  3032. , {.name="full of spaces url"
  3033. ,.url=" "
  3034. ,.is_connect=0
  3035. ,.rv=1
  3036. }
  3037. #if HTTP_PARSER_STRICT
  3038. , {.name="tab in URL"
  3039. ,.url="/foo\tbar/"
  3040. ,.rv=1 /* s_dead */
  3041. }
  3042. , {.name="form feed in URL"
  3043. ,.url="/foo\fbar/"
  3044. ,.rv=1 /* s_dead */
  3045. }
  3046. #else /* !HTTP_PARSER_STRICT */
  3047. , {.name="tab in URL"
  3048. ,.url="/foo\tbar/"
  3049. ,.u=
  3050. {.field_set=(1 << UF_PATH)
  3051. ,.field_data=
  3052. {{ 0, 0 } /* UF_SCHEMA */
  3053. ,{ 0, 0 } /* UF_HOST */
  3054. ,{ 0, 0 } /* UF_PORT */
  3055. ,{ 0, 9 } /* UF_PATH */
  3056. ,{ 0, 0 } /* UF_QUERY */
  3057. ,{ 0, 0 } /* UF_FRAGMENT */
  3058. ,{ 0, 0 } /* UF_USERINFO */
  3059. }
  3060. }
  3061. ,.rv=0
  3062. }
  3063. , {.name="form feed in URL"
  3064. ,.url="/foo\fbar/"
  3065. ,.u=
  3066. {.field_set=(1 << UF_PATH)
  3067. ,.field_data=
  3068. {{ 0, 0 } /* UF_SCHEMA */
  3069. ,{ 0, 0 } /* UF_HOST */
  3070. ,{ 0, 0 } /* UF_PORT */
  3071. ,{ 0, 9 } /* UF_PATH */
  3072. ,{ 0, 0 } /* UF_QUERY */
  3073. ,{ 0, 0 } /* UF_FRAGMENT */
  3074. ,{ 0, 0 } /* UF_USERINFO */
  3075. }
  3076. }
  3077. ,.rv=0
  3078. }
  3079. #endif
  3080. };
  3081. void
  3082. dump_url (const char *url, const struct http_parser_url *u)
  3083. {
  3084. unsigned int i;
  3085. printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port);
  3086. for (i = 0; i < UF_MAX; i++) {
  3087. if ((u->field_set & (1 << i)) == 0) {
  3088. printf("\tfield_data[%u]: unset\n", i);
  3089. continue;
  3090. }
  3091. printf("\tfield_data[%u]: off: %u len: %u part: \"%.*s\n\"",
  3092. i,
  3093. u->field_data[i].off,
  3094. u->field_data[i].len,
  3095. u->field_data[i].len,
  3096. url + u->field_data[i].off);
  3097. }
  3098. }
  3099. void
  3100. test_parse_url (void)
  3101. {
  3102. struct http_parser_url u;
  3103. const struct url_test *test;
  3104. unsigned int i;
  3105. int rv;
  3106. for (i = 0; i < (sizeof(url_tests) / sizeof(url_tests[0])); i++) {
  3107. test = &url_tests[i];
  3108. memset(&u, 0, sizeof(u));
  3109. rv = http_parser_parse_url(test->url,
  3110. test->url ? strlen(test->url) : 0,
  3111. test->is_connect,
  3112. &u);
  3113. if (test->rv == 0) {
  3114. if (rv != 0) {
  3115. printf("\n*** http_parser_parse_url(\"%s\") \"%s\" test failed, "
  3116. "unexpected rv %d ***\n\n", test->url, test->name, rv);
  3117. abort();
  3118. }
  3119. if (memcmp(&u, &test->u, sizeof(u)) != 0) {
  3120. printf("\n*** http_parser_parse_url(\"%s\") \"%s\" failed ***\n",
  3121. test->url, test->name);
  3122. printf("target http_parser_url:\n");
  3123. dump_url(test->url, &test->u);
  3124. printf("result http_parser_url:\n");
  3125. dump_url(test->url, &u);
  3126. abort();
  3127. }
  3128. } else {
  3129. /* test->rv != 0 */
  3130. if (rv == 0) {
  3131. printf("\n*** http_parser_parse_url(\"%s\") \"%s\" test failed, "
  3132. "unexpected rv %d ***\n\n", test->url, test->name, rv);
  3133. abort();
  3134. }
  3135. }
  3136. }
  3137. }
  3138. void
  3139. test_method_str (void)
  3140. {
  3141. assert(0 == strcmp("GET", http_method_str(HTTP_GET)));
  3142. assert(0 == strcmp("<unknown>", http_method_str(1337)));
  3143. }
  3144. void
  3145. test_status_str (void)
  3146. {
  3147. assert(0 == strcmp("OK", http_status_str(HTTP_STATUS_OK)));
  3148. assert(0 == strcmp("Not Found", http_status_str(HTTP_STATUS_NOT_FOUND)));
  3149. assert(0 == strcmp("<unknown>", http_status_str(1337)));
  3150. }
  3151. void
  3152. test_message (const struct message *message)
  3153. {
  3154. size_t raw_len = strlen(message->raw);
  3155. size_t msg1len;
  3156. for (msg1len = 0; msg1len < raw_len; msg1len++) {
  3157. parser_init(message->type);
  3158. size_t read;
  3159. const char *msg1 = message->raw;
  3160. const char *msg2 = msg1 + msg1len;
  3161. size_t msg2len = raw_len - msg1len;
  3162. if (msg1len) {
  3163. assert(num_messages == 0);
  3164. messages[0].headers_complete_cb_called = FALSE;
  3165. read = parse(msg1, msg1len);
  3166. if (!messages[0].headers_complete_cb_called && parser.nread != read) {
  3167. assert(parser.nread == read);
  3168. print_error(msg1, read);
  3169. abort();
  3170. }
  3171. if (message->upgrade && parser.upgrade && num_messages > 0) {
  3172. messages[num_messages - 1].upgrade = msg1 + read;
  3173. goto test;
  3174. }
  3175. if (read != msg1len) {
  3176. print_error(msg1, read);
  3177. abort();
  3178. }
  3179. }
  3180. read = parse(msg2, msg2len);
  3181. if (message->upgrade && parser.upgrade) {
  3182. messages[num_messages - 1].upgrade = msg2 + read;
  3183. goto test;
  3184. }
  3185. if (read != msg2len) {
  3186. print_error(msg2, read);
  3187. abort();
  3188. }
  3189. read = parse(NULL, 0);
  3190. if (read != 0) {
  3191. print_error(message->raw, read);
  3192. abort();
  3193. }
  3194. test:
  3195. if (num_messages != 1) {
  3196. printf("\n*** num_messages != 1 after testing '%s' ***\n\n", message->name);
  3197. abort();
  3198. }
  3199. if(!message_eq(0, 0, message)) abort();
  3200. }
  3201. }
  3202. void
  3203. test_message_count_body (const struct message *message)
  3204. {
  3205. parser_init(message->type);
  3206. size_t read;
  3207. size_t l = strlen(message->raw);
  3208. size_t i, toread;
  3209. size_t chunk = 4024;
  3210. for (i = 0; i < l; i+= chunk) {
  3211. toread = MIN(l-i, chunk);
  3212. read = parse_count_body(message->raw + i, toread);
  3213. if (read != toread) {
  3214. print_error(message->raw, read);
  3215. abort();
  3216. }
  3217. }
  3218. read = parse_count_body(NULL, 0);
  3219. if (read != 0) {
  3220. print_error(message->raw, read);
  3221. abort();
  3222. }
  3223. if (num_messages != 1) {
  3224. printf("\n*** num_messages != 1 after testing '%s' ***\n\n", message->name);
  3225. abort();
  3226. }
  3227. if(!message_eq(0, 0, message)) abort();
  3228. }
  3229. void
  3230. test_simple_type (const char *buf,
  3231. enum http_errno err_expected,
  3232. enum http_parser_type type)
  3233. {
  3234. parser_init(type);
  3235. enum http_errno err;
  3236. parse(buf, strlen(buf));
  3237. err = HTTP_PARSER_ERRNO(&parser);
  3238. parse(NULL, 0);
  3239. /* In strict mode, allow us to pass with an unexpected HPE_STRICT as
  3240. * long as the caller isn't expecting success.
  3241. */
  3242. #if HTTP_PARSER_STRICT
  3243. if (err_expected != err && err_expected != HPE_OK && err != HPE_STRICT) {
  3244. #else
  3245. if (err_expected != err) {
  3246. #endif
  3247. fprintf(stderr, "\n*** test_simple expected %s, but saw %s ***\n\n%s\n",
  3248. http_errno_name(err_expected), http_errno_name(err), buf);
  3249. abort();
  3250. }
  3251. }
  3252. void
  3253. test_simple (const char *buf, enum http_errno err_expected)
  3254. {
  3255. test_simple_type(buf, err_expected, HTTP_REQUEST);
  3256. }
  3257. void
  3258. test_invalid_header_content (int req, const char* str)
  3259. {
  3260. http_parser parser;
  3261. http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
  3262. size_t parsed;
  3263. const char *buf;
  3264. buf = req ?
  3265. "GET / HTTP/1.1\r\n" :
  3266. "HTTP/1.1 200 OK\r\n";
  3267. parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
  3268. assert(parsed == strlen(buf));
  3269. buf = str;
  3270. size_t buflen = strlen(buf);
  3271. parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
  3272. if (parsed != buflen) {
  3273. assert(HTTP_PARSER_ERRNO(&parser) == HPE_INVALID_HEADER_TOKEN);
  3274. return;
  3275. }
  3276. fprintf(stderr,
  3277. "\n*** Error expected but none in invalid header content test ***\n");
  3278. abort();
  3279. }
  3280. void
  3281. test_invalid_header_field_content_error (int req)
  3282. {
  3283. test_invalid_header_content(req, "Foo: F\01ailure");
  3284. test_invalid_header_content(req, "Foo: B\02ar");
  3285. }
  3286. void
  3287. test_invalid_header_field (int req, const char* str)
  3288. {
  3289. http_parser parser;
  3290. http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
  3291. size_t parsed;
  3292. const char *buf;
  3293. buf = req ?
  3294. "GET / HTTP/1.1\r\n" :
  3295. "HTTP/1.1 200 OK\r\n";
  3296. parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
  3297. assert(parsed == strlen(buf));
  3298. buf = str;
  3299. size_t buflen = strlen(buf);
  3300. parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
  3301. if (parsed != buflen) {
  3302. assert(HTTP_PARSER_ERRNO(&parser) == HPE_INVALID_HEADER_TOKEN);
  3303. return;
  3304. }
  3305. fprintf(stderr,
  3306. "\n*** Error expected but none in invalid header token test ***\n");
  3307. abort();
  3308. }
  3309. void
  3310. test_invalid_header_field_token_error (int req)
  3311. {
  3312. test_invalid_header_field(req, "Fo@: Failure");
  3313. test_invalid_header_field(req, "Foo\01\test: Bar");
  3314. }
  3315. void
  3316. test_double_content_length_error (int req)
  3317. {
  3318. http_parser parser;
  3319. http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
  3320. size_t parsed;
  3321. const char *buf;
  3322. buf = req ?
  3323. "GET / HTTP/1.1\r\n" :
  3324. "HTTP/1.1 200 OK\r\n";
  3325. parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
  3326. assert(parsed == strlen(buf));
  3327. buf = "Content-Length: 0\r\nContent-Length: 1\r\n\r\n";
  3328. size_t buflen = strlen(buf);
  3329. parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
  3330. if (parsed != buflen) {
  3331. assert(HTTP_PARSER_ERRNO(&parser) == HPE_UNEXPECTED_CONTENT_LENGTH);
  3332. return;
  3333. }
  3334. fprintf(stderr,
  3335. "\n*** Error expected but none in double content-length test ***\n");
  3336. abort();
  3337. }
  3338. void
  3339. test_chunked_content_length_error (int req)
  3340. {
  3341. http_parser parser;
  3342. http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
  3343. size_t parsed;
  3344. const char *buf;
  3345. buf = req ?
  3346. "GET / HTTP/1.1\r\n" :
  3347. "HTTP/1.1 200 OK\r\n";
  3348. parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
  3349. assert(parsed == strlen(buf));
  3350. buf = "Transfer-Encoding: chunked\r\nContent-Length: 1\r\n\r\n";
  3351. size_t buflen = strlen(buf);
  3352. parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
  3353. if (parsed != buflen) {
  3354. assert(HTTP_PARSER_ERRNO(&parser) == HPE_UNEXPECTED_CONTENT_LENGTH);
  3355. return;
  3356. }
  3357. fprintf(stderr,
  3358. "\n*** Error expected but none in chunked content-length test ***\n");
  3359. abort();
  3360. }
  3361. void
  3362. test_header_cr_no_lf_error (int req)
  3363. {
  3364. http_parser parser;
  3365. http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
  3366. size_t parsed;
  3367. const char *buf;
  3368. buf = req ?
  3369. "GET / HTTP/1.1\r\n" :
  3370. "HTTP/1.1 200 OK\r\n";
  3371. parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
  3372. assert(parsed == strlen(buf));
  3373. buf = "Foo: 1\rBar: 1\r\n\r\n";
  3374. size_t buflen = strlen(buf);
  3375. parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
  3376. if (parsed != buflen) {
  3377. assert(HTTP_PARSER_ERRNO(&parser) == HPE_LF_EXPECTED);
  3378. return;
  3379. }
  3380. fprintf(stderr,
  3381. "\n*** Error expected but none in header whitespace test ***\n");
  3382. abort();
  3383. }
  3384. void
  3385. test_no_overflow_parse_url (void)
  3386. {
  3387. int rv;
  3388. struct http_parser_url u;
  3389. http_parser_url_init(&u);
  3390. rv = http_parser_parse_url("http://example.com:8001", 22, 0, &u);
  3391. if (rv != 0) {
  3392. fprintf(stderr,
  3393. "\n*** test_no_overflow_parse_url invalid return value=%d\n",
  3394. rv);
  3395. abort();
  3396. }
  3397. if (u.port != 800) {
  3398. fprintf(stderr,
  3399. "\n*** test_no_overflow_parse_url invalid port number=%d\n",
  3400. u.port);
  3401. abort();
  3402. }
  3403. }
  3404. void
  3405. test_header_overflow_error (int req)
  3406. {
  3407. http_parser parser;
  3408. http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
  3409. size_t parsed;
  3410. const char *buf;
  3411. buf = req ? "GET / HTTP/1.1\r\n" : "HTTP/1.0 200 OK\r\n";
  3412. parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
  3413. assert(parsed == strlen(buf));
  3414. buf = "header-key: header-value\r\n";
  3415. size_t buflen = strlen(buf);
  3416. int i;
  3417. for (i = 0; i < 10000; i++) {
  3418. parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
  3419. if (parsed != buflen) {
  3420. //fprintf(stderr, "error found on iter %d\n", i);
  3421. assert(HTTP_PARSER_ERRNO(&parser) == HPE_HEADER_OVERFLOW);
  3422. return;
  3423. }
  3424. }
  3425. fprintf(stderr, "\n*** Error expected but none in header overflow test ***\n");
  3426. abort();
  3427. }
  3428. void
  3429. test_header_nread_value ()
  3430. {
  3431. http_parser parser;
  3432. http_parser_init(&parser, HTTP_REQUEST);
  3433. size_t parsed;
  3434. const char *buf;
  3435. buf = "GET / HTTP/1.1\r\nheader: value\nhdr: value\r\n";
  3436. parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
  3437. assert(parsed == strlen(buf));
  3438. assert(parser.nread == strlen(buf));
  3439. }
  3440. static void
  3441. test_content_length_overflow (const char *buf, size_t buflen, int expect_ok)
  3442. {
  3443. http_parser parser;
  3444. http_parser_init(&parser, HTTP_RESPONSE);
  3445. http_parser_execute(&parser, &settings_null, buf, buflen);
  3446. if (expect_ok)
  3447. assert(HTTP_PARSER_ERRNO(&parser) == HPE_OK);
  3448. else
  3449. assert(HTTP_PARSER_ERRNO(&parser) == HPE_INVALID_CONTENT_LENGTH);
  3450. }
  3451. void
  3452. test_header_content_length_overflow_error (void)
  3453. {
  3454. #define X(size) \
  3455. "HTTP/1.1 200 OK\r\n" \
  3456. "Content-Length: " #size "\r\n" \
  3457. "\r\n"
  3458. const char a[] = X(1844674407370955160); /* 2^64 / 10 - 1 */
  3459. const char b[] = X(18446744073709551615); /* 2^64-1 */
  3460. const char c[] = X(18446744073709551616); /* 2^64 */
  3461. #undef X
  3462. test_content_length_overflow(a, sizeof(a) - 1, 1); /* expect ok */
  3463. test_content_length_overflow(b, sizeof(b) - 1, 0); /* expect failure */
  3464. test_content_length_overflow(c, sizeof(c) - 1, 0); /* expect failure */
  3465. }
  3466. void
  3467. test_chunk_content_length_overflow_error (void)
  3468. {
  3469. #define X(size) \
  3470. "HTTP/1.1 200 OK\r\n" \
  3471. "Transfer-Encoding: chunked\r\n" \
  3472. "\r\n" \
  3473. #size "\r\n" \
  3474. "..."
  3475. const char a[] = X(FFFFFFFFFFFFFFE); /* 2^64 / 16 - 1 */
  3476. const char b[] = X(FFFFFFFFFFFFFFFF); /* 2^64-1 */
  3477. const char c[] = X(10000000000000000); /* 2^64 */
  3478. #undef X
  3479. test_content_length_overflow(a, sizeof(a) - 1, 1); /* expect ok */
  3480. test_content_length_overflow(b, sizeof(b) - 1, 0); /* expect failure */
  3481. test_content_length_overflow(c, sizeof(c) - 1, 0); /* expect failure */
  3482. }
  3483. void
  3484. test_no_overflow_long_body (int req, size_t length)
  3485. {
  3486. http_parser parser;
  3487. http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
  3488. size_t parsed;
  3489. size_t i;
  3490. char buf1[3000];
  3491. size_t buf1len = sprintf(buf1, "%s\r\nConnection: Keep-Alive\r\nContent-Length: %lu\r\n\r\n",
  3492. req ? "POST / HTTP/1.0" : "HTTP/1.0 200 OK", (unsigned long)length);
  3493. parsed = http_parser_execute(&parser, &settings_null, buf1, buf1len);
  3494. if (parsed != buf1len)
  3495. goto err;
  3496. for (i = 0; i < length; i++) {
  3497. char foo = 'a';
  3498. parsed = http_parser_execute(&parser, &settings_null, &foo, 1);
  3499. if (parsed != 1)
  3500. goto err;
  3501. }
  3502. parsed = http_parser_execute(&parser, &settings_null, buf1, buf1len);
  3503. if (parsed != buf1len) goto err;
  3504. return;
  3505. err:
  3506. fprintf(stderr,
  3507. "\n*** error in test_no_overflow_long_body %s of length %lu ***\n",
  3508. req ? "REQUEST" : "RESPONSE",
  3509. (unsigned long)length);
  3510. abort();
  3511. }
  3512. void
  3513. test_multiple3 (const struct message *r1, const struct message *r2, const struct message *r3)
  3514. {
  3515. int message_count = count_parsed_messages(3, r1, r2, r3);
  3516. char total[ strlen(r1->raw)
  3517. + strlen(r2->raw)
  3518. + strlen(r3->raw)
  3519. + 1
  3520. ];
  3521. total[0] = '\0';
  3522. strcat(total, r1->raw);
  3523. strcat(total, r2->raw);
  3524. strcat(total, r3->raw);
  3525. parser_init(r1->type);
  3526. size_t read;
  3527. read = parse(total, strlen(total));
  3528. if (parser.upgrade) {
  3529. upgrade_message_fix(total, read, 3, r1, r2, r3);
  3530. goto test;
  3531. }
  3532. if (read != strlen(total)) {
  3533. print_error(total, read);
  3534. abort();
  3535. }
  3536. read = parse(NULL, 0);
  3537. if (read != 0) {
  3538. print_error(total, read);
  3539. abort();
  3540. }
  3541. test:
  3542. if (message_count != num_messages) {
  3543. fprintf(stderr, "\n\n*** Parser didn't see 3 messages only %d *** \n", num_messages);
  3544. abort();
  3545. }
  3546. if (!message_eq(0, 0, r1)) abort();
  3547. if (message_count > 1 && !message_eq(1, 0, r2)) abort();
  3548. if (message_count > 2 && !message_eq(2, 0, r3)) abort();
  3549. }
  3550. /* SCAN through every possible breaking to make sure the
  3551. * parser can handle getting the content in any chunks that
  3552. * might come from the socket
  3553. */
  3554. void
  3555. test_scan (const struct message *r1, const struct message *r2, const struct message *r3)
  3556. {
  3557. char total[80*1024] = "\0";
  3558. char buf1[80*1024] = "\0";
  3559. char buf2[80*1024] = "\0";
  3560. char buf3[80*1024] = "\0";
  3561. strcat(total, r1->raw);
  3562. strcat(total, r2->raw);
  3563. strcat(total, r3->raw);
  3564. size_t read;
  3565. int total_len = strlen(total);
  3566. int total_ops = 2 * (total_len - 1) * (total_len - 2) / 2;
  3567. int ops = 0 ;
  3568. size_t buf1_len, buf2_len, buf3_len;
  3569. int message_count = count_parsed_messages(3, r1, r2, r3);
  3570. int i,j,type_both;
  3571. for (type_both = 0; type_both < 2; type_both ++ ) {
  3572. for (j = 2; j < total_len; j ++ ) {
  3573. for (i = 1; i < j; i ++ ) {
  3574. if (ops % 1000 == 0) {
  3575. printf("\b\b\b\b%3.0f%%", 100 * (float)ops /(float)total_ops);
  3576. fflush(stdout);
  3577. }
  3578. ops += 1;
  3579. parser_init(type_both ? HTTP_BOTH : r1->type);
  3580. buf1_len = i;
  3581. strlncpy(buf1, sizeof(buf1), total, buf1_len);
  3582. buf1[buf1_len] = 0;
  3583. buf2_len = j - i;
  3584. strlncpy(buf2, sizeof(buf1), total+i, buf2_len);
  3585. buf2[buf2_len] = 0;
  3586. buf3_len = total_len - j;
  3587. strlncpy(buf3, sizeof(buf1), total+j, buf3_len);
  3588. buf3[buf3_len] = 0;
  3589. assert(num_messages == 0);
  3590. messages[0].headers_complete_cb_called = FALSE;
  3591. read = parse(buf1, buf1_len);
  3592. if (!messages[0].headers_complete_cb_called && parser.nread != read) {
  3593. print_error(buf1, read);
  3594. goto error;
  3595. }
  3596. if (parser.upgrade) goto test;
  3597. if (read != buf1_len) {
  3598. print_error(buf1, read);
  3599. goto error;
  3600. }
  3601. read += parse(buf2, buf2_len);
  3602. if (parser.upgrade) goto test;
  3603. if (read != buf1_len + buf2_len) {
  3604. print_error(buf2, read);
  3605. goto error;
  3606. }
  3607. read += parse(buf3, buf3_len);
  3608. if (parser.upgrade) goto test;
  3609. if (read != buf1_len + buf2_len + buf3_len) {
  3610. print_error(buf3, read);
  3611. goto error;
  3612. }
  3613. parse(NULL, 0);
  3614. test:
  3615. if (parser.upgrade) {
  3616. upgrade_message_fix(total, read, 3, r1, r2, r3);
  3617. }
  3618. if (message_count != num_messages) {
  3619. fprintf(stderr, "\n\nParser didn't see %d messages only %d\n",
  3620. message_count, num_messages);
  3621. goto error;
  3622. }
  3623. if (!message_eq(0, 0, r1)) {
  3624. fprintf(stderr, "\n\nError matching messages[0] in test_scan.\n");
  3625. goto error;
  3626. }
  3627. if (message_count > 1 && !message_eq(1, 0, r2)) {
  3628. fprintf(stderr, "\n\nError matching messages[1] in test_scan.\n");
  3629. goto error;
  3630. }
  3631. if (message_count > 2 && !message_eq(2, 0, r3)) {
  3632. fprintf(stderr, "\n\nError matching messages[2] in test_scan.\n");
  3633. goto error;
  3634. }
  3635. }
  3636. }
  3637. }
  3638. puts("\b\b\b\b100%");
  3639. return;
  3640. error:
  3641. fprintf(stderr, "i=%d j=%d\n", i, j);
  3642. fprintf(stderr, "buf1 (%u) %s\n\n", (unsigned int)buf1_len, buf1);
  3643. fprintf(stderr, "buf2 (%u) %s\n\n", (unsigned int)buf2_len , buf2);
  3644. fprintf(stderr, "buf3 (%u) %s\n", (unsigned int)buf3_len, buf3);
  3645. abort();
  3646. }
  3647. // user required to free the result
  3648. // string terminated by \0
  3649. char *
  3650. create_large_chunked_message (int body_size_in_kb, const char* headers)
  3651. {
  3652. int i;
  3653. size_t wrote = 0;
  3654. size_t headers_len = strlen(headers);
  3655. size_t bufsize = headers_len + (5+1024+2)*body_size_in_kb + 6;
  3656. char * buf = malloc(bufsize);
  3657. memcpy(buf, headers, headers_len);
  3658. wrote += headers_len;
  3659. for (i = 0; i < body_size_in_kb; i++) {
  3660. // write 1kb chunk into the body.
  3661. memcpy(buf + wrote, "400\r\n", 5);
  3662. wrote += 5;
  3663. memset(buf + wrote, 'C', 1024);
  3664. wrote += 1024;
  3665. strcpy(buf + wrote, "\r\n");
  3666. wrote += 2;
  3667. }
  3668. memcpy(buf + wrote, "0\r\n\r\n", 6);
  3669. wrote += 6;
  3670. assert(wrote == bufsize);
  3671. return buf;
  3672. }
  3673. /* Verify that we can pause parsing at any of the bytes in the
  3674. * message and still get the result that we're expecting. */
  3675. void
  3676. test_message_pause (const struct message *msg)
  3677. {
  3678. char *buf = (char*) msg->raw;
  3679. size_t buflen = strlen(msg->raw);
  3680. size_t nread;
  3681. parser_init(msg->type);
  3682. do {
  3683. nread = parse_pause(buf, buflen);
  3684. // We can only set the upgrade buffer once we've gotten our message
  3685. // completion callback.
  3686. if (messages[0].message_complete_cb_called &&
  3687. msg->upgrade &&
  3688. parser.upgrade) {
  3689. messages[0].upgrade = buf + nread;
  3690. goto test;
  3691. }
  3692. if (nread < buflen) {
  3693. // Not much do to if we failed a strict-mode check
  3694. if (HTTP_PARSER_ERRNO(&parser) == HPE_STRICT) {
  3695. return;
  3696. }
  3697. assert (HTTP_PARSER_ERRNO(&parser) == HPE_PAUSED);
  3698. }
  3699. buf += nread;
  3700. buflen -= nread;
  3701. http_parser_pause(&parser, 0);
  3702. } while (buflen > 0);
  3703. nread = parse_pause(NULL, 0);
  3704. assert (nread == 0);
  3705. test:
  3706. if (num_messages != 1) {
  3707. printf("\n*** num_messages != 1 after testing '%s' ***\n\n", msg->name);
  3708. abort();
  3709. }
  3710. if(!message_eq(0, 0, msg)) abort();
  3711. }
  3712. /* Verify that body and next message won't be parsed in responses to CONNECT */
  3713. void
  3714. test_message_connect (const struct message *msg)
  3715. {
  3716. char *buf = (char*) msg->raw;
  3717. size_t buflen = strlen(msg->raw);
  3718. parser_init(msg->type);
  3719. parse_connect(buf, buflen);
  3720. if (num_messages != 1) {
  3721. printf("\n*** num_messages != 1 after testing '%s' ***\n\n", msg->name);
  3722. abort();
  3723. }
  3724. if(!message_eq(0, 1, msg)) abort();
  3725. }
  3726. int
  3727. main (void)
  3728. {
  3729. unsigned i, j, k;
  3730. unsigned long version;
  3731. unsigned major;
  3732. unsigned minor;
  3733. unsigned patch;
  3734. version = http_parser_version();
  3735. major = (version >> 16) & 255;
  3736. minor = (version >> 8) & 255;
  3737. patch = version & 255;
  3738. printf("http_parser v%u.%u.%u (0x%06lx)\n", major, minor, patch, version);
  3739. printf("sizeof(http_parser) = %u\n", (unsigned int)sizeof(http_parser));
  3740. //// API
  3741. test_preserve_data();
  3742. test_parse_url();
  3743. test_method_str();
  3744. test_status_str();
  3745. //// NREAD
  3746. test_header_nread_value();
  3747. //// OVERFLOW CONDITIONS
  3748. test_no_overflow_parse_url();
  3749. test_header_overflow_error(HTTP_REQUEST);
  3750. test_no_overflow_long_body(HTTP_REQUEST, 1000);
  3751. test_no_overflow_long_body(HTTP_REQUEST, 100000);
  3752. test_header_overflow_error(HTTP_RESPONSE);
  3753. test_no_overflow_long_body(HTTP_RESPONSE, 1000);
  3754. test_no_overflow_long_body(HTTP_RESPONSE, 100000);
  3755. test_header_content_length_overflow_error();
  3756. test_chunk_content_length_overflow_error();
  3757. //// HEADER FIELD CONDITIONS
  3758. test_double_content_length_error(HTTP_REQUEST);
  3759. test_chunked_content_length_error(HTTP_REQUEST);
  3760. test_header_cr_no_lf_error(HTTP_REQUEST);
  3761. test_invalid_header_field_token_error(HTTP_REQUEST);
  3762. test_invalid_header_field_content_error(HTTP_REQUEST);
  3763. test_double_content_length_error(HTTP_RESPONSE);
  3764. test_chunked_content_length_error(HTTP_RESPONSE);
  3765. test_header_cr_no_lf_error(HTTP_RESPONSE);
  3766. test_invalid_header_field_token_error(HTTP_RESPONSE);
  3767. test_invalid_header_field_content_error(HTTP_RESPONSE);
  3768. test_simple_type(
  3769. "POST / HTTP/1.1\r\n"
  3770. "Content-Length:\r\n" // empty
  3771. "\r\n",
  3772. HPE_INVALID_CONTENT_LENGTH,
  3773. HTTP_REQUEST);
  3774. test_simple_type(
  3775. "POST / HTTP/1.1\r\n"
  3776. "Content-Length: 42 \r\n" // Note the surrounding whitespace.
  3777. "\r\n",
  3778. HPE_OK,
  3779. HTTP_REQUEST);
  3780. test_simple_type(
  3781. "POST / HTTP/1.1\r\n"
  3782. "Content-Length: 4 2\r\n"
  3783. "\r\n",
  3784. HPE_INVALID_CONTENT_LENGTH,
  3785. HTTP_REQUEST);
  3786. test_simple_type(
  3787. "POST / HTTP/1.1\r\n"
  3788. "Content-Length: 13 37\r\n"
  3789. "\r\n",
  3790. HPE_INVALID_CONTENT_LENGTH,
  3791. HTTP_REQUEST);
  3792. test_simple_type(
  3793. "POST / HTTP/1.1\r\n"
  3794. "Content-Length: 42\r\n"
  3795. " Hello world!\r\n",
  3796. HPE_INVALID_CONTENT_LENGTH,
  3797. HTTP_REQUEST);
  3798. test_simple_type(
  3799. "POST / HTTP/1.1\r\n"
  3800. "Content-Length: 42\r\n"
  3801. " \r\n",
  3802. HPE_OK,
  3803. HTTP_REQUEST);
  3804. //// RESPONSES
  3805. test_simple_type("HTP/1.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
  3806. test_simple_type("HTTP/01.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
  3807. test_simple_type("HTTP/11.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
  3808. test_simple_type("HTTP/1.01 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
  3809. test_simple_type("HTTP/1.1\t200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
  3810. test_simple_type("\rHTTP/1.1\t200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
  3811. for (i = 0; i < ARRAY_SIZE(responses); i++) {
  3812. test_message(&responses[i]);
  3813. }
  3814. for (i = 0; i < ARRAY_SIZE(responses); i++) {
  3815. test_message_pause(&responses[i]);
  3816. }
  3817. for (i = 0; i < ARRAY_SIZE(responses); i++) {
  3818. test_message_connect(&responses[i]);
  3819. }
  3820. for (i = 0; i < ARRAY_SIZE(responses); i++) {
  3821. if (!responses[i].should_keep_alive) continue;
  3822. for (j = 0; j < ARRAY_SIZE(responses); j++) {
  3823. if (!responses[j].should_keep_alive) continue;
  3824. for (k = 0; k < ARRAY_SIZE(responses); k++) {
  3825. test_multiple3(&responses[i], &responses[j], &responses[k]);
  3826. }
  3827. }
  3828. }
  3829. test_message_count_body(&responses[NO_HEADERS_NO_BODY_404]);
  3830. test_message_count_body(&responses[TRAILING_SPACE_ON_CHUNKED_BODY]);
  3831. // test very large chunked response
  3832. {
  3833. char * msg = create_large_chunked_message(31337,
  3834. "HTTP/1.0 200 OK\r\n"
  3835. "Transfer-Encoding: chunked\r\n"
  3836. "Content-Type: text/plain\r\n"
  3837. "\r\n");
  3838. struct message large_chunked =
  3839. {.name= "large chunked"
  3840. ,.type= HTTP_RESPONSE
  3841. ,.raw= msg
  3842. ,.should_keep_alive= FALSE
  3843. ,.message_complete_on_eof= FALSE
  3844. ,.http_major= 1
  3845. ,.http_minor= 0
  3846. ,.status_code= 200
  3847. ,.response_status= "OK"
  3848. ,.num_headers= 2
  3849. ,.headers=
  3850. { { "Transfer-Encoding", "chunked" }
  3851. , { "Content-Type", "text/plain" }
  3852. }
  3853. ,.body_size= 31337*1024
  3854. ,.num_chunks_complete= 31338
  3855. };
  3856. for (i = 0; i < MAX_CHUNKS; i++) {
  3857. large_chunked.chunk_lengths[i] = 1024;
  3858. }
  3859. test_message_count_body(&large_chunked);
  3860. free(msg);
  3861. }
  3862. printf("response scan 1/2 ");
  3863. test_scan( &responses[TRAILING_SPACE_ON_CHUNKED_BODY]
  3864. , &responses[NO_BODY_HTTP10_KA_204]
  3865. , &responses[NO_REASON_PHRASE]
  3866. );
  3867. printf("response scan 2/2 ");
  3868. test_scan( &responses[BONJOUR_MADAME_FR]
  3869. , &responses[UNDERSTORE_HEADER_KEY]
  3870. , &responses[NO_CARRIAGE_RET]
  3871. );
  3872. puts("responses okay");
  3873. /// REQUESTS
  3874. test_simple("GET / IHTTP/1.0\r\n\r\n", HPE_INVALID_CONSTANT);
  3875. test_simple("GET / ICE/1.0\r\n\r\n", HPE_INVALID_CONSTANT);
  3876. test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION);
  3877. test_simple("GET / HTTP/01.1\r\n\r\n", HPE_INVALID_VERSION);
  3878. test_simple("GET / HTTP/11.1\r\n\r\n", HPE_INVALID_VERSION);
  3879. test_simple("GET / HTTP/1.01\r\n\r\n", HPE_INVALID_VERSION);
  3880. test_simple("GET / HTTP/1.0\r\nHello: w\1rld\r\n\r\n", HPE_INVALID_HEADER_TOKEN);
  3881. test_simple("GET / HTTP/1.0\r\nHello: woooo\2rld\r\n\r\n", HPE_INVALID_HEADER_TOKEN);
  3882. // Extended characters - see nodejs/test/parallel/test-http-headers-obstext.js
  3883. test_simple("GET / HTTP/1.1\r\n"
  3884. "Test: Düsseldorf\r\n",
  3885. HPE_OK);
  3886. // Well-formed but incomplete
  3887. test_simple("GET / HTTP/1.1\r\n"
  3888. "Content-Type: text/plain\r\n"
  3889. "Content-Length: 6\r\n"
  3890. "\r\n"
  3891. "fooba",
  3892. HPE_OK);
  3893. static const char *all_methods[] = {
  3894. "DELETE",
  3895. "GET",
  3896. "HEAD",
  3897. "POST",
  3898. "PUT",
  3899. //"CONNECT", //CONNECT can't be tested like other methods, it's a tunnel
  3900. "OPTIONS",
  3901. "TRACE",
  3902. "COPY",
  3903. "LOCK",
  3904. "MKCOL",
  3905. "MOVE",
  3906. "PROPFIND",
  3907. "PROPPATCH",
  3908. "SEARCH",
  3909. "UNLOCK",
  3910. "BIND",
  3911. "REBIND",
  3912. "UNBIND",
  3913. "ACL",
  3914. "REPORT",
  3915. "MKACTIVITY",
  3916. "CHECKOUT",
  3917. "MERGE",
  3918. "M-SEARCH",
  3919. "NOTIFY",
  3920. "SUBSCRIBE",
  3921. "UNSUBSCRIBE",
  3922. "PATCH",
  3923. "PURGE",
  3924. "MKCALENDAR",
  3925. "LINK",
  3926. "UNLINK",
  3927. 0 };
  3928. const char **this_method;
  3929. for (this_method = all_methods; *this_method; this_method++) {
  3930. char buf[200];
  3931. sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method);
  3932. test_simple(buf, HPE_OK);
  3933. }
  3934. static const char *bad_methods[] = {
  3935. "ASDF",
  3936. "C******",
  3937. "COLA",
  3938. "GEM",
  3939. "GETA",
  3940. "M****",
  3941. "MKCOLA",
  3942. "PROPPATCHA",
  3943. "PUN",
  3944. "PX",
  3945. "SA",
  3946. "hello world",
  3947. 0 };
  3948. for (this_method = bad_methods; *this_method; this_method++) {
  3949. char buf[200];
  3950. sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method);
  3951. test_simple(buf, HPE_INVALID_METHOD);
  3952. }
  3953. // illegal header field name line folding
  3954. test_simple("GET / HTTP/1.1\r\n"
  3955. "name\r\n"
  3956. " : value\r\n"
  3957. "\r\n",
  3958. HPE_INVALID_HEADER_TOKEN);
  3959. const char *dumbluck2 =
  3960. "GET / HTTP/1.1\r\n"
  3961. "X-SSL-Nonsense: -----BEGIN CERTIFICATE-----\r\n"
  3962. "\tMIIFbTCCBFWgAwIBAgICH4cwDQYJKoZIhvcNAQEFBQAwcDELMAkGA1UEBhMCVUsx\r\n"
  3963. "\tETAPBgNVBAoTCGVTY2llbmNlMRIwEAYDVQQLEwlBdXRob3JpdHkxCzAJBgNVBAMT\r\n"
  3964. "\tAkNBMS0wKwYJKoZIhvcNAQkBFh5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMu\r\n"
  3965. "\tdWswHhcNMDYwNzI3MTQxMzI4WhcNMDcwNzI3MTQxMzI4WjBbMQswCQYDVQQGEwJV\r\n"
  3966. "\tSzERMA8GA1UEChMIZVNjaWVuY2UxEzARBgNVBAsTCk1hbmNoZXN0ZXIxCzAJBgNV\r\n"
  3967. "\tBAcTmrsogriqMWLAk1DMRcwFQYDVQQDEw5taWNoYWVsIHBhcmQYJKoZIhvcNAQEB\r\n"
  3968. "\tBQADggEPADCCAQoCggEBANPEQBgl1IaKdSS1TbhF3hEXSl72G9J+WC/1R64fAcEF\r\n"
  3969. "\tW51rEyFYiIeZGx/BVzwXbeBoNUK41OK65sxGuflMo5gLflbwJtHBRIEKAfVVp3YR\r\n"
  3970. "\tgW7cMA/s/XKgL1GEC7rQw8lIZT8RApukCGqOVHSi/F1SiFlPDxuDfmdiNzL31+sL\r\n"
  3971. "\t0iwHDdNkGjy5pyBSB8Y79dsSJtCW/iaLB0/n8Sj7HgvvZJ7x0fr+RQjYOUUfrePP\r\n"
  3972. "\tu2MSpFyf+9BbC/aXgaZuiCvSR+8Snv3xApQY+fULK/xY8h8Ua51iXoQ5jrgu2SqR\r\n"
  3973. "\twgA7BUi3G8LFzMBl8FRCDYGUDy7M6QaHXx1ZWIPWNKsCAwEAAaOCAiQwggIgMAwG\r\n"
  3974. "\tA1UdEwEB/wQCMAAwEQYJYIZIAYb4QgHTTPAQDAgWgMA4GA1UdDwEB/wQEAwID6DAs\r\n"
  3975. "\tBglghkgBhvhCAQ0EHxYdVUsgZS1TY2llbmNlIFVzZXIgQ2VydGlmaWNhdGUwHQYD\r\n"
  3976. "\tVR0OBBYEFDTt/sf9PeMaZDHkUIldrDYMNTBZMIGaBgNVHSMEgZIwgY+AFAI4qxGj\r\n"
  3977. "\tloCLDdMVKwiljjDastqooXSkcjBwMQswCQYDVQQGEwJVSzERMA8GA1UEChMIZVNj\r\n"
  3978. "\taWVuY2UxEjAQBgNVBAsTCUF1dGhvcml0eTELMAkGA1UEAxMCQ0ExLTArBgkqhkiG\r\n"
  3979. "\t9w0BCQEWHmNhLW9wZXJhdG9yQGdyaWQtc3VwcG9ydC5hYy51a4IBADApBgNVHRIE\r\n"
  3980. "\tIjAggR5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMudWswGQYDVR0gBBIwEDAO\r\n"
  3981. "\tBgwrBgEEAdkvAQEBAQYwPQYJYIZIAYb4QgEEBDAWLmh0dHA6Ly9jYS5ncmlkLXN1\r\n"
  3982. "\tcHBvcnQuYWMudmT4sopwqlBWsvcHViL2NybC9jYWNybC5jcmwwPQYJYIZIAYb4QgEDBDAWLmh0\r\n"
  3983. "\tdHA6Ly9jYS5ncmlkLXN1cHBvcnQuYWMudWsvcHViL2NybC9jYWNybC5jcmwwPwYD\r\n"
  3984. "\tVR0fBDgwNjA0oDKgMIYuaHR0cDovL2NhLmdyaWQt5hYy51ay9wdWIv\r\n"
  3985. "\tY3JsL2NhY3JsLmNybDANBgkqhkiG9w0BAQUFAAOCAQEAS/U4iiooBENGW/Hwmmd3\r\n"
  3986. "\tXCy6Zrt08YjKCzGNjorT98g8uGsqYjSxv/hmi0qlnlHs+k/3Iobc3LjS5AMYr5L8\r\n"
  3987. "\tUO7OSkgFFlLHQyC9JzPfmLCAugvzEbyv4Olnsr8hbxF1MbKZoQxUZtMVu29wjfXk\r\n"
  3988. "\thTeApBv7eaKCWpSp7MCbvgzm74izKhu3vlDk9w6qVrxePfGgpKPqfHiOoGhFnbTK\r\n"
  3989. "\twTC6o2xq5y0qZ03JonF7OJspEd3I5zKY3E+ov7/ZhW6DqT8UFvsAdjvQbXyhV8Eu\r\n"
  3990. "\tYhixw1aKEPzNjNowuIseVogKOLXxWI5vAi5HgXdS0/ES5gDGsABo4fqovUKlgop3\r\n"
  3991. "\tRA==\r\n"
  3992. "\t-----END CERTIFICATE-----\r\n"
  3993. "\r\n";
  3994. test_simple(dumbluck2, HPE_OK);
  3995. const char *corrupted_connection =
  3996. "GET / HTTP/1.1\r\n"
  3997. "Host: www.example.com\r\n"
  3998. "Connection\r\033\065\325eep-Alive\r\n"
  3999. "Accept-Encoding: gzip\r\n"
  4000. "\r\n";
  4001. test_simple(corrupted_connection, HPE_INVALID_HEADER_TOKEN);
  4002. const char *corrupted_header_name =
  4003. "GET / HTTP/1.1\r\n"
  4004. "Host: www.example.com\r\n"
  4005. "X-Some-Header\r\033\065\325eep-Alive\r\n"
  4006. "Accept-Encoding: gzip\r\n"
  4007. "\r\n";
  4008. test_simple(corrupted_header_name, HPE_INVALID_HEADER_TOKEN);
  4009. #if 0
  4010. // NOTE(Wed Nov 18 11:57:27 CET 2009) this seems okay. we just read body
  4011. // until EOF.
  4012. //
  4013. // no content-length
  4014. // error if there is a body without content length
  4015. const char *bad_get_no_headers_no_body = "GET /bad_get_no_headers_no_body/world HTTP/1.1\r\n"
  4016. "Accept: */*\r\n"
  4017. "\r\n"
  4018. "HELLO";
  4019. test_simple(bad_get_no_headers_no_body, 0);
  4020. #endif
  4021. /* TODO sending junk and large headers gets rejected */
  4022. /* check to make sure our predefined requests are okay */
  4023. for (i = 0; i < ARRAY_SIZE(requests); i++) {
  4024. test_message(&requests[i]);
  4025. }
  4026. for (i = 0; i < ARRAY_SIZE(requests); i++) {
  4027. test_message_pause(&requests[i]);
  4028. }
  4029. for (i = 0; i < ARRAY_SIZE(requests); i++) {
  4030. if (!requests[i].should_keep_alive) continue;
  4031. for (j = 0; j < ARRAY_SIZE(requests); j++) {
  4032. if (!requests[j].should_keep_alive) continue;
  4033. for (k = 0; k < ARRAY_SIZE(requests); k++) {
  4034. test_multiple3(&requests[i], &requests[j], &requests[k]);
  4035. }
  4036. }
  4037. }
  4038. printf("request scan 1/4 ");
  4039. test_scan( &requests[GET_NO_HEADERS_NO_BODY]
  4040. , &requests[GET_ONE_HEADER_NO_BODY]
  4041. , &requests[GET_NO_HEADERS_NO_BODY]
  4042. );
  4043. printf("request scan 2/4 ");
  4044. test_scan( &requests[POST_CHUNKED_ALL_YOUR_BASE]
  4045. , &requests[POST_IDENTITY_BODY_WORLD]
  4046. , &requests[GET_FUNKY_CONTENT_LENGTH]
  4047. );
  4048. printf("request scan 3/4 ");
  4049. test_scan( &requests[TWO_CHUNKS_MULT_ZERO_END]
  4050. , &requests[CHUNKED_W_TRAILING_HEADERS]
  4051. , &requests[CHUNKED_W_NONSENSE_AFTER_LENGTH]
  4052. );
  4053. printf("request scan 4/4 ");
  4054. test_scan( &requests[QUERY_URL_WITH_QUESTION_MARK_GET]
  4055. , &requests[PREFIX_NEWLINE_GET ]
  4056. , &requests[CONNECT_REQUEST]
  4057. );
  4058. puts("requests okay");
  4059. return 0;
  4060. }