aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Isom <kyle@tyrfingr.is>2012-05-11 12:49:07 +0300
committerKyle Isom <kyle@tyrfingr.is>2012-05-11 12:49:07 +0300
commitef72b098ebaa474b86fb21440d6eeb0943670c60 (patch)
treeb5f67f1edc1e983de4166d790a67aaa9298a8d2b
parentb4f2c646c38ad675219d417d47ad842c5b6fa9e4 (diff)
downloadsrvwd-ef72b098ebaa474b86fb21440d6eeb0943670c60.tar.gz
srvwd-ef72b098ebaa474b86fb21440d6eeb0943670c60.tar.bz2
srvwd-ef72b098ebaa474b86fb21440d6eeb0943670c60.zip
add srvwd-version to headers
-rw-r--r--response.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/response.c b/response.c
index c31c54a..b97041b 100644
--- a/response.c
+++ b/response.c
@@ -42,7 +42,8 @@ void
send_client_404(int clientfd, request_type rtype)
{
char headerstpl[] = "HTTP/1.1 404 Not Found\r\ncontent-type: text/html\r\n"
- "content-length: %d\r\nconnection: close\r\n\r\n";
+ "content-length: %d\r\nconnection: close\r\n"
+ "srvwd-version: %s\r\n\r\n";
char page404[] = "<!doctype html>\r\n<html>\r\n\t<head>\r\n"
"\t\t<meta charset = \"utf-8\">\r\n"
"\t\t<title>file not found</title>\r\n"
@@ -59,7 +60,7 @@ send_client_404(int clientfd, request_type rtype)
memset(headers, 0, SRVWD_CHUNKSIZE);
pagelen = strlen(page404);
- snprintf(headers, SRVWD_CHUNKSIZE, headerstpl, pagelen);
+ snprintf(headers, SRVWD_CHUNKSIZE, headerstpl, pagelen, srvwd_VERSION);
headerslen = strlen(headers);
write(clientfd, headers, headerslen);
@@ -76,7 +77,8 @@ void
send_client_file(int clientfd, char *filename, request_type rtype)
{
char headerstpl[] = "HTTP/1.1 200 OK\ncontent-type: %s\r\n"
- "content-length: %d\r\nconnection: close\r\n\r\n";
+ "content-length: %d\r\nconnection: close\r\n"
+ "srvwd-version: %s\r\n\r\n";
char buf[SRVWD_CHUNKSIZE + 1];
char content_type[SRVWD_BUFSIZE];
char *extptr;
@@ -111,7 +113,8 @@ send_client_file(int clientfd, char *filename, request_type rtype)
return;
}
- snprintf(buf, SRVWD_CHUNKSIZE, headerstpl, content_type, st.st_size);
+ snprintf(buf, SRVWD_CHUNKSIZE, headerstpl, content_type, st.st_size,
+ srvwd_VERSION);
headerslen = strlen(buf);
filep = fopen(filename, "r");
@@ -158,8 +161,9 @@ send_client_file(int clientfd, char *filename, request_type rtype)
void
send_client_dirlist(int clientfd, char *path, request_type rtype)
{
- char headers[] = "HTTP/1.1 200 OK\r\nconnection: close\r\n"
- "content-type: text/html\r\n\r\n";
+ char headertpl[] = "HTTP/1.1 200 OK\r\nconnection: close\r\n"
+ "content-type: text/html\r\n"
+ "srvwd-version: %s\r\n\r\n";
char headtpl[] = "<!doctype html>\r\n<html>\r\n\t<head>\r\n"
"\t\t<meta charset = \"utf-8\">\r\n"
"\t\t<title>contents of %s</title>\r\n"
@@ -185,11 +189,14 @@ send_client_dirlist(int clientfd, char *path, request_type rtype)
}
memset(buf, 0, SRVWD_CHUNKSIZE + 1);
+ snprintf(buf, SRVWD_CHUNKSIZE, headertpl, srvwd_VERSION);
+ headerslen = strlen(buf);
+ write(clientfd, buf, headerslen);
+
+ memset(buf, 0, SRVWD_CHUNKSIZE + 1);
snprintf(buf, SRVWD_CHUNKSIZE, headtpl, path, path);
- headerslen = strlen(headers);
buflen = strlen(buf);
- write(clientfd, headers, headerslen);
if (HEAD == rtype)
return;