Go to the documentation of this file.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 "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
00072
00073
00074
00075
00076
00077
00078
00079
00080
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
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
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 }