Commit 5d2b27de1cd0e276d7dc685ee3159d2d961da185

Authored by Georg Hopp
1 parent f8fd4993

remove specialized asset loadings and use generic one.

... ... @@ -4,11 +4,11 @@
4 4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 5 <head>
6 6 <title>My own little Web-App</title>
7   - <link rel="stylesheet" type="text/css" href="/assets/style/common">
8   - <script type="text/javascript" src="/assets/js/jquery"></script>
9   - <script type="text/javascript" src="/assets/js/serverval"></script>
10   - <script type="text/javascript" src="/assets/js/session"></script>
11   - <script type="text/javascript" src="/assets/js/init"></script>
  7 + <link rel="stylesheet" type="text/css" href="/style/common.css">
  8 + <script type="text/javascript" src="/js/jquery.js"></script>
  9 + <script type="text/javascript" src="/js/serverval.js"></script>
  10 + <script type="text/javascript" src="/js/session.js"></script>
  11 + <script type="text/javascript" src="/js/init.js"></script>
12 12 </head>
13 13 <body>
14 14 <ul id="menu">
... ... @@ -40,7 +40,7 @@
40 40 <div id="main">
41 41 <h1>Testpage</h1>
42 42 Welcome<span></span>!!!<br />
43   - <img src="/image/me" />
  43 + <img src="/image/waldschrat.jpg" />
44 44 </div>
45 45 <hr />
46 46 <div id="msg"></div>
... ...
... ... @@ -82,7 +82,8 @@ httpWorkerCtor(void * _this, va_list * params)
82 82 nvalue = strlen(value);
83 83
84 84 if ('\n' == value[nvalue-1]) {
85   - value[nvalue-1] = '\0';
  85 + nvalue--;
  86 + value[nvalue] = '\0';
86 87 }
87 88
88 89 hashAdd(this->mime_types,
... ...
... ... @@ -151,15 +151,7 @@ httpWorkerProcess(HttpWorker this, Stream st)
151 151 }
152 152
153 153 if (0 == strcmp("GET", request->method)) {
154   -
155   - if (0 == strcmp("/", request->path)) {
156   - response = httpWorkerGetAsset(
157   - request,
158   - "./assets/html/main.html",
159   - CSTRA("text/html"));
160   - }
161   -
162   - else if (0 == strcmp("/sessinfo/", request->path)) {
  154 + if (0 == strcmp("/sessinfo/", request->path)) {
163 155 response = (HttpMessage)httpResponseSession(this->session);
164 156 }
165 157
... ... @@ -182,20 +174,6 @@ httpWorkerProcess(HttpWorker this, Stream st)
182 174 }
183 175 }
184 176
185   - else if (0 == strcmp("/image/me", request->path)) {
186   - response = httpWorkerGetAsset(
187   - request,
188   - "./assets/image/waldschrat.jpg",
189   - CSTRA("image/jpeg"));
190   - }
191   -
192   - else if (0 == strcmp("/assets/js/jquery", request->path)) {
193   - response = httpWorkerGetAsset(
194   - request,
195   - "./assets/js/jquery-1.7.1.min.js",
196   - CSTRA("text/javascript"));
197   - }
198   -
199 177 else if (0 == strcmp("/assets/js/serverval", request->path)) {
200 178 response = httpWorkerGetAsset(
201 179 request,
... ... @@ -203,36 +181,24 @@ httpWorkerProcess(HttpWorker this, Stream st)
203 181 CSTRA("text/javascript"));
204 182 }
205 183
206   - else if (0 == strcmp("/assets/js/session", request->path)) {
207   - response = httpWorkerGetAsset(
208   - request,
209   - "./assets/js/session.js",
210   - CSTRA("text/javascript"));
211   - }
212   -
213   - else if (0 == strcmp("/assets/js/init", request->path)) {
214   - response = httpWorkerGetAsset(
215   - request,
216   - "./assets/js/init.js",
217   - CSTRA("text/javascript"));
218   - }
219   -
220   - else if (0 == strcmp("/assets/style/common", request->path)) {
221   - response = httpWorkerGetAsset(
222   - request,
223   - "./assets/style/common.css",
224   - CSTRA("text/css"));
225   - }
226   -
227 184 else {
228 185 char html_asset[2048] = "./assets/html";
229 186 char base_asset[2048] = "./assets";
  187 + char main_asset[] = "/main.html";
230 188
231   - char * extension = strrchr(request->path, '.');
232   - char * mime_type = NULL;
  189 + char * mime_type = NULL;
233 190 char default_mime[] = "application/octet-stream";
234   - char * asset = base_asset;
  191 + char * asset_path = base_asset;
  192 + char * asset;
  193 + char * extension;
  194 +
  195 + if (0 == strcmp("/", request->path)) {
  196 + asset = main_asset;
  197 + } else {
  198 + asset = request->path;
  199 + }
235 200
  201 + extension = strrchr(asset, '.');
236 202
237 203 if (NULL != extension) {
238 204 extension++;
... ... @@ -241,17 +207,17 @@ httpWorkerProcess(HttpWorker this, Stream st)
241 207
242 208 if (NULL != mime_type &&
243 209 0 == memcmp(mime_type, CSTRA("text/html"))) {
244   - asset = html_asset;
  210 + asset_path = html_asset;
245 211 }
246 212
247 213 if (NULL == mime_type) {
248 214 mime_type = default_mime;
249 215 }
250 216
251   - strcat(asset, request->path);
  217 + strcat(asset_path, asset);
252 218 response = httpWorkerGetAsset(
253 219 request,
254   - asset,
  220 + asset_path,
255 221 mime_type,
256 222 strlen(mime_type));
257 223 }
... ...
Please register or login to post a comment