toolbox

Check-in [564880f6c2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:http-code: add flag to enable redirects
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 564880f6c28d6e645aa3dbbba7d5903cfadc5d28e38b916a0b43e563fff5967d
User & Date: jef 2019-05-03 07:42:31
Context
2019-05-06
12:10
calc: improve man page documentation check-in: 1d0bf615b7 user: jef tags: trunk
2019-05-03
07:42
http-code: add flag to enable redirects check-in: 564880f6c2 user: jef tags: trunk
2019-05-02
21:38
http-code: fix mixed indentation typo check-in: cf9ec4c414 user: jef tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to doc/http-code.md.

8
9
10
11
12
13
14
15
16
17
18




19
20
21
22
23
24
25
26
27
28
29
30

**http-code**
*url*

## DESCRIPTION

**http-code**
display the HTTP status code for an url (after HTTP redirects).

## OPTIONS





**-t** *int*

> Specify timeout in milliseconds (10000 by default)

## EXAMPLE

	$ http-code https://foutaise.org
	200

## AUTHOR

Gerome Fournier <[jef@foutaise.org](mailto:jef@foutaise.org)>.







|



>
>
>
>


|









8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

**http-code**
*url*

## DESCRIPTION

**http-code**
display the HTTP status code for an url.

## OPTIONS

**-r**

> Follow redirects (off by default)

**-t** *int*

> Timeout in milliseconds (off by default)

## EXAMPLE

	$ http-code https://foutaise.org
	200

## AUTHOR

Gerome Fournier <[jef@foutaise.org](mailto:jef@foutaise.org)>.

Changes to src/http-code/http-code.1.

5
6
7
8
9
10
11
12
13
14


15
16
17
18
19
20
21
22
23
24
.Nm http-code
.Nd Display HTTP status code for an url
.Sh SYNOPSIS
.Nm
.Ar url
.Sh DESCRIPTION
.Nm
display the HTTP status code for an url (after HTTP redirects).
.Sh OPTIONS
.Bl -tag -width indent


.It Fl t Ar int
Specify timeout in milliseconds (10000 by default)
.El
.Sh EXAMPLE
.Bd -literal
$ http-code https://foutaise.org
200
.Ed
.Sh AUTHOR
.An Gerome Fournier Aq Mt jef@foutaise.org .







|


>
>

|








5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
.Nm http-code
.Nd Display HTTP status code for an url
.Sh SYNOPSIS
.Nm
.Ar url
.Sh DESCRIPTION
.Nm
display the HTTP status code for an url.
.Sh OPTIONS
.Bl -tag -width indent
.It Fl r
Follow redirects (off by default)
.It Fl t Ar int
Timeout in milliseconds (off by default)
.El
.Sh EXAMPLE
.Bd -literal
$ http-code https://foutaise.org
200
.Ed
.Sh AUTHOR
.An Gerome Fournier Aq Mt jef@foutaise.org .

Changes to src/http-code/http-code.c.

15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
..
55
56
57
58
59
60
61


62
63
64
65
66
67
68
69



70
71
72
73
74
75
76
..
81
82
83
84
85
86
87


88

89
90
91



92
93
94
{
	fprintf(stderr,
		"Display HTTP status code for an url\n"
		"Usage:\n"
		"	%s url\n"
		"Options:\n"
		"	-h           : display this help and exit\n"

		"	-t <timeout> : timeout in milliseconds (10000 by default)\n", PROGNAME);
	exit(1);
}

long
parse_timeout(char *str)
{
	long value;
................................................................................
	exit(0);
}

int
main(int argc, char *argv[])
{
	CURL *curl;


	long timeout = 10000;
	int ch;

	while ((ch = getopt(argc, argv, "ht:")) != -1) {
		switch (ch) {
		case 'h':
			usage();
			break;



		case 't':
			timeout = parse_timeout(optarg);
			break;
		}

	}
	argc -= optind;
................................................................................

	curl = curl_easy_init();
	if (curl == NULL)
		die("unable to initialize curl");
	curl_easy_setopt(curl, CURLOPT_URL, argv[0]);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl);


	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

	curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, timeout);
	curl_easy_setopt(curl, CURLOPT_USERAGENT, "Curl");
	curl_easy_perform(curl);




	return EXIT_SUCCESS;
}







>
|







 







>
>
|


|




>
>
>







 







>
>
|
>
|
<
|
>
>
>



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
..
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
..
87
88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
{
	fprintf(stderr,
		"Display HTTP status code for an url\n"
		"Usage:\n"
		"	%s url\n"
		"Options:\n"
		"	-h           : display this help and exit\n"
		"	-r           : follow redirect (off by default)\n"
		"	-t <timeout> : timeout in milliseconds (off by default)\n", PROGNAME);
	exit(1);
}

long
parse_timeout(char *str)
{
	long value;
................................................................................
	exit(0);
}

int
main(int argc, char *argv[])
{
	CURL *curl;
	CURLcode res;
	int redirect = 0;
	long timeout = 0;
	int ch;

	while ((ch = getopt(argc, argv, "hrt:")) != -1) {
		switch (ch) {
		case 'h':
			usage();
			break;
		case 'r':
			redirect = 1;
			break;
		case 't':
			timeout = parse_timeout(optarg);
			break;
		}

	}
	argc -= optind;
................................................................................

	curl = curl_easy_init();
	if (curl == NULL)
		die("unable to initialize curl");
	curl_easy_setopt(curl, CURLOPT_URL, argv[0]);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl);
	curl_easy_setopt(curl, CURLOPT_USERAGENT, "Curl");
	if (redirect)
		curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
	if (timeout > 0)
		curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, timeout);

	res = curl_easy_perform(curl);
	if (res != CURLE_OK)
		die("'%s': %s", argv[0], curl_easy_strerror(res));
	curl_easy_cleanup(curl);

	return EXIT_SUCCESS;
}