/[jscoverage]/tags/jscoverage-0.4/jscoverage-server.c
ViewVC logotype

Diff of /tags/jscoverage-0.4/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 317 by siliconforks, Tue Oct 14 01:28:46 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 443  Line 444 
444      case '\t':      case '\t':
445        fputs("\\t", f);        fputs("\\t", f);
446        break;        break;
447        /* IE doesn't support this */
448        /*
449      case '\v':      case '\v':
450        fputs("\\v", f);        fputs("\\v", f);
451        break;        break;
452        */
453      case '"':      case '"':
454        fputs("\\\"", f);        fputs("\\\"", f);
455        break;        break;
# Line 852  Line 856 
856      free(encoding);      free(encoding);
857      Stream_delete(input_stream);      Stream_delete(input_stream);
858      if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {      if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {
859        free(characters);        send_response(client_exchange, 500, "Encoding not supported\n");
       send_response(client_exchange, 502, "Encoding not supported\n");  
860        goto done;        goto done;
861      }      }
862      else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {      else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
       free(characters);  
863        send_response(client_exchange, 502, "Error decoding response\n");        send_response(client_exchange, 502, "Error decoding response\n");
864        goto done;        goto done;
865      }      }
# Line 870  Line 872 
872        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) {
873          continue;          continue;
874        }        }
875          else if (strcasecmp(h->name, HTTP_CONTENT_TYPE) == 0) {
876            HTTPExchange_add_response_header(client_exchange, HTTP_CONTENT_TYPE, "text/javascript; charset=ISO-8859-1");
877            continue;
878          }
879        HTTPExchange_add_response_header(client_exchange, h->name, h->value);        HTTPExchange_add_response_header(client_exchange, h->name, h->value);
880      }      }
881      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 1012 
1012        goto done;        goto done;
1013      }      }
1014    
1015        /*
1016        When do we send a charset with Content-Type?
1017        if Content-Type is "text" or "application"
1018          if instrumented JavaScript
1019            use Content-Type: application/javascript; charset=ISO-8859-1
1020          else if --encoding is given
1021            use that encoding
1022          else
1023            send no charset
1024        else
1025          send no charset
1026        */
1027      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);  
1028      if (strcmp(content_type, "text/javascript") == 0 && ! is_no_instrument(abs_path)) {      if (strcmp(content_type, "text/javascript") == 0 && ! is_no_instrument(abs_path)) {
1029          HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, "text/javascript; charset=ISO-8859-1");
1030    
1031        Stream * input_stream = Stream_new(0);        Stream * input_stream = Stream_new(0);
1032        Stream_write_file_contents(input_stream, f);        Stream_write_file_contents(input_stream, f);
1033    
# Line 1018  Line 1037 
1037        Stream_delete(input_stream);        Stream_delete(input_stream);
1038    
1039        if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {        if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {
         free(characters);  
1040          send_response(exchange, 500, "Encoding not supported\n");          send_response(exchange, 500, "Encoding not supported\n");
1041          goto done;          goto done;
1042        }        }
1043        else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {        else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
         free(characters);  
1044          send_response(exchange, 500, "Error decoding JavaScript file\n");          send_response(exchange, 500, "Error decoding JavaScript file\n");
1045          goto done;          goto done;
1046        }        }
# Line 1038  Line 1055 
1055        Stream_delete(output_stream);        Stream_delete(output_stream);
1056      }      }
1057      else {      else {
1058          /* send the Content-Type with charset if necessary */
1059          if (specified_encoding != NULL && (str_starts_with(content_type, "text/") || str_starts_with(content_type, "application/"))) {
1060            char * content_type_with_charset = NULL;
1061            xasprintf(&content_type_with_charset, "%s; charset=%s", content_type, specified_encoding);
1062            HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, content_type_with_charset);
1063            free(content_type_with_charset);
1064          }
1065          else {
1066            HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, content_type);
1067          }
1068    
1069        char buffer[8192];        char buffer[8192];
1070        size_t bytes_read;        size_t bytes_read;
1071        while ((bytes_read = fread(buffer, 1, 8192, f)) > 0) {        while ((bytes_read = fread(buffer, 1, 8192, f)) > 0) {
# Line 1086  Line 1114 
1114        exit(EXIT_SUCCESS);        exit(EXIT_SUCCESS);
1115      }      }
1116      else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {      else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
1117        printf("jscoverage-server %s\n", VERSION);        version();
       exit(EXIT_SUCCESS);  
1118      }      }
1119      else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {      else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
1120        verbose = 1;        verbose = 1;
# Line 1121  Line 1148 
1148          fatal_command_line("--encoding: option requires an argument");          fatal_command_line("--encoding: option requires an argument");
1149        }        }
1150        jscoverage_encoding = argv[i];        jscoverage_encoding = argv[i];
1151          specified_encoding = jscoverage_encoding;
1152      }      }
1153      else if (strncmp(argv[i], "--encoding=", 11) == 0) {      else if (strncmp(argv[i], "--encoding=", 11) == 0) {
1154        jscoverage_encoding = argv[i] + 11;        jscoverage_encoding = argv[i] + 11;
1155          specified_encoding = jscoverage_encoding;
1156      }      }
1157    
1158      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.317

  ViewVC Help
Powered by ViewVC 1.1.24