Ignore:
Timestamp:
05/01/11 18:07:52 (9 years ago)
Author:
Admin
Message:

WebIf: Add Content-Length to headers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam-http-helpers.c

    r5152 r5154  
    410410}
    411411
    412 void send_headers(FILE *f, int32_t status, char *title, char *extra, char *mime, int32_t cache, int8_t forcePlain){
     412void send_headers(FILE *f, int32_t status, char *title, char *extra, char *mime, int32_t cache, int32_t length, int8_t forcePlain){
    413413  time_t now;
    414414  char timebuf[32];
    415   char buf[sizeof(PROTOCOL) + sizeof(SERVER) + strlen(title) + (extra == NULL?0:strlen(extra)+2) + (mime == NULL?0:strlen(mime)+2) + 256];
     415  char buf[sizeof(PROTOCOL) + sizeof(SERVER) + strlen(title) + (extra == NULL?0:strlen(extra)+2) + (mime == NULL?0:strlen(mime)+2) + 300];
    416416  char *pos = buf;
    417417   
     
    435435        pos += snprintf(pos, sizeof(buf)-(pos-buf),"Cache-Control: public, max-age=7200\r\n");
    436436    }
     437    pos += snprintf(pos, sizeof(buf)-(pos-buf),"Content-Length: %d\r\n", length);
    437438    pos += snprintf(pos, sizeof(buf)-(pos-buf),"Last-Modified: %s\r\n", timebuf);
    438439    pos += snprintf(pos, sizeof(buf)-(pos-buf), "Connection: close\r\n");
     
    447448void send_file(FILE *f, char *filename){
    448449    int32_t fileno = 0;
     450    char* mimetype = "";
    449451
    450452    if (!strcmp(filename, "CSS")){
    451453        filename = cfg.http_css;
     454        mimetype = "text/css";
    452455        fileno = 1;
    453456    } else if (!strcmp(filename, "JS")){
    454457        filename = cfg.http_jscript;
     458        mimetype = "text/javascript";
    455459        fileno = 2;
    456460    }
     
    464468        while((read = fread(buffer,sizeof(char), 1023, fp)) > 0) {
    465469            buffer[read] = '\0';
     470            send_headers(f, 200, "OK", NULL, mimetype, 1, strlen(buffer), 0);
    466471            webif_write(buffer, f);
    467472        }
     
    469474        fclose (fp);
    470475    } else {
    471         if (fileno == 1)
     476        if (fileno == 1){
     477            send_headers(f, 200, "OK", NULL, mimetype, 1, strlen(CSS), 0);
    472478            webif_write(CSS, f);
    473         else if (fileno == 2)
     479        } else if (fileno == 2){
     480            send_headers(f, 200, "OK", NULL, mimetype, 1, strlen(JSCRIPT), 0);
    474481            webif_write(JSCRIPT, f);
     482        }
    475483    }
    476484}
     
    479487    char buf[(2* strlen(title)) + strlen(text) + 128];
    480488    char *pos = buf;
    481     send_headers(f, status, title, extra, "text/html", 0, forcePlain);
     489    send_headers(f, status, title, extra, "text/html", 0, strlen(buf), forcePlain);
    482490    pos += snprintf(pos, sizeof(buf)-(pos-buf), "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\r\n", status, title);
    483491    pos += snprintf(pos, sizeof(buf)-(pos-buf), "<BODY><H4>%d %s</H4>\r\n", status, title);
Note: See TracChangeset for help on using the changeset viewer.