0

i custom varnish 500 error page,but i found that it could not display chinese characters,

i tried deliver an error page from a static file, but it is not working User-friendly error pages from Varnish

Community
  • 1
  • 1
mk_
  • 409
  • 1
  • 3
  • 17

2 Answers2

0

The example you're pointing to manipulates the file contents with sprintf and strcat, which probably don't work well on UTF-8 (your file is in UTF-8 like the header states, right?). You might test your luck with a byte-based C function like memcpy, or use a utf-8 proof string copy/formatting function (never dealt with this stuff in C).

Could you describe it is not working in more detail?

Community
  • 1
  • 1
ivy
  • 5,539
  • 1
  • 34
  • 48
  • thanks for reply, so sorry i have no feedback until now.I am new at C, but After a lot of debugging and tracing , this problem has been resolved, below is the full part of Related in varnish.vcf – mk_ Jul 03 '12 at 09:20
0

below is the full part of Related in varnish.vcf

C{
  #include <stdio.h>
  #include <stddef.h>
  #include <stdlib.h>
}C
sub vcl_error {

set obj.http.Content-Type = "text/html; charset=utf-8";
set obj.http.Retry-After = "5";
if ((obj.status == 500 || obj.status == 503)&&client.ip !~ flnet){
   C{
     FILE    *infile;
     char    *buffer;
     char fname [50];
     long    numbytes;

        sprintf(fname, "/var/www/html/%d.html", VRT_r_obj_status(sp));
     infile = fopen(fname, "r");
      if(infile == NULL)
         return 1;

       fseek(infile, 0L, SEEK_END);
       numbytes = ftell(infile);
       fseek(infile, 0L, SEEK_SET);
       buffer = (char*)calloc(numbytes, sizeof(char));
       fread(buffer, sizeof(char), numbytes, infile);
       fclose(infile);
       VRT_synth_page(sp, 0, buffer, "<!-- XID: ", VRT_r_req_xid(sp), " -->", vrt_magic_string_end);

       free(buffer);
     return 0;
    }C
  }
mk_
  • 409
  • 1
  • 3
  • 17