• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

TestHttpTransact.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
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   ///// Accept /////
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   ///// Accept-Charset /////
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   ///// Accept-Encoding /////
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   ///// Accept-Language /////
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 }

Generated by  doxygen 1.7.1