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 #if !defined (_HttpTransactHeaders_h_)
00025 #define _HttpTransactHeaders_h_
00026 
00027 #define ink_time_t time_t
00028 
00029 extern int nstrhex(char *d, unsigned int i);
00030 
00031 class HttpTransactHeaders
00032 {
00033 public:
00034   static bool is_this_http_method_supported(int method);
00035   static bool is_method_cacheable(const HttpConfigParams *http_config_param, const int method);
00036   static bool is_method_cache_lookupable(int method);
00037   static bool is_this_a_hop_by_hop_header(const char *field_name_wks);
00038   static bool is_this_method_supported(int the_scheme, int the_method);
00039 
00040   static void insert_supported_methods_in_response(HTTPHdr * response, int the_scheme);
00041 
00042   static void build_base_response(HTTPHdr * outgoing_response, HTTPStatus status,
00043                                   const char *reason_phrase, int reason_phrase_len, ink_time_t date);
00044 
00045   static void copy_header_fields(HTTPHdr * src_hdr, HTTPHdr * new_hdr,
00046                                  bool retain_proxy_auth_hdrs, ink_time_t date = 0);
00047 
00048   static void convert_request(HTTPVersion outgoing_ver, HTTPHdr * outgoing_request);
00049   static void convert_response(HTTPVersion outgoing_ver, HTTPHdr * outgoing_response);
00050   static void convert_to_0_9_request_header(HTTPHdr * outgoing_request);
00051   static void convert_to_1_0_request_header(HTTPHdr * outgoing_request);
00052   static void convert_to_1_1_request_header(HTTPHdr * outgoing_request);
00053   static void convert_to_0_9_response_header(HTTPHdr * outgoing_response);
00054   static void convert_to_1_0_response_header(HTTPHdr * outgoing_response);
00055   static void convert_to_1_1_response_header(HTTPHdr * outgoing_response);
00056 
00057   static ink_time_t calculate_document_age(ink_time_t request_time, ink_time_t response_time,
00058                                            HTTPHdr * base_response, ink_time_t base_response_date, ink_time_t now);
00059   static bool does_server_allow_response_to_be_stored(HTTPHdr * resp);
00060   static bool downgrade_request(bool * origin_server_keep_alive, HTTPHdr * outgoing_request);
00061 
00062   static void generate_and_set_squid_codes(HTTPHdr * header, char *via_string,
00063                                           HttpTransact::SquidLogInfo * squid_codes);
00064 
00065   
00066   
00067   
00068   
00069   static void insert_warning_header(HttpConfigParams *http_config_param,
00070                                     HTTPHdr *header, HTTPWarningCode code,
00071                                     const char *warn_text = NULL, int warn_text_len = 0);
00072   static void insert_time_and_age_headers_in_response(ink_time_t request_sent_time,
00073                                                       ink_time_t response_received_time,
00074                                                       ink_time_t now, HTTPHdr * base, HTTPHdr * outgoing);
00075   static void insert_server_header_in_response(const char *server_tag, int server_tag_size, HTTPHdr * header);
00076   static void insert_via_header_in_request(HttpTransact::State *s, HTTPHdr *header);
00077   static void insert_via_header_in_response(HttpTransact::State *s, HTTPHdr *header);
00078   static void insert_hsts_header_in_response(HttpTransact::State *s, HTTPHdr *header);
00079 
00080   static bool is_request_proxy_authorized(HTTPHdr * incoming_hdr);
00081 
00082   static void insert_basic_realm_in_proxy_authenticate(const char *realm, HTTPHdr * header, bool bRevPrxy);
00083 
00084   static void remove_conditional_headers(HTTPHdr * outgoing);
00085   static void remove_100_continue_headers(HttpTransact::State *s, HTTPHdr * outgoing);
00086   static void remove_host_name_from_url(HTTPHdr * outgoing_request);
00087   static void add_global_user_agent_header_to_request(OverridableHttpConfigParams *http_txn_conf, HTTPHdr * header);
00088   static void add_server_header_to_response(OverridableHttpConfigParams *http_txn_conf, HTTPHdr * header);
00089   static void remove_privacy_headers_from_request(HttpConfigParams *http_config_param,
00090                                                   OverridableHttpConfigParams *http_txn_conf, HTTPHdr * header);
00091 
00092   static int nstrcpy(char *d, const char *as);
00093 };
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 inline bool
00104 HttpTransactHeaders::is_this_http_method_supported(int method)
00105 {
00106   return ((method == HTTP_WKSIDX_GET) ||
00107           (method == HTTP_WKSIDX_POST) ||
00108           (method == HTTP_WKSIDX_CONNECT) ||
00109           (method == HTTP_WKSIDX_DELETE) ||
00110           (method == HTTP_WKSIDX_PURGE) ||
00111           (method == HTTP_WKSIDX_HEAD) ||
00112           (method == HTTP_WKSIDX_OPTIONS) ||
00113           (method == HTTP_WKSIDX_PUT) || (method == HTTP_WKSIDX_PUSH) || (method == HTTP_WKSIDX_TRACE));
00114 }
00115 
00116 inline int
00117 HttpTransactHeaders::nstrcpy(char *d, const char *as)
00118 {
00119   const char *s = as;
00120   while (*s)
00121     *d++ = *s++;
00122   return s - as;
00123 }
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 inline bool
00136 HttpTransactHeaders::is_request_proxy_authorized(HTTPHdr * incoming_hdr)
00137 {
00138   ink_assert(incoming_hdr);
00139   
00140   return true;
00141 }
00142 
00143 #endif