ostinelli / misultin

Misultin (pronounced mee-sool-téen) is an Erlang library for building fast lightweight HTTP(S) servers, which also supports websockets.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

headers normalization

tereska opened this issue · comments

I have some service that get headers from 3rd party.
Is there some automatic way of normalizing headers or I must do this on my own?
I'm talking about this fragment of code:
https://github.com/ostinelli/misultin/blob/master/src/misultin_http.erl#L579

In headers_01 example i have output like this:

HTTP/1.1 200 OK
Date: Sun, 30 Oct 2011 13:26:46 GMT
Server: misultin/0.8
Connection: Keep-Alive
Content-Length: 3
server: someserver
date: some date

ok

In headers_02 example all is OK but i need to care about proper header name formatting:

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 3
Server: someserver
Date: some date

ok

Examples code:

-module(test).
-export([headers_01/0, headers_02/0]).

headers_01() ->
    misultin:start_link([
        { port, 8080 }, 
        { loop, fun(Req) -> 
          Req:respond(200, [{'server', "someserver"}, {'date', "some date"}], <<"ok\n">>) end }
    ]).

headers_02() ->
    misultin:start_link([
        { port, 8080 }, 
        { loop, fun(Req) -> 
           Req:respond(200, [{'Server', "someserver"}, {'Date', "some date"}], <<"ok\n">>) end }
    ]).

headers in misultin are defined according to erlang:decode_packet/3 function, which clearly states the internal header representation and defines 'Server' and 'Date' atoms.

i'm not exactly clear on what you are doing, but if you are grabbing headers from 3rd party servers which need to be normalized, that's where you should normalize them yourself, just as you probably would do with any other framework/language.

So You don't plan normalize headers in misultin right? I will normalize them on my own then. Thanks for info about decode_packet!

all incoming HTTP requests already have their headers normalized when they are parsed.

if they aren't it's because you are inputting them in other ways, in which case you should provide whatever normalization you are referring to.

r.

I was talking about outcomming headers in Response.
My thinking was, so you normalize request headers You will normalize Response headers :)
I will normalize them myself in my code and pass right atom values to Req:respond function.

I;m doing something like this. On request i am calling web service which returns headers and body.
then i'm proxyng that data thru Req.respond

But that web service has headers in other format (all headers are lowercase) and I was thinking that misultin will normalize them for me