http-accept 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/http/accept/languages.rb +2 -1
- data/lib/http/accept/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 954845d60bf94eee8063d94cd3e848d9fa551464
|
4
|
+
data.tar.gz: 7a82a3455fdd4a2dd6de9fcc973750aa3be5cd12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5746efff959b201d04f83725d00c103c71f9a5dad69b33d7ee765b8b23f68b947fb9d61aac11faa08d25ac857280fb131d7595a38d5a74dce73bcf853f58aaee
|
7
|
+
data.tar.gz: 4cd56d9c300498ad2ddaa6534fa011b955a395f5632c9162f533ddaa2f27923a8d0901dd96ded80013c75269d3862218205c7eda9a43fec8b63b280cbdee24ae
|
data/README.md
CHANGED
@@ -8,6 +8,14 @@ Current `Accept-Encoding:` and `Accept-Charset:` are not supported. This is beca
|
|
8
8
|
[![Code Climate](https://codeclimate.com/github/ioquatix/http-accept.svg)](https://codeclimate.com/github/ioquatix/http-accept)
|
9
9
|
[![Coverage Status](https://coveralls.io/repos/ioquatix/http-accept/badge.svg)](https://coveralls.io/r/ioquatix/http-accept)
|
10
10
|
|
11
|
+
## Motivation
|
12
|
+
|
13
|
+
I've been [developing some tools for building RESTful endpoints](https://github.com/ioquatix/utopia/blob/master/lib/utopia/controller/respond.rb) and part of that involved versioning. After reviewing the options, I settled on using the `Accept: application/json;version=1` method [as outlined here](http://labs.qandidate.com/blog/2014/10/16/using-the-accept-header-to-version-your-api/).
|
14
|
+
|
15
|
+
The `version=1` part of the `media-type` is a `parameter` as defined by [RFC7231 Section 3.1.1.1](https://tools.ietf.org/html/rfc7231#section-3.1.1.1). After reviewing several existing different options for parsing the `Accept:` header, I noticed a disturbing trend: `header.split(',')`. Because parameters may contain quoted strings which contain commas, this is clearly not an appropriate way to parse the header.
|
16
|
+
|
17
|
+
I am concerned about correctness, security and performance. As such, I implemented this gem to provide a simple high level interface for both parsing and correctly interpreting these headers.
|
18
|
+
|
11
19
|
## Installation
|
12
20
|
|
13
21
|
Add this line to your application's Gemfile:
|
@@ -26,7 +26,8 @@ require_relative 'sort'
|
|
26
26
|
module HTTP
|
27
27
|
module Accept
|
28
28
|
module Languages
|
29
|
-
|
29
|
+
# https://tools.ietf.org/html/rfc3066#section-2.1
|
30
|
+
LOCALE = /\*|[A-Z]{1,8}(-[A-Z0-9]{1,8})*/i
|
30
31
|
|
31
32
|
# https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9
|
32
33
|
QVALUE = /0(\.[0-9]{0,3})?|1(\.[0]{0,3})?/
|
data/lib/http/accept/version.rb
CHANGED