annotate http/url.k @ 14:bc647a5f0421 draft

modify HttpRequest.k
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 29 May 2012 00:22:51 +0900
parents 0335cdd081d0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
da5149cbb9f4 add http/test/urlTest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1 class URL {
4
108812b08e75 add http/postRequest.k http/url.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
12
da5149cbb9f4 add http/test/urlTest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
3 String url;
da5149cbb9f4 add http/test/urlTest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
4 String host;
13
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
5 String uri;
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
6
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
7 String copyString(String str, int index) {
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
8 int size = str.getSize();
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
9 String tmp = "";
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
10 for (int i=index; i < size; i++) {
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
11 tmp += str[i];
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
12 }
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
13 return tmp;
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
14 }
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
15
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
16
12
da5149cbb9f4 add http/test/urlTest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
17 URL(String url) {
da5149cbb9f4 add http/test/urlTest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
18 int ret = url.search("http://");
13
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
19 if ( ret != 0) {
12
da5149cbb9f4 add http/test/urlTest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
20 throw new Script!!("unknown protocol");
4
108812b08e75 add http/postRequest.k http/url.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 }
13
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
22 this.url = url;
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
23 String str = url.split("http://")[1];
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
24 ret = str.search("/");
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
25 if ( ret == -1) {
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
26 this.uri = "/";
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
27 this.host = str;
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
28 } else {
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
29 this.host = str.split("/")[0];
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
30 this.uri = copyString(str, ret);
0335cdd081d0 modify HttpRequest.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
31 }
4
108812b08e75 add http/postRequest.k http/url.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 }
108812b08e75 add http/postRequest.k http/url.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
108812b08e75 add http/postRequest.k http/url.k
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }