/[jscoverage]/trunk/jscoverage-server.c
ViewVC logotype

Diff of /trunk/jscoverage-server.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 253 by siliconforks, Sun Oct 5 18:09:02 2008 UTC revision 312 by siliconforks, Mon Oct 13 17:52:01 2008 UTC
# Line 38  Line 38 
38  #include "stream.h"  #include "stream.h"
39  #include "util.h"  #include "util.h"
40    
41    static const char * specified_encoding = NULL;
42  const char * jscoverage_encoding = "ISO-8859-1";  const char * jscoverage_encoding = "ISO-8859-1";
43  bool jscoverage_highlight = true;  bool jscoverage_highlight = true;
44    
# Line 852  Line 853 
853      free(encoding);      free(encoding);
854      Stream_delete(input_stream);      Stream_delete(input_stream);
855      if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {      if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {
856        free(characters);        send_response(client_exchange, 500, "Encoding not supported\n");
       send_response(client_exchange, 502, "Encoding not supported\n");  
857        goto done;        goto done;
858      }      }
859      else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {      else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
       free(characters);  
860        send_response(client_exchange, 502, "Error decoding response\n");        send_response(client_exchange, 502, "Error decoding response\n");
861        goto done;        goto done;
862      }      }
# Line 870  Line 869 
869        if (is_hop_by_hop_header(h->name) || strcasecmp(h->name, HTTP_CONTENT_LENGTH) == 0) {        if (is_hop_by_hop_header(h->name) || strcasecmp(h->name, HTTP_CONTENT_LENGTH) == 0) {
870          continue;          continue;
871        }        }
872          else if (strcasecmp(h->name, HTTP_CONTENT_TYPE) == 0) {
873            HTTPExchange_add_response_header(client_exchange, HTTP_CONTENT_TYPE, "text/javascript; charset=ISO-8859-1");
874            continue;
875          }
876        HTTPExchange_add_response_header(client_exchange, h->name, h->value);        HTTPExchange_add_response_header(client_exchange, h->name, h->value);
877      }      }
878      add_via_header(HTTPExchange_get_response_message(client_exchange), HTTPExchange_get_response_http_version(server_exchange));      add_via_header(HTTPExchange_get_response_message(client_exchange), HTTPExchange_get_response_http_version(server_exchange));
# Line 1006  Line 1009 
1009        goto done;        goto done;
1010      }      }
1011    
1012        /*
1013        When do we send a charset with Content-Type?
1014        if Content-Type is "text" or "application"
1015          if instrumented JavaScript
1016            use Content-Type: application/javascript; charset=ISO-8859-1
1017          else if --encoding is given
1018            use that encoding
1019          else
1020            send no charset
1021        else
1022          send no charset
1023        */
1024      const char * content_type = get_content_type(filesystem_path);      const char * content_type = get_content_type(filesystem_path);
     HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, content_type);  
1025      if (strcmp(content_type, "text/javascript") == 0 && ! is_no_instrument(abs_path)) {      if (strcmp(content_type, "text/javascript") == 0 && ! is_no_instrument(abs_path)) {
1026          HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, "text/javascript; charset=ISO-8859-1");
1027    
1028        Stream * input_stream = Stream_new(0);        Stream * input_stream = Stream_new(0);
1029        Stream_write_file_contents(input_stream, f);        Stream_write_file_contents(input_stream, f);
1030    
# Line 1018  Line 1034 
1034        Stream_delete(input_stream);        Stream_delete(input_stream);
1035    
1036        if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {        if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {
         free(characters);  
1037          send_response(exchange, 500, "Encoding not supported\n");          send_response(exchange, 500, "Encoding not supported\n");
1038          goto done;          goto done;
1039        }        }
1040        else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {        else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
         free(characters);  
1041          send_response(exchange, 500, "Error decoding JavaScript file\n");          send_response(exchange, 500, "Error decoding JavaScript file\n");
1042          goto done;          goto done;
1043        }        }
# Line 1038  Line 1052 
1052        Stream_delete(output_stream);        Stream_delete(output_stream);
1053      }      }
1054      else {      else {
1055          /* send the Content-Type with charset if necessary */
1056          if (specified_encoding != NULL && (str_starts_with(content_type, "text/") || str_starts_with(content_type, "application/"))) {
1057            char * content_type_with_charset = NULL;
1058            xasprintf(&content_type_with_charset, "%s; charset=%s", content_type, specified_encoding);
1059            HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, content_type_with_charset);
1060            free(content_type_with_charset);
1061          }
1062          else {
1063            HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, content_type);
1064          }
1065    
1066        char buffer[8192];        char buffer[8192];
1067        size_t bytes_read;        size_t bytes_read;
1068        while ((bytes_read = fread(buffer, 1, 8192, f)) > 0) {        while ((bytes_read = fread(buffer, 1, 8192, f)) > 0) {
# Line 1086  Line 1111 
1111        exit(EXIT_SUCCESS);        exit(EXIT_SUCCESS);
1112      }      }
1113      else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {      else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
1114        printf("jscoverage-server %s\n", VERSION);        version();
       exit(EXIT_SUCCESS);  
1115      }      }
1116      else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {      else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
1117        verbose = 1;        verbose = 1;
# Line 1121  Line 1145 
1145          fatal_command_line("--encoding: option requires an argument");          fatal_command_line("--encoding: option requires an argument");
1146        }        }
1147        jscoverage_encoding = argv[i];        jscoverage_encoding = argv[i];
1148          specified_encoding = jscoverage_encoding;
1149      }      }
1150      else if (strncmp(argv[i], "--encoding=", 11) == 0) {      else if (strncmp(argv[i], "--encoding=", 11) == 0) {
1151        jscoverage_encoding = argv[i] + 11;        jscoverage_encoding = argv[i] + 11;
1152          specified_encoding = jscoverage_encoding;
1153      }      }
1154    
1155      else if (strcmp(argv[i], "--ip-address") == 0) {      else if (strcmp(argv[i], "--ip-address") == 0) {

Legend:
Removed from v.253  
changed lines
  Added in v.312

  ViewVC Help
Powered by ViewVC 1.1.24