LibItsHttp_Functions.ttcn 5.4 KB
Newer Older
garciay's avatar
garciay committed
1
2
module LibItsHttp_Functions {
    
Yann Garcia's avatar
Yann Garcia committed
3
4
5
6
7
    // LibCommon
    import from LibCommon_Time all;
    import from LibCommon_VerdictControl all;
    import from LibCommon_Sync all;
    
garciay's avatar
garciay committed
8
9
10
    // LibHttp
    import from LibItsHttp_TypesAndValues all;
    import from LibItsHttp_Pics all;
Yann Garcia's avatar
Yann Garcia committed
11
    import from LibItsHttp_TestSystem all;
garciay's avatar
garciay committed
12
    
Yann Garcia's avatar
Yann Garcia committed
13
14
15
    group http_preambles {
      
      /**
Yann Garcia's avatar
Yann Garcia committed
16
       * @desc    Setups default configuration
Yann Garcia's avatar
Yann Garcia committed
17
       * @param   p_certificate_id The certificate identifier the TA shall use in case of secured IUT
Yann Garcia's avatar
Yann Garcia committed
18
19
       */
      function f_cfUp(
Yann Garcia's avatar
Yann Garcia committed
20
                      in charstring p_certificate_id
Yann Garcia's avatar
Yann Garcia committed
21
22
23
24
25
26
27
28
      ) 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
29
    
Yann Garcia's avatar
Yann Garcia committed
30
31
32
33
34
35
    group http_postambles {
      
      /**
       * @desc    Deletes default configuration 
       */
      function f_cfDown() runs on HttpComponent /* TITAN TODO: system HttpTestAdapter */ {
garciay's avatar
garciay committed
36
          
Yann Garcia's avatar
Yann Garcia committed
37
38
39
40
41
42
43
44
45
46
          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(
47
48
                                           in charstring p_header_content_type := PICS_HEADER_CONTENT_TYPE,
                                           in charstring p_header_content_text := "",
Yann Garcia's avatar
Yann Garcia committed
49
50
                                           out HeaderLines p_headers
      ) {
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
        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
68
69
        v_i := v_i + 1;
        p_headers[v_i] := { c_header_authorization, { "Basic YWxhZGRpbjpvcGVuc2VzYW1l" } };
Yann Garcia's avatar
Yann Garcia committed
70
71
        //v_i := v_i + 1;
        //p_headers[v_i] := { c_header_accept, { "application/x-its-response" } };
Yann Garcia's avatar
Yann Garcia committed
72
73
      } // End of function f_init_default_headers_list
      
Yann Garcia's avatar
Yann Garcia committed
74
75
76
77
78
      function f_set_headers_list(
                                  in charstring_list p_headers_to_set,
                                  in charstring_list p_headers_value,
                                  inout HeaderLines p_headers
                                  ) {
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        // 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
98
      } // End of function f_set_headers_list
99
      
Yann Garcia's avatar
Yann Garcia committed
100
101
102
103
      function f_remove_headers_list(
                                     in charstring_list p_headers_to_remove,
                                     inout HeaderLines p_headers
                                     ) {
104
105
106
107
108
109
110
111
112
113
114
115
116
        // 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
117
          } // End of 'for' statement
118
        } // End of 'for' statement
Yann Garcia's avatar
Yann Garcia committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
      } // 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
140
141
142
      
    } // End of group http_headers
    
garciay's avatar
garciay committed
143
} // End of module LibItsHttp_Functions