Skip to content

Commit 1970133

Browse files
authored
Merge pull request #7280 from kenjis/docs-improve-content_negotiation.rst
docs: fix message.rst and improve content_negotiation.rst
2 parents 3ab4816 + 53b4e7f commit 1970133

2 files changed

Lines changed: 37 additions & 33 deletions

File tree

user_guide_src/source/incoming/content_negotiation.rst

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
1-
*******************
1+
###################
22
Content Negotiation
3-
*******************
3+
###################
4+
5+
.. contents::
6+
:local:
7+
:depth: 2
8+
9+
****************************
10+
What is Content Negotiation?
11+
****************************
412

513
Content negotiation is a way to determine what type of content to return to the client based on what the client
614
can handle, and what the server can handle. This can be used to determine whether the client is wanting HTML or JSON
7-
returned, whether the image should be returned as a jpg or png, what type of compression is supported and more. This
15+
returned, whether the image should be returned as a JPEG or PNG, what type of compression is supported and more. This
816
is done by analyzing four different headers which can each support multiple value options, each with their own priority.
17+
918
Trying to match this up manually can be pretty challenging. CodeIgniter provides the ``Negotiator`` class that
1019
can handle this for you.
1120

12-
=================
21+
At it's heart Content Negotiation is simply a part of the HTTP specification that allows a single
22+
resource to serve more than one type of content, allowing the clients to request the type of
23+
data that works best for them.
24+
25+
A classic example of this is a browser that cannot display PNG files can request only GIF or
26+
JPEG images. When the server receives the request, it looks at the available file types the client
27+
is requesting and selects the best match from the image formats that it supports, in this case
28+
likely choosing a JPEG image to return.
29+
30+
This same negotiation can happen with four types of data:
31+
32+
* **Media/Document Type** - this could be image format, or HTML vs. XML or JSON.
33+
* **Character Set** - The character set the returned document should be set in. Typically is UTF-8.
34+
* **Document Encoding** - Typically the type of compression used on the results.
35+
* **Document Language** - For sites that support multiple languages, this helps determine which to return.
36+
37+
*****************
1338
Loading the Class
14-
=================
39+
*****************
1540

1641
You can load an instance of the class manually through the Service class:
1742

@@ -28,9 +53,9 @@ method:
2853
When accessed this way, the first parameter is the type of content you're trying to find a match for, while the
2954
second is an array of supported values.
3055

31-
===========
56+
***********
3257
Negotiating
33-
===========
58+
***********
3459

3560
In this section, we will discuss the 4 types of content that can be negotiated and show how that would look using
3661
both of the methods described above to access the negotiator.

user_guide_src/source/incoming/message.rst

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
1-
=============
1+
#############
22
HTTP Messages
3-
=============
3+
#############
44

55
The Message class provides an interface to the portions of an HTTP message that are common to both
66
requests and responses, including the message body, protocol version, utilities for working with
77
the headers, and methods for handling content negotiation.
88

9-
This class is the parent class that both the :doc:`Request Class </incoming/request>` and the
10-
:doc:`Response Class </outgoing/response>` extend from. As such, some methods, such as the content
11-
negotiation methods, may apply only to a request or response, and not the other one, but they have
12-
been included here to keep the header methods together.
13-
14-
What is Content Negotiation?
15-
============================
16-
17-
At it's heart Content Negotiation is simply a part of the HTTP specification that allows a single
18-
resource to serve more than one type of content, allowing the clients to request the type of
19-
data that works best for them.
20-
21-
A classic example of this is a browser that cannot display PNG files can request only GIF or
22-
JPEG images. When the server receives the request, it looks at the available file types the client
23-
is requesting and selects the best match from the image formats that it supports, in this case
24-
likely choosing a JPEG image to return.
25-
26-
This same negotiation can happen with four types of data:
27-
28-
* **Media/Document Type** - this could be image format, or HTML vs. XML or JSON.
29-
* **Character Set** - The character set the returned document should be set in. Typically is UTF-8.
30-
* **Document Encoding** - Typically the type of compression used on the results.
31-
* **Document Language** - For sites that support multiple languages, this helps determine which to return.
9+
This class is the parent class that both the :doc:`Request Class <../incoming/request>` and the
10+
:doc:`Response Class <../outgoing/response>` extend from.
3211

3312
***************
3413
Class Reference
@@ -68,7 +47,7 @@ Class Reference
6847
:returns: void
6948

7049
Scans and parses the headers found in the SERVER data and stores it for later access.
71-
This is used by the :doc:`IncomingRequest Class </incoming/incomingrequest>` to make
50+
This is used by the :doc:`IncomingRequest Class <../incoming/incomingrequest>` to make
7251
the current request's headers available.
7352

7453
The headers are any SERVER data that starts with ``HTTP_``, like ``HTTP_HOST``. Each message

0 commit comments

Comments
 (0)