
  2002-11-09 (-q1)
    ¡¦charset¤Î»ØÄê¤¬¤Ê¤¤¤È¤­¡¤Content-Type¥Ø¥Ã¥À¤Ëcharset¤òÉÕ¤±¤Ê¤¤¤è¤¦¤Ë¤·¤¿¡£
    ¡¦¥¨¥é¡¼¤¬È¯À¸¤·¤¿¤È¤­¤Ë¡¤¸¶°ø¤ÏÉÔÌÀ¤À¤¬¡¤eruby¤¬µïºÂ¤Ã¤Æ¤·¤Þ¤¦¡£Apache
      ¤Î¥¨¥é¡¼¥í¥°¤ËÂçÎÌ¤Ë½ÐÎÏ¤¬¤¢¤ë¤¬¡¤²èÌÌ¤ËÉ½¼¨¤·¤¿Êý¤¬¤è¤µ¤½¤¦¤Ê¤Î¤Ç¡¤
      CGI¤Î¾ì¹ç¤Ï¡¤¾ï¤Ë¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤òÉ½¼¨¤¹¤ë¤è¤¦¤Ë¤¹¤ë¡£

  2002-11-10 (-q2)
    ¡¦¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤òÉ½¼¨¤¹¤ë¤È¤­¤Ï¡¤¾õÂÖ¥³¡¼¥É¤ò500¤È¤·¤¿¡£

  2002-11-23 (-q3)
    ¡¦ERuby.headers_out¤òÄÉ²Ã¡£HTTP¥Ø¥Ã¥À¡¼¥Õ¥£¡¼¥ë¥É¤òÄÉ²Ã¤Ç¤­¤ë¤è¤¦¤Ë¤·¤¿¡£

diff -Ncr eruby-0.9.8.orig/eruby.h eruby-0.9.8-cur/eruby.h
*** eruby-0.9.8.orig/eruby.h	Fri Apr 19 17:33:27 2002
--- eruby-0.9.8-cur/eruby.h	Sat Nov 23 13:24:29 2002
***************
*** 31,36 ****
--- 31,37 ----
  extern int eruby_noheader;
  extern VALUE eruby_charset;
  extern VALUE eruby_default_charset;
+ extern VALUE eruby_headers_out;
  #define ERUBY_CHARSET RSTRING(eruby_charset)->ptr
  
  const char *eruby_version();
diff -Ncr eruby-0.9.8.orig/eruby_lib.c eruby-0.9.8-cur/eruby_lib.c
*** eruby-0.9.8.orig/eruby_lib.c	Mon Jan  7 18:10:53 2002
--- eruby-0.9.8-cur/eruby_lib.c	Sat Nov 23 14:17:53 2002
***************
*** 49,54 ****
--- 49,55 ----
  int eruby_noheader = 0;
  VALUE eruby_charset;
  VALUE eruby_default_charset;
+ VALUE eruby_headers_out;
  
  #define ERUBY_BEGIN_DELIMITER "<%"
  #define ERUBY_END_DELIMITER "%>"
***************
*** 751,756 ****
--- 752,766 ----
      return Qnil;
  }
  
+ static VALUE eruby_get_headers_out(VALUE self)
+ {
+     if (NIL_P(eruby_headers_out)) {
+         eruby_headers_out = rb_ary_new();
+         rb_global_variable(&eruby_headers_out);
+     }
+     return eruby_headers_out;
+ }
+ 
  void eruby_init()
  {
      rb_define_virtual_variable("$NOHEADER", noheader_getter, noheader_setter);
***************
*** 766,771 ****
--- 776,782 ----
  			       eruby_set_default_charset, 1);
      rb_define_singleton_method(mERuby, "import", eruby_import, 1);
      rb_define_singleton_method(mERuby, "load", eruby_import, 1);
+     rb_define_singleton_method(mERuby, "headers_out", eruby_get_headers_out, 0);
  
      cERubyCompiler = rb_define_class_under(mERuby, "Compiler", rb_cObject);
      rb_define_singleton_method(cERubyCompiler, "new", eruby_compiler_s_new, 0);
***************
*** 786,791 ****
--- 797,804 ----
      rb_global_variable(&eruby_charset);
      rb_global_variable(&eruby_default_charset);
  
+     eruby_headers_out = Qnil;
+ 
      rb_provide("eruby");
  }
  
diff -Ncr eruby-0.9.8.orig/eruby_main.c eruby-0.9.8-cur/eruby_main.c
*** eruby-0.9.8.orig/eruby_main.c	Mon Oct 15 13:55:40 2001
--- eruby-0.9.8-cur/eruby_main.c	Sat Nov 23 13:37:35 2002
***************
*** 275,287 ****
      return s;
  }
  
! static void print_http_headers()
  {
!     char *tmp;
  
      if ((tmp = getenv("SERVER_PROTOCOL")) == NULL)
          tmp = "HTTP/1.0";
!     printf("%s 200 OK\r\n", tmp);
      if ((tmp = getenv("SERVER_SOFTWARE")) == NULL)
  	tmp = "unknown-server/0.0";
      printf("Server: %s\r\n", tmp);
--- 275,287 ----
      return s;
  }
  
! static void print_http_headers(const char* status)
  {
!     const char* tmp;
  
      if ((tmp = getenv("SERVER_PROTOCOL")) == NULL)
          tmp = "HTTP/1.0";
!     printf("%s %s\r\n", tmp, status);
      if ((tmp = getenv("SERVER_SOFTWARE")) == NULL)
  	tmp = "unknown-server/0.0";
      printf("Server: %s\r\n", tmp);
***************
*** 299,306 ****
  	if ((imgdir = getenv("SCRIPT_NAME")) == NULL)
  	    imgdir = "UNKNOWN_IMG_DIR";
          if (mode == MODE_NPHCGI)
!             print_http_headers();
          fprintf(out, "Content-Type: text/html\r\n");
          fprintf(out, "Content-Style-Type: text/css\r\n");
          fprintf(out, "\r\n");
  	fprintf(out, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n");
--- 299,307 ----
  	if ((imgdir = getenv("SCRIPT_NAME")) == NULL)
  	    imgdir = "UNKNOWN_IMG_DIR";
          if (mode == MODE_NPHCGI)
!             print_http_headers("500 Internal Server Error");
          fprintf(out, "Content-Type: text/html\r\n");
+         fprintf(out, "Status: 500 Internal Server Error\r\n");
          fprintf(out, "Content-Style-Type: text/css\r\n");
          fprintf(out, "\r\n");
  	fprintf(out, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n");
***************
*** 420,426 ****
  static void give_img_logo(int mode)
  {
      if (mode == MODE_NPHCGI)
! 	print_http_headers();
      printf("Content-Type: image/png\r\n\r\n");
      fwrite(eruby_logo_data, eruby_logo_size, 1, stdout);
  }
--- 421,427 ----
  static void give_img_logo(int mode)
  {
      if (mode == MODE_NPHCGI)
! 	print_http_headers("200 OK");
      printf("Content-Type: image/png\r\n\r\n");
      fwrite(eruby_logo_data, eruby_logo_size, 1, stdout);
  }
***************
*** 532,539 ****
      code = eruby_load(eruby_filename, 0, &state);
      ruby_finalize();
      if (state && !rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
! 	if (RTEST(ruby_debug) &&
! 	    (eruby_mode == MODE_CGI || eruby_mode == MODE_NPHCGI)) {
  	    error_print(stdout, state, 1, eruby_mode, code);
  	    exit(0);
  	}
--- 533,539 ----
      code = eruby_load(eruby_filename, 0, &state);
      ruby_finalize();
      if (state && !rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
! 	if (eruby_mode == MODE_CGI || eruby_mode == MODE_NPHCGI) {
  	    error_print(stdout, state, 1, eruby_mode, code);
  	    exit(0);
  	}
***************
*** 548,559 ****
      out = RSTRING(rb_defout)->ptr;
      nout = RSTRING(rb_defout)->len;
      if (!eruby_noheader &&
! 	(eruby_mode == MODE_CGI || eruby_mode == MODE_NPHCGI)) {
  	if (eruby_mode == MODE_NPHCGI)
! 	    print_http_headers();
  
! 	printf("Content-Type: text/html; charset=%s\r\n", ERUBY_CHARSET);
  	printf("Content-Length: %d\r\n", nout);
  	printf("\r\n");
      }
      fwrite(out, nout, 1, stdout);
--- 548,572 ----
      out = RSTRING(rb_defout)->ptr;
      nout = RSTRING(rb_defout)->len;
      if (!eruby_noheader &&
!        (eruby_mode == MODE_CGI || eruby_mode == MODE_NPHCGI)) {
  	if (eruby_mode == MODE_NPHCGI)
! 	    print_http_headers("200 OK");
  
!         if (ERUBY_CHARSET && ERUBY_CHARSET[0] != '\0')
!             printf("Content-Type: text/html; charset=%s\r\n", ERUBY_CHARSET);
!         else
!             printf("Content-Type: text/html\r\n");
  	printf("Content-Length: %d\r\n", nout);
+ 
+         if (!NIL_P(eruby_headers_out)) {
+             int i;
+             for (i = 0; i < RARRAY(eruby_headers_out)->len; i++) {
+                 VALUE s = rb_ary_entry(eruby_headers_out, i);
+                 Check_Type(s, T_STRING);
+                 printf("%s\r\n", STR2CSTR(s));
+             }
+         }
+ 
  	printf("\r\n");
      }
      fwrite(out, nout, 1, stdout);
