0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 04:10:24 +00:00

Update the guide with range requests support

Also update the list of headers cowboy_rest might set
and tweak a small number of other items.
This commit is contained in:
Loïc Hoguin 2024-01-23 13:15:55 +01:00
parent 4ffcbfbf43
commit 427a276ef2
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
8 changed files with 1350 additions and 325 deletions

View file

@ -144,6 +144,16 @@ never be called.
Implement the `languages_provided` or `charsets_provided`
callbacks if applicable.
Does the resource accept ranged requests? If it does,
implement the `ranges_provided` callback. Resources that
only accept `bytes` units can use the callback name
`auto` and let Cowboy automatically do ranged responses.
Other callbacks should have a name prefix of `ranged_`
for clarity. For example, `ranged_bytes` or `ranged_pages`.
If the resource needs to perform additional checks before
accepting to do a ranged responses, implement the
`range_satisfiable` callback.
Is there any other header that may make the representation
of the resource vary? Implement the `variances` callback.
@ -191,10 +201,15 @@ the `options` method.
=== GET and HEAD methods
If you implement the methods GET and/or HEAD, you must
implement one `ProvideResource` callback for each
implement one `ProvideCallback` callback for each
content-type returned by the `content_types_provided`
callback.
When range requests are accepted, you must implement one
`RangeCallback` for each range unit returned by
`ranges_provided` (unless `auto` was used). This is
in addition to the `ProvideCallback` callback.
=== PUT, POST and PATCH methods
If you implement the methods PUT, POST and/or PATCH,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 74 KiB

Before After
Before After

View file

@ -2,24 +2,23 @@
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="744.09448819"
height="1052.3622047"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)"
sodipodi:docname="rest_conneg.svg"
inkscape:export-filename="/home/essen/Dropbox/Public/drawing.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
inkscape:export-ydpi="90"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<defs
id="defs4">
<linearGradient
@ -50,7 +49,7 @@
</linearGradient>
<linearGradient
id="linearGradient5233"
osb:paint="solid">
inkscape:swatch="solid">
<stop
style="stop-color:#69d2e7;stop-opacity:1;"
offset="0"
@ -64,26 +63,34 @@
borderopacity="1.0"
inkscape:pageopacity="1"
inkscape:pageshadow="2"
inkscape:zoom="1.4142136"
inkscape:cx="222.80947"
inkscape:cy="634.56615"
inkscape:zoom="0.65304847"
inkscape:cx="259.55194"
inkscape:cy="483.11881"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1402"
inkscape:window-width="1440"
inkscape:window-height="900"
inkscape:window-x="0"
inkscape:window-y="38"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:snap-global="true"
showguides="true">
showguides="true"
inkscape:showpageshadow="2"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1">
<inkscape:grid
type="xygrid"
id="grid5357"
empspacing="5"
visible="true"
visible="false"
enabled="true"
snapvisiblegridlinesonly="true" />
snapvisiblegridlinesonly="true"
originx="0"
originy="0"
spacingy="1"
spacingx="1"
units="px" />
</sodipodi:namedview>
<metadata
id="metadata7">
@ -93,7 +100,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
@ -112,7 +119,7 @@
<g
transform="translate(303.92143,-296.03137)"
id="g5650-7"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-filename="rest_conneg.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643">
<path
@ -557,149 +564,149 @@
inkscape:export-ydpi="89.926643" />
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none"
x="-58.692513"
y="114.39204"
id="text5371"
sodipodi:linespacing="125%"><tspan
id="text5371"><tspan
sodipodi:role="line"
id="tspan5373"
x="-58.692513"
y="114.39204">some text</tspan></text>
y="114.39204"
style="font-size:16px;line-height:1.25;font-family:sans-serif">some text</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="-58.692513"
y="53.112247"
id="text5371-2"
sodipodi:linespacing="125%"><tspan
id="text5371-2"><tspan
sodipodi:role="line"
id="tspan5373-6"
x="-58.692513"
y="53.112247">some text</tspan></text>
y="53.112247"
style="font-size:16px;line-height:1.25;font-family:sans-serif">some text</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="246.18575"
y="310.19913"
id="text5371-2-3"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-7"
x="246.18575"
y="310.19913">has accept-language?</tspan></text>
y="310.19913"
style="font-size:16px;line-height:1.25;font-family:sans-serif">has accept-language?</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="245.60762"
y="477.47531"
id="text5371-2-3-0"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-7-3"
x="245.60762"
y="477.47531">has accept-charset?</tspan></text>
y="477.47531"
style="font-size:16px;line-height:1.25;font-family:sans-serif">has accept-charset?</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
x="-58.692513"
y="236.95154"
id="text5371-4"
sodipodi:linespacing="125%"><tspan
id="text5371-4"><tspan
sodipodi:role="line"
id="tspan5373-9"
x="-58.692513"
y="236.95154">some text</tspan></text>
y="236.95154"
style="font-size:16px;line-height:1.25;font-family:sans-serif">some text</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
x="245.00391"
y="60.912468"
id="text5371-4-0"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
x="245.00391"
y="60.912468"
id="tspan17171">start</tspan></text>
id="tspan17171"
style="font-size:16px;line-height:1.25;font-family:sans-serif">start</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="246.11153"
y="561.14258"
id="text5371-2-9"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-8"
x="246.11153"
y="561.14258">charsets_provided</tspan></text>
y="561.14258"
style="font-size:16px;line-height:1.25;font-family:sans-serif">charsets_provided</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="246.64278"
y="646.58331"
id="text5371-2-7"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-2"
x="246.64278"
y="646.58331">variances</tspan></text>
y="646.58331"
style="font-size:16px;line-height:1.25;font-family:sans-serif">ranges_provided</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="246.13106"
y="142.80627"
id="text5371-2-95"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-80"
x="246.13106"
y="142.80627">has accept?</tspan></text>
y="142.80627"
style="font-size:16px;line-height:1.25;font-family:sans-serif">has accept?</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="245.80684"
y="226.4736"
id="text5371-2-32"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-27"
x="245.80684"
y="226.4736">content_types_provided</tspan></text>
y="226.4736"
style="font-size:16px;line-height:1.25;font-family:sans-serif">content_types_provided</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="246.05293"
y="393.80801"
id="text5371-2-74"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-18"
x="246.05293"
y="393.80801">languages_provided</tspan></text>
y="393.80801"
style="font-size:16px;line-height:1.25;font-family:sans-serif">languages_provided</tspan></text>
<rect
style="fill:#d1f2a5;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:3;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect5273-1-2"
@ -710,88 +717,88 @@
rx="15" />
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none"
x="262.26562"
y="185.95248"
id="text5371-2-391"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-63"
x="262.26562"
y="185.95248">true</tspan></text>
y="185.95248"
style="font-size:16px;line-height:1.25;font-family:sans-serif">true</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none"
x="262.26562"
y="269.61978"
id="text5371-2-954"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-808"
x="262.26562"
y="269.61978">provided*</tspan></text>
y="269.61978"
style="font-size:16px;line-height:1.25;font-family:sans-serif">provided*</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none"
x="262.26562"
y="353.28702"
id="text5371-2-4"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-11"
x="262.26562"
y="353.28702">true</tspan></text>
y="353.28702"
style="font-size:16px;line-height:1.25;font-family:sans-serif">true</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none"
x="262.26562"
y="436.95425"
id="text5371-2-92"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-4"
x="262.26562"
y="436.95425">provided*</tspan></text>
y="436.95425"
style="font-size:16px;line-height:1.25;font-family:sans-serif">provided*</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none"
x="262.26562"
y="520.62152"
id="text5371-2-739"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-0"
x="262.26562"
y="520.62152">true</tspan></text>
y="520.62152"
style="font-size:16px;line-height:1.25;font-family:sans-serif">true</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#6d8e41;fill-opacity:1;stroke:none"
x="262.26562"
y="604.28876"
id="text5371-2-8"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-3"
x="262.26562"
y="604.28876">provided*</tspan></text>
y="604.28876"
style="font-size:16px;line-height:1.25;font-family:sans-serif">provided*</tspan></text>
<g
transform="matrix(0,-1,1,0,-513.31414,353.05561)"
id="g5650-2">
@ -820,75 +827,75 @@
</g>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
x="76.761719"
y="227.88033"
id="text5371-4-6"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-9-0"
x="76.761719"
y="227.88033">false</tspan></text>
y="227.88033"
style="font-size:16px;line-height:1.25;font-family:sans-serif">false</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
x="76.761719"
y="395.20209"
id="text5371-4-2"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-9-01"
x="76.761719"
y="395.20209">false</tspan></text>
y="395.20209"
style="font-size:16px;line-height:1.25;font-family:sans-serif">false</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
x="413.26172"
y="374.19577"
id="text5371-4-3"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-9-62"
x="413.26172"
y="374.19577">not provided*</tspan></text>
y="374.19577"
style="font-size:16px;line-height:1.25;font-family:sans-serif">not provided*</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
x="76.761719"
y="562.52386"
id="text5371-4-4"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-9-2"
x="76.761719"
y="562.52386">false</tspan></text>
y="562.52386"
style="font-size:16px;line-height:1.25;font-family:sans-serif">false</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
x="-8.8034744"
y="663.24762"
id="text5371-4-5"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"
transform="matrix(0.7410941,-0.67140117,0.67140117,0.7410941,0,0)"><tspan
transform="rotate(-42.1753)"><tspan
sodipodi:role="line"
id="tspan5373-9-09"
x="-8.8034744"
y="663.24762">not provided*</tspan></text>
y="663.24762"
style="font-size:16px;line-height:1.25;font-family:sans-serif">not provided*</tspan></text>
<rect
style="fill:#effab4;fill-opacity:1;fill-rule:nonzero;stroke:#c7d28c;stroke-width:2.73499846;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect5273-7-3-1"
@ -931,18 +938,18 @@
</g>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none"
x="599.20062"
y="394.09869"
id="text5371-43"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-3"
x="599.20062"
y="394.09869">406 not acceptable</tspan></text>
y="394.09869"
style="font-size:16px;line-height:1.25;font-family:sans-serif">406 not acceptable</tspan></text>
<rect
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:2.44279909;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect5367"
@ -956,19 +963,19 @@
inkscape:export-ydpi="89.926643" />
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="-544.69421"
y="-354.17184"
id="text5371-2-3-0-7"
sodipodi:linespacing="125%"
transform="matrix(0,-1,1,0,0,0)"
transform="rotate(-90)"
inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-7-3-9"
x="-544.69421"
y="-354.17184">middlewares</tspan></text>
y="-354.17184"
style="font-size:16px;line-height:1.25;font-family:sans-serif">middlewares</tspan></text>
<g
transform="matrix(0,-1,1,0,-508.93096,565.23553)"
id="g5650-2-0-4"
@ -1093,19 +1100,48 @@
</g>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
x="509.41452"
y="-106.16136"
id="text5371-4-5-9"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"
transform="matrix(0.69480867,0.71919462,-0.71919462,0.69480867,0,0)"><tspan
transform="rotate(45.988027)"><tspan
sodipodi:role="line"
id="tspan5373-9-09-1"
x="509.41452"
y="-106.16136">not provided*</tspan></text>
y="-106.16136"
style="font-size:16px;line-height:1.25;font-family:sans-serif">not provided*</tspan></text>
<g
transform="translate(303.92156,372.14538)"
id="g5650-6-2-7"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643">
<path
inkscape:connector-curvature="0"
id="path5570-78-4-5"
d="m -57.78256,351.41962 v 52.3259"
style="opacity:0.8;fill:none;stroke:#6d8e41;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
transform="matrix(0.58787746,0,0,0.58787746,73.160466,163.35774)"
inkscape:transform-center-y="2.1823437"
d="m -222.73865,430.10821 -12.85982,-22.27386 25.71964,0 z"
inkscape:randomized="0"
inkscape:rounded="0"
inkscape:flatsided="true"
sodipodi:arg2="2.6179939"
sodipodi:arg1="1.5707963"
sodipodi:r2="7.4246211"
sodipodi:r1="14.849242"
sodipodi:cy="415.25897"
sodipodi:cx="-222.73865"
sodipodi:sides="3"
id="path5576-9-2-3"
style="opacity:0.8;fill:#6d8e41;fill-opacity:1;fill-rule:nonzero;stroke:#6d8e41;stroke-width:0;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
sodipodi:type="star" />
</g>
<rect
style="fill:#d1f2a5;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:3;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect5273-1-41-0"
@ -1119,17 +1155,42 @@
inkscape:export-ydpi="89.926643" />
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="246.15048"
y="725.27777"
y="730.10156"
id="text5371-2-7-9"
sodipodi:linespacing="125%"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-2-1"
x="246.15048"
y="725.27777">...</tspan></text>
y="730.10156"
style="font-size:16px;line-height:1.25;font-family:sans-serif">variances</tspan></text>
<rect
style="fill:#d1f2a5;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:3;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect5273-1-41-0-2"
width="210.17955"
height="35.209244"
x="141.049"
y="789.44257"
rx="15"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="246.15047"
y="808.03937"
id="text5371-2-7-9-9"
inkscape:export-filename="/home/essen/ninenines/cowboy/guide/rest_options.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-2-1-1"
x="246.15047"
y="808.03937"
style="font-size:16px;line-height:1.25;font-family:sans-serif">...</tspan></text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 55 KiB

Before After
Before After

View file

@ -95,6 +95,11 @@ callback will only be called at the end of the
"GET and HEAD methods" diagram, when all conditions
have been met.
Optionally, the `ranges_provided` also returns the
name of a callback for every range unit it accepts. This
will be called at the end of the "GET and HEAD methods"
diagram in the case of ranged requests.
The selected content-type, language and charset are
saved as meta values in the Req object. You *should*
use the appropriate representation if you set a
@ -121,11 +126,18 @@ succeed, the resource can be retrieved.
Cowboy prepares the response by first retrieving
metadata about the representation, then by calling
the `ProvideResource` callback. This is the callback
the `ProvideCallback` callback. This is the callback
you defined for each content-types you returned from
`content_types_provided`. This callback returns the body
that will be sent back to the client, or a fun if the
body must be streamed.
that will be sent back to the client.
For ranged requests, but only when the `ranges_provided`
callback was defined earlier, Cowboy will add the selected
`range` information to the Req object and call the
`range_satisfiable` callback. After confirming that the
range can be provided, Cowboy calls the `RangeResource`
callback and produces a ranged response using the
ranged data from the callback.
When the resource does not exist, Cowboy will figure out
whether the resource existed previously, and if so whether

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 168 KiB

Before After
Before After

File diff suppressed because it is too large Load diff

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 115 KiB

Before After
Before After

View file

@ -84,6 +84,8 @@ if it is undefined, moving directly to the next step. Similarly,
| multiple_choices | `false`
| options | `ok`
| previously_existed | `false`
| ranges_provided | skip
| range_satisfiable | `true`
| rate_limited | `false`
| resource_exists | `true`
| service_available | `true`
@ -97,8 +99,9 @@ As you can see, Cowboy tries to move on with the request whenever
possible by using well thought out default values.
In addition to these, there can be any number of user-defined
callbacks that are specified through `content_types_accepted/2`
and `content_types_provided/2`. They can take any name, however
callbacks that are specified through `content_types_accepted/2`,
`content_types_provided/2` or `ranges_provided/2`. They can take
any name (except `auto` for range callbacks), however
it is recommended to use a separate prefix for the callbacks of
each function. For example, `from_html` and `to_html` indicate
in the first case that we're accepting a resource given as HTML,
@ -113,9 +116,10 @@ Req object directly. The values are defined in the following table:
[cols="<,<",options="header"]
|===
| Key | Details
| media_type | The content-type negotiated for the response entity.
| language | The language negotiated for the response entity.
| charset | The charset negotiated for the response entity.
| media_type | The content-type negotiated for the response entity
| language | The language negotiated for the response entity
| charset | The charset negotiated for the response entity
| range | The range selected for the ranged response
|===
They can be used to send a proper body with the response to a
@ -129,11 +133,16 @@ of the REST code. They are listed in the following table.
[cols="<,<",options="header"]
|===
| Header name | Details
| accept-ranges | Range units accepted by the resource
| allow | HTTP methods allowed by the resource
| content-language | Language used in the response body
| content-range | Range of the content found in the response
| content-type | Media type and charset of the response body
| etag | Etag of the resource
| expires | Expiration date of the resource
| last-modified | Last modification date for the resource
| location | Relative or absolute URI to the requested resource
| retry-after | Delay or time the client should wait before accessing the resource
| vary | List of headers that may change the representation of the resource
| www-authenticate | Authentication information to access the resource
|===

View file

@ -1196,6 +1196,7 @@ if_range(Req=#{headers := #{<<"if-range">> := _, <<"range">> := _}},
if_range(Req, State) ->
range(Req, State).
%% @todo This can probably be moved to if_range directly.
range(Req, State=#state{ranges_a=[]}) ->
set_resp_body(Req, State);
range(Req, State) ->