Skip to content

Loading…

Header/2 function in mochiweb_request_bridge.erl #2

Closed
wants to merge 1 commit into from

2 participants

@mdaguete

Hello Rusty,

I've added a header/2 function in mochiweb_request_bridge.erl to allow search for user defined headers.

Regards.

@mdaguete mdaguete Added a header/2 function to mochiweb_request_bridge.
Accepts the header name as atom or string, if atom option is used take care that al _ are converted to -
81af81a
@choptastic
The Nitrogen Web Framework for Erlang member

This should have been merged long ago, but never was. For that, I apologize. As it is now, mochiweb_request_bridge:header/2 exists as merged from the ChicagoBoss variation of SimpleBridge. I like how you do the atom to list conversion though, and I will likely incorporate that change tomorrow. For now, I will leave the pull request open, as it's getting late, and I simply don't have the time to complete the merger now.

Thanks Manuel!

@mdaguete

Don't worry .. Thank you.

@choptastic
The Nitrogen Web Framework for Erlang member

There are some abstractions on this that make this more flexible in the upcoming 2.0 release.

@choptastic choptastic closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 16, 2010
  1. @mdaguete

    Added a header/2 function to mochiweb_request_bridge.

    mdaguete committed
    Accepts the header name as atom or string, if atom option is used take care that al _ are converted to -
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 1 deletion.
  1. +9 −1 src/mochiweb_bridge_modules/mochiweb_request_bridge.erl
View
10 src/mochiweb_bridge_modules/mochiweb_request_bridge.erl
@@ -9,7 +9,7 @@
init/1,
request_method/1, path/1, uri/1,
peer_ip/1, peer_port/1,
- headers/1, cookies/1,
+ headers/1, header/2, cookies/1,
query_params/1, post_params/1, request_body/1,
socket/1, recv_from_socket/3
]).
@@ -64,6 +64,14 @@ headers({Req, _DocRoot}) ->
],
[{K, V} || {K, V} <- Headers1, V /= undefined].
+header(Header,Req) when is_atom(Header) ->
+ F = fun($_) -> $-;(X) -> X end,
+ HeaderAsString = [F(X) || X <- erlang:atom_to_list(Header)],
+ header(HeaderAsString,Req);
+header(Header,{Req, _DocRoot}) when is_list(Header) ->
+ Req:get_header_value(Header).
+
+
cookies({Req, _DocRoot}) ->
Req:parse_cookie().
Something went wrong with that request. Please try again.