aboutsummaryrefslogtreecommitdiffstats
path: root/guide/internals.md
blob: 3179b9fb2921ebcf4873851cee1e36c1db8c8dbc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Internals
=========

Architecture
------------

@todo Describe.

Lowercase header names
----------------------

For consistency reasons it has been chosen to convert all header names
to lowercase binary strings. This prevents the programmer from making
case mistakes, and is possible because header names are case insensitive.

This works fine for the large majority of clients. However, some badly
implemented clients, especially ones found in corporate code or closed
source products, may not handle header names in a case insensitive manner.
This means that when Cowboy returns lowercase header names, these clients
will not find the headers they are looking for.

A simple way to solve this is to create an `onresponse` hook that will
format the header names with the expected case.

``` erlang
capitalize_hook(Status, Headers, Body, Req) ->
    Headers2 = [{cowboy_bstr:capitalize_token(N), V}
        || {N, V} <- Headers],
    {ok, Req2} = cowboy_req:reply(Status, Headers2, Body, Req),
    Req2.
```

Efficiency considerations
-------------------------

@todo Mention that you need to cleanup in terminate especially if you
used the process dictionary, started timers, started monitoring...