basho / webmachine (http://webmachine.basho.com/)
A REST-based system for building web applications.
| commit 111: | 3e6cd84ef483 |
| parent 110: | 8953dc6ec205 |
| branch: | default |
handle strange "q" value format in Accept header from FeedBurner client (thanks, Marc)
7 months ago
Changed (Δ868 bytes):
raw changeset »
src/webmachine_util.erl (19 lines added, 0 lines removed)
Up to file-list src/webmachine_util.erl:
| … | … | @@ -152,6 +152,9 @@ prioritize_media(Type,Params,Acc) -> |
152 |
152 |
QVal = case Val of |
153 |
153 |
"1" -> |
154 |
154 |
1; |
155 |
[$.|_] -> |
|
156 |
%% handle strange FeedBurner Accept |
|
157 |
list_to_float([$0|Val]); |
|
155 |
158 |
_ -> list_to_float(Val) |
156 |
159 |
end, |
157 |
160 |
{QVal, Type, Rest ++ Acc}; |
| … | … | @@ -255,6 +258,9 @@ build_conneg_list([Acc|AccRest], Result) |
255 |
258 |
case PrioStr of |
256 |
259 |
"0" -> {0.0, Choice}; |
257 |
260 |
"1" -> {1.0, Choice}; |
261 |
[$.|_] -> |
|
262 |
%% handle strange FeedBurner Accept |
|
263 |
{list_to_float([$0|PrioStr]), Choice}; |
|
258 |
264 |
_ -> {list_to_float(PrioStr), Choice} |
259 |
265 |
end; |
260 |
266 |
{Choice} -> |
| … | … | @@ -301,3 +307,16 @@ choose_media_type_test() -> |
301 |
307 |
|| I <- ShouldMatch ], |
302 |
308 |
[ ?assertEqual(none, choose_media_type([Provided], I)) |
303 |
309 |
|| I <- WantNone ]. |
310 |
||
311 |
choose_media_type_qval_test() -> |
|
312 |
Provided = ["text/html", "image/jpeg"], |
|
313 |
HtmlMatch = ["image/jpeg;q=0.5, text/html", |
|
314 |
"text/html, image/jpeg; q=0.5", |
|
315 |
"text/*; q=0.8, image/*;q=0.7", |
|
316 |
"text/*;q=.8, image/*;q=.7"], %% strange FeedBurner format |
|
317 |
JpgMatch = ["image/*;q=1, text/html;q=0.9", |
|
318 |
"image/png, image/*;q=0.3"], |
|
319 |
[ ?assertEqual("text/html", choose_media_type(Provided, I)) |
|
320 |
|| I <- HtmlMatch ], |
|
321 |
[ ?assertEqual("image/jpeg", choose_media_type(Provided, I)) |
|
322 |
|| I <- JpgMatch ]. |
