/[jscoverage]/trunk/tests/http-server-empty-header-value.c
ViewVC logotype

Diff of /trunk/tests/http-server-empty-header-value.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 438 by siliconforks, Tue Jun 9 04:31:39 2009 UTC revision 610 by siliconforks, Fri Sep 24 20:35:36 2010 UTC
# Line 1  Line 1 
1  /*  /*
2      http-server-empty-header-value.c - HTTP server that outputs a header with an empty value      http-server-empty-header-value.c - HTTP server that outputs a header with an empty value
3      Copyright (C) 2009 siliconforks.com      Copyright (C) 2009, 2010 siliconforks.com
4    
5      This program is free software; you can redistribute it and/or modify      This program is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published by      it under the terms of the GNU General Public License as published by
# Line 24  Line 24 
24    
25  #include "http-server.h"  #include "http-server.h"
26    
27  int main(void) {  int main(int argc, const char ** argv) {
28  #ifdef __MINGW32__  #ifdef __MINGW32__
29    WSADATA data;    WSADATA data;
30    if (WSAStartup(MAKEWORD(1, 1), &data) != 0) {    if (WSAStartup(MAKEWORD(1, 1), &data) != 0) {
# Line 32  Line 32 
32    }    }
33  #endif  #endif
34    
35      assert(argc == 2);
36      uint16_t port = (uint16_t) atoi(argv[1]);
37    
38    SOCKET s = socket(PF_INET, SOCK_STREAM, 0);    SOCKET s = socket(PF_INET, SOCK_STREAM, 0);
39    assert(s != INVALID_SOCKET);    assert(s != INVALID_SOCKET);
40    
# Line 40  Line 43 
43    
44    struct sockaddr_in a;    struct sockaddr_in a;
45    a.sin_family = AF_INET;    a.sin_family = AF_INET;
46    a.sin_port = htons(8000);    a.sin_port = htons(port);
47    a.sin_addr.s_addr = htonl(INADDR_LOOPBACK);    a.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
48    int result = bind(s, (struct sockaddr *) &a, sizeof(a));    int result = bind(s, (struct sockaddr *) &a, sizeof(a));
49    assert(result == 0);    assert(result == 0);
# Line 55  Line 58 
58      assert(client_socket > 0);      assert(client_socket > 0);
59    
60      /* read request */      /* read request */
61        bool ping = false;
62        bool first = true;
63      int state = 0;      int state = 0;
64      while (state != 2) {      while (state != 2) {
65        uint8_t buffer[8192];        uint8_t buffer[8192];
66        ssize_t bytes_read = recv(client_socket, buffer, 8192, 0);        ssize_t bytes_read = recv(client_socket, buffer, 8192, 0);
67        assert(bytes_read > 0);        assert(bytes_read > 0);
68          if (first) {
69            if (strncmp("GET /ping", buffer, 9) == 0) {
70              ping = true;
71            }
72            first = false;
73          }
74        for (int i = 0; i < bytes_read && state != 2; i++) {        for (int i = 0; i < bytes_read && state != 2; i++) {
75          uint8_t byte = buffer[i];          uint8_t byte = buffer[i];
76          switch (state) {          switch (state) {
# Line 85  Line 96 
96        }        }
97      }      }
98    
99      /* send response */      char * message;
100      char * message = "HTTP/1.1 200 OK\r\nContent-Encoding: \r\nConnection: close\r\nContent-type: text/html\r\n\r\nHello\n";      if (ping) {
101          /* send normal response */
102          message = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-type: text/html\r\n\r\nHello\n";
103        }
104        else {
105          /* send bogus response */
106          message = "HTTP/1.1 200 OK\r\nContent-Encoding: \r\nConnection: close\r\nContent-type: text/html\r\n\r\nHello\n";
107        }
108      size_t message_length = strlen(message);      size_t message_length = strlen(message);
109      ssize_t bytes_sent = send(client_socket, message, message_length, 0);      ssize_t bytes_sent = send(client_socket, message, message_length, 0);
110      assert(bytes_sent == (ssize_t) message_length);      assert(bytes_sent == (ssize_t) message_length);

Legend:
Removed from v.438  
changed lines
  Added in v.610

  ViewVC Help
Powered by ViewVC 1.1.24