libwinyl
Loading...
Searching...
No Matches
http_1_0.c

Demonstrates winyl_change_http.

#include <stdio.h>
#include <stdlib.h>
#include <winyl/winyl.h>
#include <winyl/request.h>
int main(int argc, char* argv[]) {
winyl host = winyl_open("postman-echo.com", 80);
if (host.error != 0) {
// We don't handle errors properly here,
// please see basic.c for proper error handling.
printf("Error code %d\n", host.error);
winyl_close(&host);
exit(1);
}
// the default is HTTP/1.1, let's change it to HTTP/1.0
// we pass WINYL_REQUEST_NO_HEADERS so we can see the raw headers with the body
if (res.error != 0) {
printf("Error code %d\n", res.error);
winyl_close(&host);
exit(1);
}
// Unfortunately, a server returning a HTTP/1.1 response to a HTTP/1.0 request
// is valid behavior. Note it might be thrown off by the library sending a
// Host header, even with a HTTP/1.0 request for compatiblity reasons.
//
// We can verify this behavior with curl aswell.
// curl -v --http1.0 http://postman-echo.com/get
printf("See notes in the example's code!\n");
printf("%s\n", res.body);
winyl_close(&host);
exit(0);
}
Contains the winyl_request function and related.
#define WINYL_REQUEST_NO_HEADERS
Skips parsing the headers.
Definition request.h:42
void winyl_response_close(winyl_response *response)
Frees memory used up by response.
winyl_response winyl_request(winyl *host, char *path, int flags)
Performs a HTTP request.
Represents a HTTP response.
Definition request.h:13
int error
Contains the error code after any winyl call.
Definition request.h:15
char * body
Response body.
Definition request.h:34
Represents a HTTP host.
Definition winyl.h:27
int error
Contains the error code after any winyl call.
Definition winyl.h:29
Contains the winyl_open function and related.
void winyl_close(winyl *host)
Frees memory used up by host.
#define WINYL_HTTP_1_0
HTTP/1.0 for winyl_change_http.
Definition winyl.h:18
winyl winyl_open(char *hostname, int port)
Opens an HTTP host with the specified port.
int winyl_change_http(winyl *host, int version)
Changes HTTP version used for requests to host.