Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sean Flannigan - Sprint-Challenge--C-Web-Server #140

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- https://github.com/LambdaSchool/Sprint-Challenge--C-Web-Server/pull/140 -->
# Sprint Challenge: C Web Server Sprint

This challenge allows you to practice the concepts and techniques learned over
Expand Down
45 changes: 34 additions & 11 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ urlinfo_t *parse_url(char *url)
char *path;

urlinfo_t *urlinfo = malloc(sizeof(urlinfo_t));

/*
We can parse the input URL by doing the following:

Expand All @@ -46,7 +45,21 @@ urlinfo_t *parse_url(char *url)
*/

///////////////////
// IMPLEMENT ME! //
char *fs = strchr(hostname, '/');
if(fs != NULL) {
path = fs + 1;
*fs = '\0';
}

char *fc = strchr(hostname, ':');
if(fc != NULL) {
port = fc + 1;
*fc = '\0';
}
urlinfo->hostname = hostname;
urlinfo->port = port;
urlinfo->path = path;

///////////////////

return urlinfo;
Expand All @@ -69,10 +82,15 @@ int send_request(int fd, char *hostname, char *port, char *path)
int rv;

///////////////////
// IMPLEMENT ME! //
int request_length = snprintf(request, max_request_size, "GET /%s HTTP/1.1\n"
"Host: %s:%s\n"
"Connection: close\n"
"\n", path, hostname, port);

rv = send(fd, request, request_length, 0);
///////////////////

return 0;
return rv;
}

int main(int argc, char *argv[])
Expand All @@ -85,16 +103,21 @@ int main(int argc, char *argv[])
exit(1);
}

urlinfo_t *urlinfo = parse_url(argv[1]);
///////////////////
sockfd = get_socket(urlinfo->hostname, urlinfo->port);
send_request(sockfd, urlinfo->hostname, urlinfo->port, urlinfo->path);
while ((numbytes = recv(sockfd, buf, BUFSIZE - 1, 0)) > 0) {
printf("%s\n\n", buf);
}

/*
1. Parse the input URL
2. Initialize a socket by calling the `get_socket` function from lib.c
3. Call `send_request` to construct the request and send it
4. Call `recv` in a loop until there is no more data to receive from the server. Print the received response to stdout.
// 1. Parse the input URL
// 2. Initialize a socket by calling the `get_socket` function from lib.c
// 3. Call `send_request` to construct the request and send it
// 4. Call `recv` in a loop until there is no more data to receive from the server. Print the received response to stdout.
5. Clean up any allocated memory and open file descriptors.
*/

///////////////////
// IMPLEMENT ME! //
///////////////////

return 0;
Expand Down