2 * "$Id: testhttp.c,v 1.12 2002/01/02 17:58:41 mike Exp $"
4 * HTTP test program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2002 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Main entry.
30 * Include necessary headers...
38 * 'main()' - Main entry.
41 int /* O - Exit status */
42 main(int argc
, /* I - Number of command-line arguments */
43 char *argv
[]) /* I - Command-line arguments */
45 int i
; /* Looping var */
46 http_t
*http
; /* HTTP connection */
47 http_status_t status
; /* Status of GET command */
48 char buffer
[8192]; /* Input buffer */
49 long bytes
; /* Number of bytes read */
50 FILE *out
; /* Output file */
51 char host
[HTTP_MAX_URI
],
53 username
[HTTP_MAX_URI
],
54 resource
[HTTP_MAX_URI
];
57 time_t start
, current
;
64 for (i
= 1; i
< argc
; i
++)
66 if (strcmp(argv
[i
], "-o") == 0)
69 out
= fopen(argv
[i
], "wb");
73 httpSeparate(argv
[i
], method
, username
, host
, &port
, resource
);
75 http
= httpConnect(host
, port
);
81 printf("Requesting file \"%s\"...\n", resource
);
82 httpClearFields(http
);
83 httpSetField(http
, HTTP_FIELD_ACCEPT_LANGUAGE
, "en");
84 httpGet(http
, resource
);
85 while ((status
= httpUpdate(http
)) == HTTP_CONTINUE
);
87 if (status
== HTTP_OK
)
90 printf("GET failed with status %d...\n", status
);
94 length
= atoi(httpGetField(http
, HTTP_FIELD_CONTENT_LENGTH
));
97 while ((bytes
= httpRead(http
, buffer
, sizeof(buffer
))) > 0)
100 fwrite(buffer
, bytes
, 1, out
);
103 current
= time(NULL
);
104 if (current
== start
) current
++;
105 printf("\r%ld/%ld bytes (%ld bytes/sec) ", total
, length
,
106 total
/ (current
- start
));
112 puts("Closing connection to server...");
123 * End of "$Id: testhttp.c,v 1.12 2002/01/02 17:58:41 mike Exp $".