Skip to content

Commit fc30c99

Browse files
authored
Add: support for HTTP/2 (#1610)
* Add: support for HTTP/2 See NASL manual documentation. Jira: SC-1038 `openvas-nasl -X -t example.com http2.nasl` ``` h = http2_handle(); display(h); r = http2_get(handle:h, port:443, item:"/", schema:"https"); display("response: ", r); rc = http2_get_response_code(handle:h); display("return code: ", rc); http2_close_handle(h); h = http2_handle(); display(h); r = http2_get(handle:h, port:3000, item:"/vts", schema:"http"); display("response: ", r); rc = http2_get_response_code(handle:h); display("return code: ", rc); http2_close_handle(h); ``` * nasl/nasl_http2.c * small fix reported by clippy non related to this PR's topic * fix typos
1 parent 6addc38 commit fc30c99

File tree

17 files changed

+943
-3
lines changed

17 files changed

+943
-3
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# http2_close_handle
2+
3+
## NAME
4+
5+
**http2_close_handle** - Close a handle for http requests previously initialized.
6+
7+
## SYNOPSIS
8+
9+
*void* **http_close_handle**(handle: *int*);
10+
11+
**http_close_handle** takes one argument.
12+
13+
## DESCRIPTION
14+
Close a handle for http requests previously initialized.
15+
16+
## RETURN VALUE
17+
It returns an integer or NULL on error.
18+
19+
## EXAMPLES
20+
21+
**1** Close the handle identifier
22+
```cpp
23+
h = http2_handle();
24+
display(h);
25+
http2_close_handle(h);
26+
```
27+
28+
## SEE ALSO
29+
30+
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# http2_delete
2+
3+
## NAME
4+
5+
**http2_delete** - performs an HTTP2 DELETE request for the server on the port.
6+
7+
## SYNOPSIS
8+
9+
*void* **http_delete**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);
10+
11+
**http_delete** takes five named arguments.
12+
13+
## DESCRIPTION
14+
Performs an HTTP2 DELETE request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.
15+
16+
If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
17+
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).
18+
19+
## RETURN VALUE
20+
It returns a string (the http response). Null on error
21+
22+
## EXAMPLES
23+
24+
**1** Delete and display the formatted delete request:
25+
```cpp
26+
h = http2_handle();
27+
display(h);
28+
29+
r = http2_delete(handle:h, port:3000, item:"/vts", schema:"http");
30+
display("response: ", r);
31+
rc = http2_get_response_code(handle:h);
32+
display("return code: ", rc);
33+
```
34+
35+
## SEE ALSO
36+
37+
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# http2_get
2+
3+
## NAME
4+
5+
**http2_get** - performs an HTTP2 GET request for the server on the port.
6+
7+
## SYNOPSIS
8+
9+
*void* **http_get**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);
10+
11+
**http_get** takes five named arguments.
12+
13+
## DESCRIPTION
14+
Performs an HTTP2 GET request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.
15+
16+
If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
17+
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).
18+
19+
## RETURN VALUE
20+
It returns a string (the http response). Null on error
21+
22+
## EXAMPLES
23+
24+
**1** Get and display the formatted get request:
25+
```cpp
26+
h = http2_handle();
27+
display(h);
28+
29+
r = http2_get(handle:h, port:3000, item:"/vts", schema:"http");
30+
display("response: ", r);
31+
rc = http2_get_response_code(handle:h);
32+
display("return code: ", rc);
33+
```
34+
35+
## SEE ALSO
36+
37+
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# http2_get_response_code
2+
3+
## NAME
4+
5+
**http2_get_response_code** - Gets the response code
6+
7+
## SYNOPSIS
8+
9+
*void* **http2_get_response_code**(handle: *int*);
10+
11+
**http_get** takes one argument.
12+
13+
## DESCRIPTION
14+
After performing a request, is possible to get the response code calling this function and giving the handle identifier.
15+
16+
## RETURN VALUE
17+
It returns an intenger with the response code. Null on error
18+
19+
## EXAMPLES
20+
21+
**1** Get and display the response code:
22+
```cpp
23+
h = http2_handle();
24+
display(h);
25+
26+
r = http2_get(handle:h, port:3000, item:"/vts", schema:"http");
27+
display("response: ", r);
28+
rc = http2_get_response_code(handle:h);
29+
display("return code: ", rc);
30+
```
31+
32+
## SEE ALSO
33+
34+
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# http2_handle
2+
3+
## NAME
4+
5+
**http2_handle** - Creates a handle for http requests.
6+
7+
## SYNOPSIS
8+
9+
*void* **http_handle**();
10+
11+
**http_handle** takes no argument.
12+
13+
## DESCRIPTION
14+
Initialize a handle for performing http requests.
15+
16+
## RETURN VALUE
17+
It returns an integer or NULL on error.
18+
19+
## EXAMPLES
20+
21+
**1** Get the handle identifier
22+
```cpp
23+
h = http2_handle();
24+
display(h);
25+
```
26+
27+
## SEE ALSO
28+
29+
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# http2_head
2+
3+
## NAME
4+
5+
**http2_head** - performs an HTTP2 HEAD request for the server on the port.
6+
7+
## SYNOPSIS
8+
9+
*void* **http_head**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);
10+
11+
**http_head** takes five named arguments.
12+
13+
## DESCRIPTION
14+
Performs an HTTP2 HEAD request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.
15+
16+
If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
17+
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).
18+
19+
## RETURN VALUE
20+
It returns a string (the http response). Null on error
21+
22+
## EXAMPLES
23+
24+
**1** Get and display the formatted head request:
25+
```cpp
26+
h = http2_handle();
27+
display(h);
28+
29+
r = http2_head(handle:h, port:3000, item:"/", schema:"http");
30+
display("response: ", r);
31+
rc = http2_get_response_code(handle:h);
32+
display("return code: ", rc);
33+
```
34+
35+
## SEE ALSO
36+
37+
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# http2_post
2+
3+
## NAME
4+
5+
**http2_post** - performs an HTTP2 POST request for the server on the port.
6+
7+
## SYNOPSIS
8+
9+
*void* **http_post**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);
10+
11+
**http_post** takes five named arguments.
12+
13+
## DESCRIPTION
14+
Performs an HTTP2 POST request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.
15+
16+
If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
17+
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).
18+
19+
## RETURN VALUE
20+
It returns a string (the http response). Null on error
21+
22+
## EXAMPLES
23+
24+
**1** Get and display the formatted post request:
25+
```cpp
26+
h = http2_handle();
27+
display(h);
28+
29+
r = http2_post(handle:h, port:3000, item:"/scan", schema:"http", data:"bad scan config format");
30+
display("response: ", r);
31+
rc = http2_get_response_code(handle:h);
32+
display("return code: ", rc);
33+
```
34+
35+
## SEE ALSO
36+
37+
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# http2_put
2+
3+
## NAME
4+
5+
**http2_put** - performs an HTTP2 PUT request for the server on the port.
6+
7+
## SYNOPSIS
8+
9+
*void* **http_put**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);
10+
11+
**http_put** takes five named arguments.
12+
13+
## DESCRIPTION
14+
Performs an HTTP2 PUT request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.
15+
16+
If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
17+
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).
18+
19+
## RETURN VALUE
20+
It returns a string (the http response). Null on error
21+
22+
## EXAMPLES
23+
24+
**1** Get and display the formatted put request:
25+
```cpp
26+
h = http2_handle();
27+
display(h);
28+
29+
r = http2_put(handle:h, port:3000, item:"/scan", schema:"http", data:"bad scan config format");
30+
display("response: ", r);
31+
rc = http2_get_response_code(handle:h);
32+
display("return code: ", rc);
33+
```
34+
35+
## SEE ALSO
36+
37+
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# http2_set_custom_header
2+
3+
## NAME
4+
5+
**http2_set_custom_header** - Set a custom header element in the header
6+
7+
## SYNOPSIS
8+
9+
*void* **http_set_custom_header**(handle: *int*, header_item: *string*);
10+
11+
**http_set_custom_header** takes two arguments.
12+
13+
## DESCRIPTION
14+
Adds a new element to initialized handle header.
15+
16+
## RETURN VALUE
17+
It returns an integer or NULL on error.
18+
19+
## EXAMPLES
20+
21+
**1** Set a new element in the header
22+
```cpp
23+
h = http2_handle();
24+
display(h);
25+
http2_set_custom_header(handle: h, handle_item: "Content-Type: application/json");
26+
```
27+
28+
## SEE ALSO
29+
30+
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# HTTP2 Functions
2+
3+
## GENERAL
4+
5+
These functions are mainly used for performing HTTP2 request.
6+
7+
## TABLE OF CONTENT
8+
- **[http2_handle](http2_handle.md)** - Creates a handle for http requests.
9+
- **[http2_close_handle](http2_close_handle.md)** - Close a handle for http requests previously initialized.
10+
- **[http2_get_response_code](http2_get_response_code.md)** - Get the http response code after performing a HTTP request.
11+
- **[http2_set_custom_header](http2_set_custom_header.md)** - Set a custom header element in the header.
12+
- **[http2_delete](http2_delete.md)** - performs an HTTP2 DELETE request for the server on the port.
13+
- **[http2_get](http2_get.md)** - performs an HTTP2 DELETE request for the server on the port.
14+
- **[http2_head](http2_head.md)** - performs an HTTP2 HEAD request for the server on the port.
15+
- **[http2_post](http2_post.md)** - performs an HTTP2 POST request for the server on the port.
16+
- **[http2_put](http2_put.md)** - performs an HTTP2 PUT request for the server on the port.

0 commit comments

Comments
 (0)