Webmachine 1.5: virtual host dispatching
Justin Sheehy - Justin Sheehy - November 19, 2009We recently tagged and pushed the webmachine-1.5 release, which has a number of minor bugfixes and one major new feature: resource dispatching on Host as well as on URL. There was a healthy discussion on the webmachine mailing list about this, and I think that the compromise solution that was created is a good one. The description from the changeset is quite good documentation of the new feature in my opinion.
dispatch rules can now take two different forms:
The old form: {PathMatchSpec, Module, Paramters}
The new form: {HostMatchSpec, [{PathMatchSpec, Module, Parameters}]}
The former is equivalent to the latter with HostMatchSpec={['*'],'*'}
HostMatchSpec is matched against one of (in order of preference):
X-Forwarded-For, X-Forwarded-Host, X-Forwarded-Server, Host
HostMatchSpec can have two forms:
{[HostPart], PortSpec}
or
[HostPart]
The latter is equivalent to the former with PortSpec='*'
The list of host parts is matched against the hostname extracted from
a header in much the same way that PathMatchSpec is matched against
the path.
Examples:
{[], root_resource, [x]}.
{['*'], [{[], root_resource, [x]}]}.
{{['*'],'*'}, [{[], root_resource, [x]}]}.
Will each match the root path of any host.
{["example","com"], [{[], root_resource, [x]},
{["static"], static_resource, [y]}]}.
Will dispatch the root of example.com to root_resource and
example.com/static to static_resource.
{['*',"example","com"], [{[], root_resource, [x]},
{["static"], static_resource, [y]}]}.
Will do the same as above, but also for any subdomains of
example.com.
{{[host,"local"], 8000}, [{[], res_A, [x]}]}.
{{[host,"local"], 8001}, [{[], res_B, [x]}]}.
Will dispatch requests to ?.local:8000/ to res_A and requests
to ?.local:8001/ to resB, binding the host part immediately
preceding ".local" to 'host', such that
wrq:get_path_info(host, ReqData) would return the matched string.
Some notable features of this approach include complete backward compatibility (allowing new host-specific rules to be added to old URL-only dispatch lists without rewriting the entire list) and bringing the same simple pattern-matching style of dispatch to the host portion of the problem.
You may also be interested to see a new site for Webmachine at http://webmachine.basho.com/.
That site is currently just a different structure on the documents from the bitbucket wiki, but it is likely to grow over time.
As of this release, we are doing away with private development branches by default, and expect to work against the bitbucket tip by default. Making that same change for Riak has certainly paid off, and we hope that with Webmachine it will also allow people to more easily get involved and work against the active codebase.
Enjoy!
Categories: Blogs Justin Sheehy
Comments
No comments so far, you could be the first.Add comment
Erlang on Twitter
» ingojaeckel (ingo jaeckel): Even more awesome, free Erlang resources http://t.co/blGINLJd
» DiTeam (Тимурка): @multybuq @ukhin руби хороший вариант :) можно даже без rails..попробуй erlang еще :)
» michelir5 (Micheli Gelatinous): @pharkmillups Still seeing it. I might just have to manually install it. The version of Erlang required by Riak is not current version in HB
» Angry_Lawyer (Tony Aldridge): @rvirding @saghul If Erlang kills you, does a supervisor automatically create a replacement of you?
» rvirding (Robert Virding): Softly I hope. RT @saghul: Slowly making progress… erlang is killing me.
» jsvd (João Duarte): RT @FrancescoC: Woot! RT @valdo404: Practical Erlang Programming at #QConLondon I want to go there
» saghul (Saúl Ibarra Corretgé): Slowly making progress… erlang is killing me.
» dlsspy (Dustin Sallings): @IbnFirnas heh. The erlang parts are still solid. The currently active alerting box is arm5, failed over from a pc that died one day.
» quercialwji2 (Quercia Quinn): @MikeSmooth_ABCs http://t.co/pPiIpTCx
» levicole (Levi Kennedy): @pharkmillups the homebrew version of erlang is the most recent version, and riak requires R14B I think.
Statistics
Number of aggregated posts: 10456
Number of comments: 1445
Most recent article: February 06, 2012
Latest comments
» simple smile on Scale means Skills: Very informative article. Pretty sure people would love to go to that place for shopping. Specially to those who are…
» simplesmile on 27 January 2012: Erlang Solutions embarks on an Erlang Embedded KTP: Your article will make the world better. Thanks again and good luck to you in your life. See you next time.simplesmile
» tandblekning easewhite on 08 February 2012: Erlang Express 3-day Course in San Francisco on 8 February: ncomprehensible to me now, but in general, the usefulness and significance is overwhelmingtandblekning easewhite