We are about to merge major incompatible changes into master.
If you have controllers or custom event handlers written in Erlang, then pay 
careful attention to the upgrade notes below.


We are going to merge Cowboy support into the master branch.
This replaces MochiWeb and Webmachine


All controllers, you will need to change your controllers.
And Cowboy is using binaries, so you need to replace strings with binaries:

 * Binary values for all query arguments, cookies, and whatnots.
 * Binary value for postbacks and notifications, instead of strings.


No, it is not stable.
We are testing, and moving to a stable 1.0
We are also using the unreleased and unstable Cowboy 2.0.

Use the stable (0.x) branch for your production sites.


If you dare, please give this a test drive and report any issues.


Marc and the rest of the team.

———————————— cut here ——————————————— 

Erlang code, Controllers, Event handlers

If you made a site using custom controllers or request handling then you need 
to adapt your Erlang code. 
Zotonic is now using Cowboy under the hood for the http handling, previously 
this was MochiWeb. 

The following changes are made:

 * Binaries for all request variables and arguments.
 * Events use binaries for strings in templates.
 * Cookies are binaries.
 * Request headers are binaries.
 * Controllers initialization callbacks are removed.
 * Controller callbacks have a single *Context* argument.
 * Custom websocket handlers now use the Cowboy callbacks, see 
 * The include file ``include/controller_webmachine_helper.hrl`` is removed 
(and not needed anymore).

Binaries for request variables

If you request an argument with ``z_context:get_q/2`` and related functions 
then you might need to adapt some code. If the you request the query argument 
using an *atom* or *binary* then the argument will be returned as a *binary*. 
If you request using a *string* then the result will be a string, this is for 
backwards compatibility. The function ``get_q_all`` will return all arguments 
as binaries.

In short:

  * ``z_context:get_q(<<"arg">>, Context)`` returns ``<<"value">>``
  * ``z_context:get_q(arg, Context)`` returns ``<<"value">>``
  * ``z_context:get_q("arg", Context)`` returns ``"value"``
  * ``z_context:get_q_all(Context)`` returns ``[ {<<"arg">>,<<"value">>}, ...]``

The binary name is the preferred way to request arguments.

Events like submit, postback and postback_notify

Strings in the ``#submit{}``, ``#postback{}``  and ``#postback_notify{}`` 
events are now binaries. This is especially the case for the message, trigger, 
target, and form fields.

For example, replace ``#submit{message="hello"}`` with ``#submit{message = 
Watch the space between ``=`` and the ``<<"...">>``, without the space you will 
get a syntax error.


Use binaries for fetching and setting cookie names and values, don't use 

Request and response headers

All request and response headers now use binary names and values, do not use 

The request and response header names are normalized to lowercase names, so 
always use ``<<"x-my-header">>`` and *never* ``<<"X-My-Header">>``.

The header values are passed as-is, and they are always binaries.


The controllers are simplified and will need some adaptations.

The following callbacks are removed:

 * `init`
 * `ping`
 All other callbacks have now a single *Context* argument, the *ReqData* 
argument has been removed. 
 There is no need anymore for the ``?WM_REQ`` and ``?WM_REPLY`` macros, and 
they have been removed.

Other controller changes changes are:

 * Content types are now binaries in `content_types_accepted` and 
 * Character sets are now binaries in `charsets_provided`
 * Methods are now binaries in `allowed_methods` and `known_methods`
 * Encodings are now binaries in `content_encodings_provided`
 * The return value of `generate_etag` must be a binary


You received this message because you are subscribed to the Google Groups 
"Zotonic developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to zotonic-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to