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

TestHttpHeader.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 /*************************** -*- Mod: C++ -*- ******************************
00025 
00026    TestHeaderTokenizer.cc --
00027    Created On      : Mon Jan 20 11:48:10 1997
00028 
00029 
00030  ****************************************************************************/
00031 #include "HttpHeaderTokenizer.h"
00032 #include "ink_assert.h"
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <errno.h>
00036 #include <ctype.h>
00037 #include <memory.h>
00038 #include <assert.h>
00039 #include <string.h>
00040 #include <strings.h>
00041 #include <unistd.h>
00042 #include <stdarg.h>
00043 #include <libgen.h>
00044 #include <limits.h>
00045 #include <fcntl.h>
00046 #include <time.h>
00047 #include <sys/param.h>
00048 #include <sys/stat.h>
00049 
00050 static void
00051 add_field(HttpHeader * h, const char *name, const char *value)
00052 {
00053   h->m_header_fields.set_raw_header_field(name, value);
00054 }
00055 
00056 /////////////////////////////////////////////////////////////
00057 //
00058 //  test_add_fields()
00059 //
00060 /////////////////////////////////////////////////////////////
00061 static void
00062 test_add_fields(HttpHeader * h)
00063 {
00064   char long_accept_header[2048];
00065   memset(long_accept_header, 'B', sizeof(long_accept_header));
00066   long_accept_header[sizeof(long_accept_header) - 1] = '\0';
00067   add_field(h, "Accept", long_accept_header);
00068   add_field(h, "Accept", "image/gif");
00069   add_field(h, "Accept", "image/x-xbitmap");
00070   add_field(h, "Accept", "image/jpeg");
00071   add_field(h, "Accept", "image/pjpeg");
00072   add_field(h, "Accept", "*/*");
00073   add_field(h, "Set-Cookie", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
00074   add_field(h, "Set-Cookie", "1234567890987654321");
00075   return;
00076 }
00077 
00078 /////////////////////////////////////////////////////////////
00079 //
00080 //  test_hacked_http_header_field()
00081 //
00082 /////////////////////////////////////////////////////////////
00083 static void
00084 test_hacked_http_header_field()
00085 {
00086   HttpHackedMultiValueRawHeaderField f;
00087 
00088 #define ADD_FIELD(s) f.add(s, sizeof(s))
00089   ADD_FIELD("image/gif");
00090   ADD_FIELD("image/x-xbitmap");
00091   ADD_FIELD("image/jpeg");
00092   ADD_FIELD("image/pjpeg");
00093   ADD_FIELD("*/*");
00094 #undef ADD_FIELD
00095 
00096   int count = f.get_count();
00097   cout << "count = " << count << endl;
00098   int length = 0;
00099   for (int i = 0; i < count; i++) {
00100     cout << "Accept: " << f.get(i, &length) << endl;
00101     cout << "(length = " << length << ")" << endl;
00102   }
00103   return;
00104 }
00105 
00106 /////////////////////////////////////////////////////////////
00107 //
00108 //  test_url_parse()
00109 //
00110 /////////////////////////////////////////////////////////////
00111 void
00112 test_url_parse(const char *url_string)
00113 {
00114   URL url(url_string, strlen(url_string));
00115   char buf[4096];
00116 
00117   url.dump(buf, sizeof(buf));
00118 
00119   cout << buf << endl;
00120 
00121   return;
00122 }
00123 
00124 /////////////////////////////////////////////////////////////
00125 //
00126 //  test_url()
00127 //
00128 /////////////////////////////////////////////////////////////
00129 void
00130 test_url()
00131 {
00132   test_url_parse("http://charm.example.com  ");
00133   test_url_parse
00134     ("http://webchat16.wbs.net:6666?private=herbalessences&color=4&volume=0&tagline=&picture=&home_page=hi@there.&ignore=edheldinruth+taz0069+speezman&back=&Room=Hot_Tub&handle=cagou67&mu=893e159ef7fe0ddb022c655cc1c30abd33d4ae6d90d22f8a&last_read_para=&npo=&fsection=input&chatmode=push&reqtype=input&InputText=Sweetie%2C+do+you+have+time+to+go+to+a+private+room..if+not+I%27m+just+going+to+have+to+change+to+normal+mode...let+me+know%3F%3F/");
00135 
00136   return;
00137 }
00138 
00139 /////////////////////////////////////////////////////////////
00140 //
00141 //  test_header_tokenizer()
00142 //
00143 // message_type HTTP_MESSAGE_TYPE_REQUEST or HTTP_MESSAGE_TYPE_RESPONSE
00144 /////////////////////////////////////////////////////////////
00145 void
00146 test_header_tokenizer_run(const char *buf, HttpMessageType_t message_type)
00147 {
00148   HttpHeaderTokenizer tokenizer;
00149   HttpHeader header;
00150   int bytes_used;
00151 
00152   tokenizer.start(&header, message_type, false);
00153 
00154   tokenizer.run(buf, strlen(buf), true, &bytes_used);
00155 
00156   cout << header << endl;
00157 
00158   return;
00159 }
00160 
00161 void
00162 test_header_tokenizer()
00163 {
00164   test_header_tokenizer_run
00165     ("GET http://webchat16.wbs.net:6666?private=herbalessences&color=4&volume=0&tagline=&picture=&home_page=hi@there.&ignore=edheldinruth+taz0069+speezman&back=&Room=Hot_Tub&handle=cagou67&mu=893e159ef7fe0ddb022c655cc1c30abd33d4ae6d90d22f8a&last_read_para=&npo=&fsection=input&chatmode=push&reqtype=input&InputText=Sweetie%2C+do+you+have+time+to+go+to+a+private+room..if+not+I%27m+just+going+to+have+to+change+to+normal+mode...let+me+know%3F%3F/ HTTP/1.0\r\n",
00166      HTTP_MESSAGE_TYPE_REQUEST);
00167 
00168   return;
00169 }
00170 
00171 /////////////////////////////////////////////////////////////
00172 //
00173 //  TestHttpHeader()
00174 //
00175 /////////////////////////////////////////////////////////////
00176 void
00177 TestHttpHeader()
00178 {
00179   HttpHeader h;
00180   h.m_message_type = HTTP_MESSAGE_TYPE_REQUEST;
00181   h.m_method = HTTP_METHOD_GET;
00182   h.m_version = HttpVersion(1, 0);
00183 
00184   test_add_fields(&h);
00185 
00186   cout << h << endl;
00187 
00188   cout << "concatenated accept" << endl;
00189   char accept_buf[4000];
00190   h.m_header_fields.get_comma_separated_accept_value(accept_buf, sizeof(accept_buf));
00191   cout << accept_buf << endl;
00192 
00193   int l;
00194   cout << "first accept" << endl;
00195   cout << h.m_header_fields.m_accept.get(0, &l) << endl;
00196 
00197 
00198   char buf[4096];
00199   int marshal_length = h.marshal(buf, sizeof(buf));
00200 
00201   HttpHeader h1;
00202   h1.unmarshal(buf, marshal_length);
00203 
00204   cout << "unmarshalled: " << endl;
00205   cout << h1 << endl;
00206 
00207   cout << "test url parser:" << endl;
00208   test_url();
00209 
00210   cout << "test_header_tokenizer:" << endl;
00211   test_header_tokenizer();
00212 
00213   return;
00214 }

Generated by  doxygen 1.7.1