11.6

A.

--- tiny.origin.c	2021-02-25 07:26:33.302592754 +0000
+++ tiny.6.c	2021-02-25 07:26:33.302592754 +0000
@@ -13,6 +13,8 @@
 void clienterror(int fd, char *cause, char *errnum,
     char *shortmsg, char *longmsg);
 
+void echo(int connfd);
+
 int main(int argc, char **argv)
 {
   int listenfd, connfd;
@@ -33,11 +35,24 @@
     Getnameinfo((SA *) &clientaddr, clientlen, hostname, MAXLINE,
         port, MAXLINE, 0);
     printf("Accepted connection from (%s, %s)\n", hostname, port);
-    doit(connfd);                                             //line:netp:tiny:doit
+    echo(connfd);
     Close(connfd);                                            //line:netp:tiny:close
   }
 }
 
+void echo(int connfd) {
+  size_t n;
+  char buf[MAXLINE];
+  rio_t rio;
+
+  Rio_readinitb(&rio, connfd);
+  while ((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0) {
+    if (strcmp(buf, "\r\n") == 0)
+      break;
+    Rio_writen(connfd, buf, n);
+  }
+}
+
 /*
  * doit - handle one HTTP request/response transaction
  */

B.

./tiny.6 5000 run server and firefox visit localhost:5000

GET / HTTP/1.1
Host: localhost:5000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

C.

HTTP 1.1

D.

visit rfc section 14 Header Field Definitions

Accept: 14.1

The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used to indicate that the request is specifically limited to a small set of desired types, as in the case of a request for an in-line image.

Accept-Encoding: 14.3

The Accept-Encoding request-header field is similar to Accept, but restricts the content-codings that are acceptable in the response.

Accept-Language: 14.4

The Accept-Language request-header field is similar to Accept, but restricts the set of natural languages that are preferred as a response to the request. Language tags are defined in section 3.10.

Connection: 14.10

The Connection general-header field allows the sender to specify options that are desired for that particular connection and MUST NOT be communicated by proxies over further connections.

Host: 14.23

The Host request-header field specifies the Internet host and port number of the resource being requested, as obtained from the original URI given by the user or referring resource. The Host field value MUST represent the naming authority of the origin server or gateway given by the original URL. This allows the origin server or gateway to differentiate between internally-ambiguous URLs, such as the root “/” URL of a server for multiple host names on a single IP address.

User-Agent: 14.43

The User-Agent request-header field contains information about the user agent originating the request. This is for statistical purposes, the tracing of protocol violations, and automated recognition of user agents for the sake of tailoring responses to avoid particular user agent limitations. User agents SHOULD include this field with requests. The field can contain multiple product tokens (section 3.8) and comments identifying the agent and any subproducts which form a significant part of the user agent. By convention, the product tokens are listed in order of their significance for identifying the application.

comments powered by Disqus