00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #include "HttpNet.h"
00025 #include <iostream.h>
00026 #include "ink_assert.h"
00027 #include "DebugStream.h"
00028 #include "IOBuffer.h"
00029 #include "Main.h"
00030 #include "Event.h"
00031 #include "ProtectedQueue.h"
00032 #include "Cluster.h"
00033 #include "HttpConfig.h"
00034 #include "HttpTransact.h"
00035 
00036 HttpNetProcessor httpNetProcessor;
00037 HttpConfigParams httpConfigParams;
00038 DebugStream debug_out("debug.txt", 1, 1, "DebugStreamLevels.txt", "http.stops");
00039 
00040 
00041 
00042 
00043 
00044 typedef struct
00045 {
00046   char *accept;
00047   char *field;
00048 } AcceptPair;
00049 
00050 void
00051 test()
00052 {
00053   float q;
00054 
00055 
00056 
00057   static AcceptPair a1[] = {
00058     {"*", "text/html"},
00059     {"image/gif, *; q=.9, text/*; q=.2", "text/html"},
00060     {NULL, NULL}
00061   };
00062 
00063   fprintf(stderr, "\n*** Testing Accept matching ***\n");
00064   for (int i = 0; a1[i].accept; i++) {
00065     q = HttpTransact::CalcQualityOfAcceptMatch(a1[i].accept, a1[i].field);
00066     fprintf(stderr, "Accept(\"%s\",\"%s\") ==> %g\n", a1[i].accept, a1[i].field, q);
00067   }
00068 
00069 
00070 
00071   static AcceptPair a2[] = {
00072     {"*", "us-ascii"},
00073     {NULL, NULL}
00074   };
00075 
00076   fprintf(stderr, "\n*** Testing Accept-Charset matching ***\n");
00077   for (int i = 0; a2[i].accept; i++) {
00078     q = HttpTransact::CalcQualityOfAcceptCharsetMatch(a2[i].accept, a2[i].field);
00079     fprintf(stderr, "Accept-Charset(\"%s\",\"%s\") ==> %g\n", a2[i].accept, a2[i].field, q);
00080   }
00081 
00082 
00083 
00084   static AcceptPair a3[] = {
00085     {"*", "gzip"},
00086     {NULL, NULL}
00087   };
00088 
00089   fprintf(stderr, "\n*** Testing Accept-Encoding matching ***\n");
00090   for (int i = 0; a3[i].accept; i++) {
00091     q = HttpTransact::CalcQualityOfAcceptEncodingMatch(a3[i].accept, a3[i].field);
00092     fprintf(stderr, "Accept-Encoding(\"%s\",\"%s\") ==> %g\n", a3[i].accept, a3[i].field, q);
00093   }
00094 
00095 
00096 
00097   static AcceptPair a4[] = {
00098     {"*", "en"},
00099     {"*", ""},
00100     {"fr, en", "en-ebonics"},
00101     {"fr, en-ebonics", "en-ebonics"},
00102     {"fr, *;q=.314, en-ebonics", "en-boston"},
00103     {"fr, *;q=.314, en-ebonics", "en-ebonics-oakland"},
00104     {NULL, NULL}
00105   };
00106 
00107   fprintf(stderr, "\n*** Testing Accept-Language matching ***\n");
00108   for (int i = 0; a4[i].accept; i++) {
00109     q = HttpTransact::CalcQualityOfAcceptLanguageMatch(a4[i].accept, a4[i].field);
00110     fprintf(stderr, "Accept-Language(\"%s\",\"%s\") ==> %g\n", a4[i].accept, a4[i].field, q);
00111   }
00112 }