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

本书共88小节:

评论 (写第一个评论)