Browse Source

Add more headers to cowboy_req:parse_header/2,3

Loïc Hoguin 5 years ago
parent
commit
0fc33c5300
2 changed files with 70 additions and 2 deletions
  1. 62 2
      doc/src/manual/cowboy_req.parse_header.asciidoc
  2. 8 0
      src/cowboy_req.erl

+ 62 - 2
doc/src/manual/cowboy_req.parse_header.asciidoc

@@ -80,7 +80,25 @@ Value   :: binary()                 %% case insensitive
 Quality :: 0..1000
 ----
 
-.authorization
+.access-control-request-headers
+[source,erlang]
+----
+parse_header(<<"access-control-request-headers">>, Req)
+    -> [Header]
+
+Header :: binary()   %% case insensitive
+----
+
+.access-control-request-method
+[source,erlang]
+----
+parse_header(<<"access-control-request-method">>)
+    -> Method
+
+Method :: binary()   %% case sensitive
+----
+
+.authorization and proxy-authorization
 [source,erlang]
 ----
 parse_header(<<"authorization">>, Req)
@@ -91,6 +109,16 @@ parse_header(<<"authorization">>, Req)
 
 // @todo Currently also parses connection. Do we want this? Should it be documented? Use case?
 
+.content-encoding and content-language
+[source,erlang]
+----
+parse_header(Name, Req) -> [Value]
+
+Name  :: <<"content-encoding">>
+       | <<"content-language">>
+Value :: binary()                 %% case insensitive
+----
+
 .content-length
 [source,erlang]
 ----
@@ -152,7 +180,27 @@ OpaqueTag :: binary()               %% case sensitive
 parse_header(Name, Req) -> calendar:datetime()
 ----
 
-.range
+.max-forwards
+[source,erlang]
+----
+parse_header(<<"max-forwards">>, Req) -> non_neg_integer()
+----
+
+.origin
+[source,erlang]
+----
+parse_header(<<"origin">>, Req)
+    -> [{Scheme, Host, Port} | GUID]
+
+Scheme :: <<"http">> | <<"https">>
+Host   :: binary()                   %% case insensitive
+Port   :: 0..65535
+GUID   :: reference()
+----
+
+Cowboy generates a reference in place of a GUID when the URI
+uses an unsupported uri-scheme or is not an absolute URI.
+
 [source,erlang]
 ----
 parse_header(<<"range">>, Req) -> {From, To} | Final
@@ -184,6 +232,14 @@ Name  :: <<"sec-websocket-protocol">>
 Token :: binary()                   %% case insensitive
 ----
 
+.trailer
+[source,erlang]
+----
+parse_header(Name, Req) -> [Header]
+
+Header :: binary()   %% case insensitive
+----
+
 .x-forwarded-for
 [source,erlang]
 ----
@@ -197,6 +253,10 @@ header Cowboy does not currently understand.
 
 == Changelog
 
+* *2.8*: The function now parses `access-control-request-headers`,
+         `access-control-request-method`, `content-encoding`,
+         `content-language`, `max-forwards`, `origin`,
+         `proxy-authorization` and `trailer`.
 * *2.0*: Only the parsed header value is returned, it is no longer wrapped in a tuple.
 * *1.0*: Function introduced.
 

+ 8 - 0
src/cowboy_req.erl

@@ -421,8 +421,12 @@ parse_header_fun(<<"accept">>) -> fun cow_http_hd:parse_accept/1;
 parse_header_fun(<<"accept-charset">>) -> fun cow_http_hd:parse_accept_charset/1;
 parse_header_fun(<<"accept-encoding">>) -> fun cow_http_hd:parse_accept_encoding/1;
 parse_header_fun(<<"accept-language">>) -> fun cow_http_hd:parse_accept_language/1;
+parse_header_fun(<<"access-control-request-headers">>) -> fun cow_http_hd:parse_access_control_request_headers/1;
+parse_header_fun(<<"access-control-request-method">>) -> fun cow_http_hd:parse_access_control_request_method/1;
 parse_header_fun(<<"authorization">>) -> fun cow_http_hd:parse_authorization/1;
 parse_header_fun(<<"connection">>) -> fun cow_http_hd:parse_connection/1;
+parse_header_fun(<<"content-encoding">>) -> fun cow_http_hd:parse_content_encoding/1;
+parse_header_fun(<<"content-language">>) -> fun cow_http_hd:parse_content_language/1;
 parse_header_fun(<<"content-length">>) -> fun cow_http_hd:parse_content_length/1;
 parse_header_fun(<<"content-type">>) -> fun cow_http_hd:parse_content_type/1;
 parse_header_fun(<<"cookie">>) -> fun cow_cookie:parse_cookie/1;
@@ -432,10 +436,14 @@ parse_header_fun(<<"if-modified-since">>) -> fun cow_http_hd:parse_if_modified_s
 parse_header_fun(<<"if-none-match">>) -> fun cow_http_hd:parse_if_none_match/1;
 parse_header_fun(<<"if-range">>) -> fun cow_http_hd:parse_if_range/1;
 parse_header_fun(<<"if-unmodified-since">>) -> fun cow_http_hd:parse_if_unmodified_since/1;
+parse_header_fun(<<"max-forwards">>) -> fun cow_http_hd:parse_max_forwards/1;
+parse_header_fun(<<"origin">>) -> fun cow_http_hd:parse_origin/1;
+parse_header_fun(<<"proxy-authorization">>) -> fun cow_http_hd:parse_proxy_authorization/1;
 parse_header_fun(<<"range">>) -> fun cow_http_hd:parse_range/1;
 parse_header_fun(<<"sec-websocket-extensions">>) -> fun cow_http_hd:parse_sec_websocket_extensions/1;
 parse_header_fun(<<"sec-websocket-protocol">>) -> fun cow_http_hd:parse_sec_websocket_protocol_req/1;
 parse_header_fun(<<"sec-websocket-version">>) -> fun cow_http_hd:parse_sec_websocket_version_req/1;
+parse_header_fun(<<"trailer">>) -> fun cow_http_hd:parse_trailer/1;
 parse_header_fun(<<"upgrade">>) -> fun cow_http_hd:parse_upgrade/1;
 parse_header_fun(<<"x-forwarded-for">>) -> fun cow_http_hd:parse_x_forwarded_for/1.