Skip to content
LibItsHttp_Functions.ttcn 5.46 KiB
Newer Older
garciay's avatar
garciay committed
module LibItsHttp_Functions {
    
Yann Garcia's avatar
Yann Garcia committed
    // LibCommon
    import from LibCommon_Time all;
    import from LibCommon_VerdictControl all;
    import from LibCommon_Sync all;
    
garciay's avatar
garciay committed
    // LibHttp
    import from LibItsHttp_TypesAndValues all;
    import from LibItsHttp_Pics all;
Yann Garcia's avatar
Yann Garcia committed
    import from LibItsHttp_TestSystem all;
garciay's avatar
garciay committed
    
Yann Garcia's avatar
Yann Garcia committed
    group http_preambles {
      
      /**
Yann Garcia's avatar
Yann Garcia committed
       * @desc    Setups default configuration
       * @param   p_certificate_id The certificate identifier the TA shall use in case of secured IUT
Yann Garcia's avatar
Yann Garcia committed
       */
      function f_cfUp(
                      in charstring p_certificate_id
Yann Garcia's avatar
Yann Garcia committed
      ) runs on HttpComponent /* TITAN TODO: system HttpTestAdapter */ {
          
          map(self:httpPort, system:httpPort);
          f_connect4SelfOrClientSync();
          
      } // End of function f_cfUp
      
    } // End of group http_preambles 
garciay's avatar
garciay committed
    
Yann Garcia's avatar
Yann Garcia committed
    group http_postambles {
      
      /**
       * @desc    Deletes default configuration 
       */
      function f_cfDown() runs on HttpComponent /* TITAN TODO: system HttpTestAdapter */ {
garciay's avatar
garciay committed
          
Yann Garcia's avatar
Yann Garcia committed
          unmap(self:httpPort, system:httpPort);
          f_disconnect4SelfOrClientSync();
          
      } // End of function f_cfDown
      
    } // End of group http_postambles 
    
    group http_headers {
      
      function f_init_default_headers_list(
                                           in charstring p_header_content_type := PICS_HEADER_CONTENT_TYPE,
                                           in charstring p_header_content_text := "",
Yann Garcia's avatar
Yann Garcia committed
                                           out HeaderLines p_headers
      ) {
        var integer v_i := 0;
        
        p_headers[v_i] := { c_header_host, { PICS_HEADER_HOST } };
        v_i := v_i + 1;
        p_headers[v_i] := { c_header_content_type, { p_header_content_type } };
        v_i := v_i + 1;
        if (p_header_content_text != "") {
          p_headers[v_i] := { c_header_content_text, { p_header_content_text } };
          v_i := v_i + 1;
        }
        p_headers[v_i] := { c_header_content_length, { "0" } };
        v_i := v_i + 1;
        p_headers[v_i] := { c_header_connection, { "keep-alive" } };
        v_i := v_i + 1;
        p_headers[v_i] := { c_header_pragma, { "no-cache" } };
        v_i := v_i + 1;
        p_headers[v_i] := { c_header_cache_control, { "no-cache" } };
YannGarcia's avatar
YannGarcia committed
        v_i := v_i + 1;
        if (PICS_USE_TOKEN_HEADER) {
          p_headers[v_i] := { c_header_authorization, { PICS_TOKEN_HEADER } }; // aladdin:opensesame
          v_i := v_i + 1;
        }
Yann Garcia's avatar
Yann Garcia committed
        //p_headers[v_i] := { c_header_accept, { "application/x-its-response" } };
Yann Garcia's avatar
Yann Garcia committed
      } // End of function f_init_default_headers_list
      
Yann Garcia's avatar
Yann Garcia committed
      function f_set_headers_list(
                                  in charstring_list p_headers_to_set,
                                  in charstring_list p_headers_value,
                                  inout HeaderLines p_headers
                                  ) {
        // Sanity checks
        if (lengthof(p_headers_to_set) == 0) {
          return;
        } else if (lengthof(p_headers) == 0) {
          return;
        }
        
        for (var integer v_idx := 0; v_idx < lengthof(p_headers_to_set); v_idx := v_idx + 1) {
          var integer v_jdx;
          for (v_jdx := 0; v_jdx < lengthof(p_headers); v_jdx := v_jdx + 1) {
            if (p_headers[v_jdx].header_name == p_headers_to_set[v_idx]) {
              p_headers[v_jdx].header_value := p_headers_value; // NOTE Codec won't encode it
              break;
            }
            if (v_jdx == lengthof(p_headers)) {
              p_headers[v_jdx].header_value := p_headers_value;
            }
          } // End of 'for' statement 
        } // End of 'for' statement
Yann Garcia's avatar
Yann Garcia committed
      } // End of function f_set_headers_list
Yann Garcia's avatar
Yann Garcia committed
      function f_remove_headers_list(
                                     in charstring_list p_headers_to_remove,
                                     inout HeaderLines p_headers
                                     ) {
        // Sanity checks
        if (lengthof(p_headers_to_remove) == 0) {
          return;
        } else if (lengthof(p_headers) == 0) {
          return;
        }
        
        for (var integer v_idx := 0; v_idx < lengthof(p_headers_to_remove); v_idx := v_idx + 1) {
          for (var integer v_jdx := 0; v_jdx < lengthof(p_headers); v_jdx := v_jdx + 1) {
            if (p_headers[v_jdx].header_name == p_headers_to_remove[v_idx]) {
              p_headers[v_jdx].header_value := omit; // NOTE Codec won't encode it
              break;
            }
Yann Garcia's avatar
Yann Garcia committed
          } // End of 'for' statement
        } // End of 'for' statement
Yann Garcia's avatar
Yann Garcia committed
      } // End of function f_remove_headers_list
      
      function f_get_header(
                            in HeaderLines p_headers,
                            in charstring p_header_name := c_header_content_text,
                            out charstring_list p_header_value
                                      ) {
        // Sanity checks
        if (lengthof(p_header_name) == 0) {
          return;
        } else if (lengthof(p_headers) == 0) {
          return;
        }
        
        for (var integer v_jdx := 0; v_jdx < lengthof(p_headers); v_jdx := v_jdx + 1) {
          if (p_headers[v_jdx].header_name == p_header_name) {
            p_header_value := p_headers[v_jdx].header_value; // NOTE Codec won't encode it
            break;
          }
        } // End of 'for' statement
      } // End of function f_get_header
Yann Garcia's avatar
Yann Garcia committed
      
    } // End of group http_headers
    
garciay's avatar
garciay committed
} // End of module LibItsHttp_Functions