[web-devel] Happstack Irregular News #1

Jeremy Shaw jeremy at n-heptane.com
Sat Apr 21 03:57:31 CEST 2012


Welcome to the Happstack Irregular News #1! - 2012-04-20
========================================================

This is the first issue of the Happstack Irregular News which is
published on an irregular basis.

Today a bunch of new and updated packages where uploaded to hackage,
so it seemed like a good time to make some news!

Big thanks to Dag Odenhall, Roel van Dijk, and mekeor.melire for their
contributions. Also big thanks to Niklas Broberg, Felipe Lessa, and
Gershom Bazerman for being responsive maintainers of their respective
packages!

Details:

NEW: happstack-clientsession
----------------------------

  Dag built us a shiny new client-side session data library which
stores session data in cookies. It builds on top of the clientsession
library from Felipe Lessa and Michael Snoyman, adding the glue needed
to make it easy to use with Happstack. The happstack-clientsession
library is still new and only lightly tested. So, your feedback and
patches are appreciated. The API might still be in flux (unless we
managed to get it correct on the first try).

hsx-jmacro & happstack-jmacro
------------------------------

  Dag and I (mostly Dag) worked on the hsx-jmacro and happstack-jmacro packages.

  hsx-jmacro now includes a number of methods to embed XML generated
via HSX inside javascript generated by JMacro. See the haddock
documentation for some discussion and examples:

  http://www.happstack.com/docs/hsx-jmacro-7.0.1/doc/html/hsx-jmacro/HSX-JMacro.html

  Also check out these examples:

  http://patch-tag.com/r/mae/happstack/snapshot/current/content/pretty/hsx-jmacro/example.hs
  http://patch-tag.com/r/mae/happstack/snapshot/current/content/pretty/hsx-jmacro/example2.hs

  In the first example you will see these lines:

>    do let html :: DOMNode
>           html = <p>Generate javascript from <span class="foo" id="h">HTML & XML</span>.</p>

  which generate some simple HTML. Then in these lines, that html is
added as a child of the main div using the normal javascript
appendChild DOM function:

>          js :: JStat
>          js = [jmacro| document.getElementById('main').appendChild(`(html)`);
>                       |]

  Then we have our main handler function, which splices that
Javascript into our final HTML document:

>           handler :: ServerPart XML
>           handler = defaultTemplate "js-example" ()
>                       <%>
>                         <div id="main" />
>                         <% js %>
>                       </%>


  So, we saw both HSX being embedded into JMacro and JMacro being
embedded into HSX. All the escaping is taking care of automatically
for us. And we get to use very familiar looking HTML and Javascript
syntax.

  Dag also made some improvements to happstack-jmacro to prevent
global namespace pollution. The 'ToMessage JStat' instance now wraps
the javascript inside an anonymous function before it is called. This
helps avoid namespace collisions when you import multiple different
javascript files (that are generated from JStat).

  There is also a new 'jmResponse :: ServerMonad m => JStat -> m
Response' function which can be used to convert javascript (JStat)
into a Response. 'jmResponse' ensures that all identifiers are unique
by prefixing them with a hash computed from the rqUri.

happstack-server
----------------

  Dag and Mekeor added a few new functions to happstack-server.

    - serveFileFrom checks that the file being served is rooted in a
specific parent directory. This is useful for preventing
../../etc/passwd type attacks when a portion of the filename is
provided by the user.
    - combineSafe is a helper function which is used by serveFileFrom
and can be reused in your own code
    - serveDirectory' is exactly like serveDirectory except that it
allows you to provide the mime-type mapping function
    - neverExpires is a helper function that sets an 'Expires' header
for as far in the future as is supported by most browsers

  I also modified happstack-server so that it can be built on
platforms with out Template Haskell (such as ARM).

happstack-hsp
-------------

    - analyticsAsync - a helper function that generates the Google
Async Google Analytics Tracking Javascript code

happstack-lite
--------------

  Type type-signature for serveFile now expects the mime-type function
to be (FilePath -> IO String) instead of (FilePath -> ServerPart
String)

misc
--------------

    - a number of packages where updated to accept more recent
dependenncies on mtl, transformers, hamlet, etc
    - Dag provided a bunch of documentation fixes to ixset

Other News:
===========

HSX
------------

HSX and friends still do not build from Hackage on GHC 7.4. I
submitted patches to Niklas, which he has pulled into darcs, but not
released on Hackage. However, we then started a long discussion about
refactoring HSX so that it no longer depends on HJScript/HJavaScript,
plus a bunch of other changes to make HSX easier to install and use.
So, hopefully we will have a smaller, better HSX out soon.

If you need HSX support on GHC 7.4 right now, you will want to fetch
the source from darcs. You can find the darcs repos on patch-tag:

http://patch-tag.com/r/nibro

Unfortunately, you do not actually want the latest version from darcs,
because some of the refactoring work has already begun. In the latest
version of HSX, some of the associated types where renamed to avoid
name classes. For example XML is now XMLType, Attribute is now
AttributeType, etc. You will want to unpull the patches that make
those changes. Hopefully this will be straightened out properly on
Hackage in the next week.

happstack-authenticate
----------------------

I also upgraded happstack-authenticate to the latest version of the
authenticate library. The latest version of authenticate dropped
support for facebook, so I updated the facebook connect support to use
the fb package. Unfortunately, the fb package had not been updated to
the latest conduits -- so I submitted a patch for that and a new fb
0.8 was released today! happstack-authenticate is still an 'alpha'
package and has not been released on hackage yet. It is available from
darcs if you wish to contribute:

darcs get http://src.seereason.com/happstack-authenticate/

The major blockers to releasing on hackage are:

 1. updating it so that it can take advantage of https://
 2. finishing the cookie code so that expired sessions are deleted
 3. reviewing the code and making sure we are not doing anything
obviously wrong security wise


acme-http
---------

 In case you missed it, we released acme-http on April 1:

https://groups.google.com/group/happs/browse_thread/thread/9b078d23b59a7374/d8ed6f72a55585d6?q=acme-http#d8ed6f72a55585d6

 While the announcement and date are a bit jokey, the acme-http server
is actually the beginnings of the new Happstack HTTP backend. It is a
real server which allows us to investigate some of the low-level
performance issues in very small and isolated environment. We will
then apply what we learn to the real backend.

acme-http delivered  221,693.0 req/s, making it the fastest Haskell
web server on the planet. We expect to see a drop when we add things
like support for timeouts, etc. But, we also hope to find some ways to
increase the performance over the current baseline.

web-routes for Snap
-------------------

 The web-routes package, which provides type-safe URLs, is intended to
be usable with a wide range of Haskell web frameworks. Here is a
demonstration of how web-routes can be used with Snap without
modifying either library (though there is some boiler-plate that could
be extracted):

  https://github.com/stepcut/snap-web-routes-demo


Crash Course Updates
--------------------

In response to user feedback the acid-state section of the
documentation has received some rewritten. There is also a new section
on the basics of using Template Haskell:

http://www.happstack.com/docs/crashcourse/TemplateHaskell.html#template_haskell

happstack.com updates
---------------------

A lot of work has been going into behind the scenes improvements to
the happstack.com website. Those changes should be rolling out soon!


That's all the news that's fit to print! (and that I remember!). No
extra charge for the typos!



More information about the web-devel mailing list