3. 响应对象及Cookie设置

龶龲龮龫龧龦龥龡龝龚龖龮RFC2616齿齼齺RFC齿齼齷齶齵齲齮齬齩齧齥齺齢齿齼齡齝龖http齓齑齺齍齉齅齄齀鼾龖鼽鼹http鼵齧鼱鼯齺鼫鼧鼥鼡鼟鼜鼚鼘鼕龧鼕鼓鼑鼎鼌鼋齧鼊鼆龮HTTP黼龧黸黵黱齉黮黪黧黣黟點黚齺黙黕黒黏黎齺黵黌黋黊黈黆黅黁麿齧齬齩黸麻麷麳麲麰麮麫齺麨麤麡麟齧齶麞麛麙麿齧鼊麖麔麑麏麍黼麊鼾麉麆麂鹿齧鹽鹹麲鹵黣鹲鹱鹯鹬鹯鹪黸鹨鹦麳齺鹤鹠鹵黣麳鹞鹨黸齺黚

Drupal8鼱鼯龖symfony鹁鸽齧http-foundation鸵鸲齺齍齉齡齝龖鸱鸭鸩麤齺齿鸲鸧鸤鼧\vendor\symfony\http-foundation齺鸝鸛鸚鸖鸓鸱鸭鸩麤黈

Response黈鸐鼯鸱鸭鸩麤齺鼯黙鸏龲龧鸎鸱鸭齺鸌齶鼯齧鸊麳齧鸱鸭鸩麤

鼘鸈鸇鸓鼯黙鸄鸃鸀齧齺鷼鷻鷷鷶鷲鷱Response黈

BinaryFileResponse黈齿鸲鸱鸭

JsonResponse黈json鸱鸭

RedirectResponse黈鷣齡鷢鸱鸭

StreamedResponse黈鷝鷜鷚鸱鸭

鼘鼓鸇鸓鸱鸭鼹鸩鷗黅齧Response鷓鷒龖鷏鷌鷈鷇鷆齺龫齍鷄龶鷀鼾Response黈

Response齧鼫鼯齶鶿鶾鸱鸭鶽齉齺鶼http鸱鸭鼵齧鶺龲黵龫齍鶹鶵鶳鶯cookie黚齺鶩鶦齧鶣鶡齷齶鶟鶞鶜鸩麤鶘鶗鼧鸱鸭鸩麤齺鸱鸭鸩麤齧鶓鶏鶌鶋鶊鶇鶅鼧鶁鵿鵽鵺鵹鹨龖鸱鸭齺鵵鵴龶鵱鼯$response->send();鵠鵞鵝鼚齺鵜鶩鶦鵘鷒鵖鵕鵒鵐鵍鵊齶鵉鵈麏龖齢鸩麤齺麲鵆鵱鼯鵄鵀鵽鴼齺鴸鴷齧鵆鴴齶Response齧麫鴰鴮鴬鴩鵄鵀鵽鴨鴤鵈麏龖鴣鹞齺鵉鴮鶟鴸鴷黣黟鴠鴟鴞鴛麖鸵鴘鴗麙鴕鴓鴑鴍

Symfony\Component\HttpFoundation\Response::create($content = '', $status = 200, $headers = array());鼚鼘鴨鴤鴀鳾龧鸓鸱鸭鸩麤齺

$content鼧鳽鳺鳶黣黟鷈鳳鳱鵹__toString()鳩鳦齧鸩麤
$status鼧鳢鳡鳟
$headers鼧http鸱鸭鼵龦齺鶳鶯齧HTTP鼵鵜鵱鼯send鳩鳦鹽鳞鵐鳜鳙鷆齧鵠鵞

鵜Response黣龦鸱鸭鶽齉齶鴨鴤鼯龧鸓鳕鳒鶾鶿齧齺HTTP鸱鸭鼵鼱鼯ResponseHeaderBag鸩麤鷓鷒鶺龲齺cookie鼯Cookie鸩麤鶺龲鳐鳏鶾鵜ResponseHeaderBag齧cookies鳕鳒麖鸵齍齉齺鳙鷆齧鵠鵞鳎鼫鵜Response鸩麤齍齉鳊鶏

鶳鶯龧鸓cookie:

$response->headers->setCookie(new Cookie($name,$value, $expire, $path, $domain, $secure, $httpOnly));
鲾鵒$expire鼚鼘齶鴬鴩鹽鲼齧鳽鳺鳶鲻鹽鲼鲺鲻DateTime鸩麤

Response鳱鵹__toString()鳩鳦齺鲶鲵鲴鼚鼘鴨鴤echo $response鲰鼕龧鼕鴣鹞黣黟鲬HTTP鼵

鸱鸭鸩麤鸩鲫鶾鼵齧鵄鵀黈

$response->setCache(array $options);鲪麖$options齶龧鸓鲫鶾鲦鲢麖鸵齺鲠鲜鼧鲫鶾鲦鲢黵鸝鸛鲚鲖鲔龫鲑鲫鶾鲦鲢黈'etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public'黚齺鲠鲋鼧鸩鸭齧鲋鲉

鲵黋Response鲇鲆龖麷鲃齧鱿鼯鳩鳦齺鶞鲪鼕鼹齡齝

图解HTTP

本书共71小节:

评论 (写第一个评论)