mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
test some primitives from http.c
svn:r739
This commit is contained in:
parent
9485ff9a66
commit
72a3902e5c
11
evhttp.h
11
evhttp.h
@ -362,6 +362,17 @@ void evhttp_parse_query(const char *uri, struct evkeyvalq *);
|
||||
*/
|
||||
char *evhttp_htmlescape(const char *html);
|
||||
|
||||
/**
|
||||
* Separate the host, port and path component from a URL.
|
||||
*
|
||||
* @param url the url for which to separate the components
|
||||
* @param phost pointer in which to store the pointer to the host
|
||||
* @param pport pointer in which to store the port number
|
||||
* @param pfile pointer in which to store the pointer to the path
|
||||
* @return 0 on success and -1 on failure
|
||||
*/
|
||||
int evhttp_hostportfile(char *url, char **phost, u_short *pport, char **pfile);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
2
http.c
2
http.c
@ -465,7 +465,7 @@ evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req)
|
||||
}
|
||||
}
|
||||
|
||||
/* Separated host, port and file from URI */
|
||||
/* Separate host, port and file from URI */
|
||||
|
||||
int
|
||||
evhttp_hostportfile(char *url, char **phost, u_short *pport, char **pfile)
|
||||
|
@ -1384,9 +1384,56 @@ http_connection_retry(void)
|
||||
fprintf(stdout, "OK\n");
|
||||
}
|
||||
|
||||
static void
|
||||
http_primitives(void)
|
||||
{
|
||||
char *escaped;
|
||||
char *host = NULL, *path = NULL;
|
||||
unsigned short port = 0;
|
||||
fprintf(stdout, "Testing HTTP Primitives: ");
|
||||
|
||||
escaped = evhttp_htmlescape("<script>");
|
||||
if (strcmp(escaped, "<script>"))
|
||||
goto failed;
|
||||
free(escaped);
|
||||
|
||||
escaped = evhttp_htmlescape("\"\'&");
|
||||
if (strcmp(escaped, ""'&"))
|
||||
goto failed;
|
||||
free(escaped);
|
||||
|
||||
if (evhttp_hostportfile("fto://some", NULL, NULL, NULL) != -1)
|
||||
goto failed;
|
||||
|
||||
if (evhttp_hostportfile("http://www.foo.com/path.html",
|
||||
&host, &port, &path) == -1)
|
||||
goto failed;
|
||||
|
||||
if (strcmp(host, "www.foo.com") || port != 80 ||
|
||||
strcmp(path, "/path.html"))
|
||||
goto failed;
|
||||
|
||||
if (evhttp_hostportfile("http://foo.com:8080",
|
||||
&host, &port, &path) == -1)
|
||||
goto failed;
|
||||
|
||||
if (strcmp(host, "foo.com") || port != 8080 || strcmp(path, "/"))
|
||||
goto failed;
|
||||
|
||||
fprintf(stdout, "OK\n");
|
||||
|
||||
return;
|
||||
|
||||
failed:
|
||||
fprintf(stdout, "FAILED\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
http_suite(void)
|
||||
{
|
||||
http_primitives();
|
||||
|
||||
http_base_test();
|
||||
http_bad_header_test();
|
||||
http_basic_test();
|
||||
|
Loading…
x
Reference in New Issue
Block a user