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

本书共63小节:

评论 (写第一个评论)