Differences From Artifact [b0b4bb5876]:
- File tests/OFHTTPClientTests.m — part of check-in [7e5c81e186] at 2018-01-03 19:49:46 on branch trunk — Update copyright notice (user: js, size: 3505) [annotate] [blame] [check-ins using]
To Artifact [ca69cf61a6]:
- File
tests/OFHTTPClientTests.m
— part of check-in
[8681bba25e]
at
2018-02-18 00:20:39
on branch trunk
— OFHTTPClient: Add a callback for the request body
This is in preparation for removing the body from OFHTTPRequest.
Having it as OFData that is part of the OFHTTPRequest was a bad idea, as
it does not allow streaming. (user: js, size: 4116) [annotate] [blame] [check-ins using]
︙ | |||
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | + + + + + + + + + + + + + + + + + + + + + | } @end @implementation HTTPClientTestsServer - (id)main { OFTCPSocket *listener, *client; char buffer[5]; [cond lock]; listener = [OFTCPSocket socket]; _port = [listener bindToHost: @"127.0.0.1" port: 0]; [listener listen]; [cond signal]; [cond unlock]; client = [listener accept]; if (![[client readLine] isEqual: @"GET /foo HTTP/1.1"]) OF_ENSURE(0); if (![[client readLine] hasPrefix: @"User-Agent:"]) OF_ENSURE(0); if (![[client readLine] isEqual: @"Content-Length: 5"]) OF_ENSURE(0); if (![[client readLine] isEqual: @"Content-Type: application/x-www-form-urlencoded; charset=UTF-8"]) OF_ENSURE(0); if (![[client readLine] isEqual: [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, _port]]) OF_ENSURE(0); if (![[client readLine] isEqual: @""]) OF_ENSURE(0); [client readIntoBuffer: buffer exactLength: 5]; if (memcmp(buffer, "Hello", 5) != 0) OF_ENSURE(0); [client writeString: @"HTTP/1.0 200 OK\r\n" @"cONTeNT-lENgTH: 7\r\n" @"\r\n" @"foo\n" @"bar"]; [client close]; return nil; } @end @implementation TestsAppDelegate (OFHTTPClientTests) - (void)client: (OFHTTPClient *)client requestsBody: (OFStream *)body request: (OFHTTPRequest *)request context: (id)context { [body writeString: @"Hello"]; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response_ context: (id)context { response = [response_ retain]; |
︙ | |||
122 123 124 125 126 127 128 | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | - + + + + | URL = [OFURL URLWithString: [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server->_port]]; TEST(@"-[asyncPerformRequest:]", (client = [OFHTTPClient client]) && R([client setDelegate: self]) && |
︙ |