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

testheaders.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 "ink_string.h"    
00025 #include "HttpTransact.h"
00026 #include "HttpTransactHeaders.h"
00027 
00028 #define MAX_FIELD_VALUE_SIZE 512
00029 
00030 char request1[] =
00031   "GET http://people.netscape.com/jwz/hacks-1.gif HTTP/1.0\r\n"
00032   "If-Modified-Since: Wednesday, 26-Feb-97 06:58:17 GMT; length=842\r\n"
00033   "Referer: http://people.netscape.com/jwz/index.html\r\n"
00034   "Proxy-Connection: Referer, User-Agent\r\n"
00035   "Vary: If-Modified-Since, Host, Accept, Proxy-Connection, Crap\r\n"
00036   "User-Agent:  Mozilla/3.01 (X11; I; Linux 2.0.28 i586)\r\n"
00037   "Crappy-Field: value1-on-line-1, value2-on-line-1\r\n"
00038   "Crappy-Field: value-on-line-2\r\n"
00039   "Blowme: Crapshoot\r\n"
00040   "Pragma: no-cache\r\n"
00041   "Host: people.netscape.com\r\n" "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\r\n\r\n";
00042 
00043 char response1[] =
00044   "HTTP/1.0 200 !132d63600000000000000200 OK\r\n"
00045   "Server: WN/1.14.6\r\n"
00046   "Date: Tue, 26 Aug 1997 21:51:23 GMT\r\n"
00047   "Last-modified: Fri, 25 Jul 1997 15:07:05 GMT\r\n"
00048   "Content-type: text/html\r\n"
00049   "Content-length: 3831\r\n" "Accept-Range: bytes, lines\r\n" "Title: General Casualty - Home Page\r\n";
00050 
00051 char response2[] =
00052   "HTTP/1.0 304 Not Modified\r\n"
00053   "Date: Wed, 30 Jul 1997 22:31:20 GMT\r\n"
00054   "Via: 1.0 trafficserver.apache.org (Traffic-Server/1.0b [ONM])\r\n" "Server: Apache/1.1.1\r\n\r\n";
00055 
00056 void print_header(HttpHeader * header);
00057 
00058 void
00059 readin_header(HttpHeader * new_header, char *req_buffer, int length)
00060 {
00061   int bytes_used = 0;
00062 
00063   const char *tmp = req_buffer;
00064   while (*tmp) {
00065     if (new_header->parse(tmp, length, &bytes_used, false, HTTP_MESSAGE_TYPE_REQUEST) != 0)
00066       break;
00067     tmp += length;
00068   }
00069 }
00070 
00071 // void print_header(HttpHeader *header)
00072 // {
00073 //     bool done = false;
00074 //     int bytes_used = 0;
00075 //     char dumpbuf;
00076 
00077 //     header->dump_setup ();
00078 //     while (!done) {
00079 //      header->dump (&dumpbuf, 1, &bytes_used, &done);
00080 //      putc (dumpbuf, stdout);
00081 //     }
00082 // }
00083 
00084 inline void
00085 make_comma_separated_header_field_value(HttpHeader * header, const char *fieldname, char *full_str)
00086 {
00087   MIMEHeaderFieldValue *hfv;
00088   const char *str;
00089 
00090   hfv = header->mime().get(fieldname, strlen(fieldname));
00091 
00092   /* This if is needed to put in the commas correctly */
00093   if (hfv) {
00094     str = hfv->get_raw();
00095     ink_strlcat(full_str, str, MAX_FIELD_VALUE_SIZE);
00096     hfv = hfv->next();
00097   }
00098   while (hfv) {
00099     str = hfv->get_raw();
00100     ink_strlcat(full_str, ", ", MAX_FIELD_VALUE_SIZE);
00101     ink_strlcat(full_str, str, MAX_FIELD_VALUE_SIZE);
00102     hfv = hfv->next();
00103   }
00104 }
00105 
00106 void
00107 test_headers()
00108 {
00109   HttpHeader *req;
00110   char str1[MAX_FIELD_VALUE_SIZE];
00111   char str2[MAX_FIELD_VALUE_SIZE];
00112   char str3[MAX_FIELD_VALUE_SIZE];
00113 
00114   req = new(HttpHeaderAllocator.alloc())HttpHeader();
00115 
00116   readin_header(req, request1, sizeof(request1));
00117   printf("[test_headers] This is the header that was read in:\n");
00118   print_header(req);
00119 
00120   printf("[test_headers] Ok, let us see what the Proxy-Connection field is ...\n");
00121   printf("[test_headers] the value of Blowme is %s\n", req->mime().get_raw("Blowme", strlen("Blowme")));
00122 //     make_comma_separated_header_field_value(req, "Proxy-Connection", str1);
00123 //     printf("[test_headers] Proxy-Connection is %s\n", str1);
00124 
00125 //     printf("[test_headers] Let us try that with crappy-field...\n");
00126 //     make_comma_separated_header_field_value(req, "Crappy-Field", str2);
00127 //     printf("[test_headers] Crappy-Field is : %s\n", str2);
00128 
00129 //     printf("[test_headers] Let us try that with Vary, now...\n");
00130 //     make_comma_separated_header_field_value(req, "Vary", str3);
00131 //     printf("[test_headers] Vary is %s\n", str3);
00132 }

Generated by  doxygen 1.7.1