Skip to content

Commit

Permalink
Compliance with standards
Browse files Browse the repository at this point in the history
  • Loading branch information
canalpay committed Feb 16, 2011
1 parent 4e6fb7f commit 086f6c3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 39 deletions.
49 changes: 35 additions & 14 deletions library/cookie.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,77 @@ import library.fixedString;
import std.conv;
import std.cstream;



string[string] cookie()
{
string[string] resultCookie;
string cookie = getenv("HTTP_COOKIE");


resultCookie=forCookie(decode(cookie)); //fixedString.forCookie
resultCookie = forCookie(decode(cookie)); //fixedString.forCookie


return resultCookie;
}

void setCookie(string name, string data, long expiresIn = 0, string path = null, string domain = null, bool httpOnly = false)



void setCookie(string name, string data, long expiresIn = 0,
string path = null, string domain = null, bool httpOnly = false)
{

string[] responseCookies;

string cookie = name ~ "=";
cookie ~= data;
string[] hd;
if(path !is null)


if (path !is null) {
cookie ~= "; path=" ~ path;
if(expiresIn != 0)
}

if (expiresIn != 0) {
cookie ~= "; Max-Age=" ~ to!(string)(expiresIn);
if(domain !is null)
}

if (domain !is null) {
cookie ~= "; domain=" ~ domain;
if(httpOnly == true )
}

if (httpOnly == true) {
cookie ~= "; HttpOnly";
}

responseCookies ~= cookie;
foreach(c; responseCookies)

foreach (c; responseCookies) {
hd ~= "Set-Cookie: " ~ c;
}

foreach(one;hd)
foreach (one; hd) {
std.stdio.writeln(one);

}
}


void endCookie()
{
std.stdio.writeln();
}





void clearCookie(string name, string path = null, string domain = null) {

string[string] test;
test=cookie();
if(name in test)
test = cookie();

if (name in test) {
setCookie(name, "", 1, path, domain);
} else {
//thrown error with standard error of turna. But it yet is not defined standart error of turna.
}

}
13 changes: 9 additions & 4 deletions library/envVar.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import std.conv;
import std.uri;
//import library.convertToUTF8;
import library.fixedString;


/*
* This module is for the get method.
*
Expand All @@ -27,7 +29,7 @@ string[string] get()
string get = getenv("QUERY_STRING");


resultGet=forGetAndPost(get); //fixedString.forGetAndPost
resultGet = forGetAndPost(get); //fixedString.forGetAndPost



Expand All @@ -48,20 +50,23 @@ string[string] post()

string[string] resultPost;
char[] firstPost;
while(firstPost.length<to!int(getenv("CONTENT_LENGTH"))){


while (firstPost.length < to!int(getenv("CONTENT_LENGTH"))) {

firstPost~=din.getc;
firstPost ~= din.getc;

}


resultPost=forGetAndPost(to!(string)(firstPost));//fixedString.forGetAndPost
resultPost = forGetAndPost(to!(string)(firstPost));//fixedString.forGetAndPost


return resultPost;

}


string serverSoftware()
{
return decode(getenv("SERVER_SOFTWARE"));
Expand Down
40 changes: 19 additions & 21 deletions library/fixedString.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ import std.uri;

string[string] forGetAndPost(string input)
{
input= decode(input);
input= replace(input, "+", " ");
input = decode(input);
input = replace(input, "+", " ");
string[string] endInput;

string[] fixedInput1=split(input, "&"); //

string[][] fixedInput2;

foreach(fixedInput;fixedInput1) {
foreach (fixedInput;fixedInput1) {

fixedInput2~=split(fixedInput,"=");
fixedInput2 ~= split(fixedInput,"=");

}

for(int a=0;a<fixedInput1.length;++a) {
for(int b=1;b<fixedInput2[a].length;++b) {
for (int a=0; a < fixedInput1.length ; ++a) {
for (int b = 1; b < fixedInput2[a].length; ++b) {
//endInput[fixedInput2[a][0]]~=fixedInput2[a][b+1];
endInput[fixedInput2[a][0]]~=fixedInput2[a][b];
endInput[fixedInput2[a][0]] ~= fixedInput2[a][b];
}
}

Expand All @@ -41,9 +41,9 @@ unittest
{
string[string] deneme;

deneme=forGetAndPost("hayvan=at&derece=Orta&ikinci+d%C3%BC%C4%9Fme=Ba%C5%9Fka+D%C3%BC%C4%9Fme");
assert(deneme["hayvan"]=="at");
assert(deneme["ikinci düğme"]=="Başka Düğme");
deneme = forGetAndPost("hayvan=at&derece=Orta&ikinci+d%C3%BC%C4%9Fme=Ba%C5%9Fka+D%C3%BC%C4%9Fme");
assert(deneme["hayvan"] == "at");
assert(deneme["ikinci düğme"] == "Başka Düğme");

}

Expand All @@ -52,20 +52,18 @@ string[string] forCookie(string input)
{
string[string] endInput;

string[] fixedInput1=split(input, "; "); //
string[] fixedInput1 = split(input, "; "); //

string[][] fixedInput2;

foreach(fixedInput;fixedInput1) {

fixedInput2~=split(fixedInput,"=");

foreach (fixedInput; fixedInput1) {
fixedInput2 ~= split(fixedInput,"=");
}

for(int a=0;a<fixedInput1.length;++a) {
for(int b=1;b<fixedInput2[a].length;++b) {
for (int a = 0; a < fixedInput1.length; ++a) {
for (int b=1; b < fixedInput2[a].length; ++b) {
//endInput[fixedInput2[a][0]]~=fixedInput2[a][b+1];
endInput[fixedInput2[a][0]]~=fixedInput2[a][b];
endInput[fixedInput2[a][0]] ~= fixedInput2[a][b];
}
}

Expand All @@ -76,9 +74,9 @@ unittest
{
string[string] deneme;

deneme=forCookie("deneme=lalala; olala olalala=passaporala ekranlarda");
assert(deneme["deneme"]=="lalala");
assert(deneme["olala olalala"]=="passaporala ekranlarda");
deneme = forCookie("deneme=lalala; olala olalala=passaporala ekranlarda");
assert(deneme["deneme"] == "lalala");
assert(deneme["olala olalala"] == "passaporala ekranlarda");

}

0 comments on commit 086f6c3

Please sign in to comment.