Vous êtes sur la page 1sur 3

2ContentNegotiation

MostHTTPresponsesincludeanentitywhichcontainsinformationforinterpretation
byahumanuser.Naturally,itisdesirabletosupplytheuserwiththe"bestavailable"
entitycorrespondingtotherequest.Unfortunatelyforserversandcaches,notall
usershavethesamepreferencesforwhatis"best,"andnotalluseragentsareequally
capableofrenderingallentitytypes.Forthatreason,HTTPhasprovisionsforseveral
mechanismsfor"contentnegotiation"theprocessofselectingthebest
representationforagivenresponsewhentherearemultiplerepresentationsavailable.
Note: This is not called "format negotiation" because the
alternate representations may be of the same media type, but use
different capabilities of that type, be in different languages,
etc.

AnyresponsecontaininganentitybodyMAYbesubjecttonegotiation,including
errorresponses.
TherearetwokindsofcontentnegotiationwhicharepossibleinHTTP:serverdriven
andagentdrivennegotiation.Thesetwokindsofnegotiationareorthogonalandthus
maybeusedseparatelyorincombination.Onemethodofcombination,referredtoas
transparentnegotiation,occurswhenacacheusestheagentdrivennegotiation
informationprovidedbytheoriginserverinordertoprovideserverdriven
negotiationforsubsequentrequests.
12.1ServerdrivenNegotiation
Iftheselectionofthebestrepresentationforaresponseismadebyanalgorithm
locatedattheserver,itiscalledserverdrivennegotiation.Selectionisbasedonthe
availablerepresentationsoftheresponse(thedimensionsoverwhichitcanvary;e.g.
language,contentcoding,etc.)andthecontentsofparticularheaderfieldsinthe
requestmessageoronotherinformationpertainingtotherequest(suchasthe
networkaddressoftheclient).
Serverdrivennegotiationisadvantageouswhenthealgorithmforselectingfrom
amongtheavailablerepresentationsisdifficulttodescribetotheuseragent,orwhen
theserverdesirestosendits"bestguess"totheclientalongwiththefirstresponse
(hopingtoavoidtheroundtripdelayofasubsequentrequestifthe"bestguess"is
goodenoughfortheuser).Inordertoimprovetheserver'sguess,theuseragent
MAYincluderequestheaderfields(Accept,AcceptLanguage,AcceptEncoding,
etc.)whichdescribeitspreferencesforsucharesponse.
Serverdrivennegotiationhasdisadvantages:
1. It is impossible for the server to accurately determine what
might be "best" for any given user, since that would require
complete knowledge of both the capabilities of the user agent
and the intended use for the response (e.g., does the user want
to view it on screen or print it on paper?).

2. Having the user agent describe its capabilities in every


request can be both very inefficient (given that only a small
percentage of responses have multiple representations) and a
potential violation of the user's privacy.
3. It complicates the implementation of an origin server and the
algorithms for generating responses to a request.
4. It may limit a public cache's ability to use the same response
for multiple user's requests.

HTTP/1.1includesthefollowingrequestheaderfieldsforenablingserverdriven
negotiationthroughdescriptionofuseragentcapabilitiesanduserpreferences:
Accept(section14.1),AcceptCharset(section14.2),AcceptEncoding
(section14.3),AcceptLanguage(section14.4),andUserAgent(section14.43).
However,anoriginserverisnotlimitedtothesedimensionsandMAYvarythe
responsebasedonanyaspectoftherequest,includinginformationoutsidethe
requestheaderfieldsorwithinextensionheaderfieldsnotdefinedbythis
specification.
TheVaryheaderfieldcanbeusedtoexpresstheparameterstheserverusestoselect
arepresentationthatissubjecttoserverdrivennegotiation.Seesection13.6foruse
oftheVaryheaderfieldbycachesandsection14.44foruseoftheVaryheaderfield
byservers.
12.2AgentdrivenNegotiation
Withagentdrivennegotiation,selectionofthebestrepresentationforaresponseis
performedbytheuseragentafterreceivinganinitialresponsefromtheoriginserver.
Selectionisbasedonalistoftheavailablerepresentationsoftheresponseincluded
withintheheaderfieldsorentitybodyoftheinitialresponse,witheach
representationidentifiedbyitsownURI.Selectionfromamongtherepresentations
maybeperformedautomatically(iftheuseragentiscapableofdoingso)ormanually
bytheuserselectingfromagenerated(possiblyhypertext)menu.
Agentdrivennegotiationisadvantageouswhentheresponsewouldvaryover
commonlyuseddimensions(suchastype,language,orencoding),whentheorigin
serverisunabletodetermineauseragent'scapabilitiesfromexaminingtherequest,
andgenerallywhenpubliccachesareusedtodistributeserverloadandreduce
networkusage.
Agentdrivennegotiationsuffersfromthedisadvantageofneedingasecondrequest
toobtainthebestalternaterepresentation.Thissecondrequestisonlyefficientwhen
cachingisused.Inaddition,thisspecificationdoesnotdefineanymechanismfor
supportingautomaticselection,thoughitalsodoesnotpreventanysuchmechanism
frombeingdevelopedasanextensionandusedwithinHTTP/1.1.
HTTP/1.1definesthe300(MultipleChoices)and406(NotAcceptable)statuscodes
forenablingagentdrivennegotiationwhentheserverisunwillingorunableto

provideavaryingresponseusingserverdrivennegotiation.
12.3TransparentNegotiation
Transparentnegotiationisacombinationofbothserverdrivenandagentdriven
negotiation.Whenacacheissuppliedwithaformofthelistofavailable
representationsoftheresponse(asinagentdrivennegotiation)andthedimensionsof
variancearecompletelyunderstoodbythecache,thenthecachebecomescapableof
performingserverdrivennegotiationonbehalfoftheoriginserverforsubsequent
requestsonthatresource.
Transparentnegotiationhastheadvantageofdistributingthenegotiationworkthat
wouldotherwiseberequiredoftheoriginserverandalsoremovingthesecond
requestdelayofagentdrivennegotiationwhenthecacheisabletocorrectlyguess
therightresponse.
Thisspecificationdoesnotdefineanymechanismfortransparentnegotiation,though
italsodoesnotpreventanysuchmechanismfrombeingdevelopedasanextension
thatcouldbeusedwithinHTTP/1.1.

Vous aimerez peut-être aussi