10 #if defined( INC_ALL )
38 static
void encodeRFC1866(
INOUT STREAM *headerStream,
42 static const char allowedChars[] =
"$-_.!*'(),\"/\x00\x00";
46 assert(
isReadPtr(
string, stringLength ) );
50 for( index = 0; index < stringLength && \
58 sputc( headerStream, ch );
63 sputc( headerStream,
'+' );
66 for( i = 0; allowedChars[ i ] !=
'\0' && ch != allowedChars[ i ] && \
69 if( allowedChars[ i ] !=
'\0' )
72 sputc( headerStream, ch );
76 char escapeString[ 8 + 8 ];
80 escapeStringLen =
sprintf_s( escapeString, 8,
"%%%02X", ch );
81 swrite( headerStream, escapeString, escapeStringLen );
110 REQUIRES( flags >= HTTP_FLAG_NONE && flags <= HTTP_FLAG_MAX );
112 status = netStream->bufferedTransportWriteFunction( stream, buffer,
114 &bytesWritten, flags );
121 if( bytesWritten < length )
127 "HTTP write timed out before all data could be written" ) );
151 char headerBuffer[ HTTP_LINEBUF_SIZE + 8 ];
152 const int transportFlag = ( contentLength > 0 && !forceGet ) ? \
157 assert( ( httpReqInfo == NULL ) || \
159 assert( ( contentLength == 0 && contentType == NULL && \
160 contentTypeLen == 0 ) || \
161 ( contentLength >= 1 && \
162 isReadPtr( contentType, contentTypeLen ) ) );
164 REQUIRES( ( contentLength == 0 && contentType == NULL && \
165 contentTypeLen == 0 ) || \
167 contentType != NULL && \
169 REQUIRES( ( httpReqInfo == NULL ) || \
170 ( httpReqInfo->attributeLen == 0 && \
171 httpReqInfo->valueLen == 0 ) || \
172 ( httpReqInfo->attributeLen > 0 && \
173 httpReqInfo->valueLen > 0 ) );
175 sMemOpen( &headerStream, headerBuffer, HTTP_LINEBUF_SIZE );
177 swrite( &headerStream,
"CONNECT ", 8 );
180 if( contentLength > 0 && !forceGet )
181 swrite( &headerStream,
"POST ", 5 );
183 swrite( &headerStream,
"GET ", 4 );
190 swrite( &headerStream,
"http://", 7 );
191 swrite( &headerStream, netStream->host, netStream->hostLen );
192 if( netStream->port != 80 )
194 char portString[ 16 + 8 ];
195 int portStringLength;
197 portStringLength =
sprintf_s( portString, 16,
":%d",
199 swrite( &headerStream, portString, portStringLength );
204 if( netStream->path != NULL && netStream->pathLen > 0 )
205 swrite( &headerStream, netStream->path, netStream->pathLen );
207 sputc( &headerStream,
'/' );
209 if( httpReqInfo != NULL )
211 if( httpReqInfo->attributeLen > 0 && httpReqInfo->valueLen > 0 )
213 sputc( &headerStream,
'?' );
214 swrite( &headerStream, httpReqInfo->attribute,
215 httpReqInfo->attributeLen );
216 sputc( &headerStream,
'=' );
217 encodeRFC1866( &headerStream, httpReqInfo->value,
218 httpReqInfo->valueLen );
220 if( httpReqInfo->extraDataLen > 0 )
222 sputc( &headerStream,
'&' );
223 swrite( &headerStream, httpReqInfo->extraData,
224 httpReqInfo->extraDataLen );
229 if( isHTTP10( stream ) )
230 swrite( &headerStream,
" HTTP/1.0\r\n", 11 );
233 swrite( &headerStream,
" HTTP/1.1\r\nHost: ", 17 );
234 swrite( &headerStream, netStream->host, netStream->hostLen );
235 swrite( &headerStream,
"\r\n", 2 );
237 swrite( &headerStream,
"Connection: close\r\n", 19 );
239 if( contentLength > 0 )
241 char lengthString[ 16 + 8 ];
242 int lengthStringLength;
250 swrite( &headerStream,
"Content-Type: ", 14 );
251 swrite( &headerStream, contentType, contentTypeLen );
252 swrite( &headerStream,
"\r\nContent-Length: ", 18 );
253 lengthStringLength =
sprintf_s( lengthString, 16,
"%d",
255 swrite( &headerStream, lengthString, lengthStringLength );
256 swrite( &headerStream,
"\r\nCache-Control: no-cache\r\n", 27 );
259 status = swrite( &headerStream,
"\r\n", 2 );
261 headerLength = stell( &headerStream );
262 sMemDisconnect( &headerStream );
264 return( sendHTTPData( stream, headerBuffer, headerLength,
271 static
int writeResponseHeader(
INOUT STREAM *stream,
272 IN_BUFFER( contentTypeLen )
const char *contentType,
278 char headerBuffer[ HTTP_LINEBUF_SIZE + 8 ], lengthString[ 16 + 8 ];
279 int headerLength =
DUMMY_INIT, lengthStringLength, status;
282 assert(
isReadPtr( contentType, contentTypeLen ) );
287 sMemOpen( &headerStream, headerBuffer, HTTP_LINEBUF_SIZE );
288 if( isHTTP10( stream ) )
289 swrite( &headerStream,
"HTTP/1.0 200 OK\r\n", 17 );
292 swrite( &headerStream,
"HTTP/1.1 200 OK\r\n", 17 );
294 swrite( &headerStream,
"Connection: close\r\n", 19 );
296 swrite( &headerStream,
"Content-Type: ", 14 );
297 swrite( &headerStream, contentType, contentTypeLen );
298 swrite( &headerStream,
"\r\nContent-Length: ", 18 );
299 lengthStringLength =
sprintf_s( lengthString, 16,
"%d",
301 swrite( &headerStream, lengthString, lengthStringLength );
302 swrite( &headerStream,
"\r\nCache-Control: no-cache\r\n", 27 );
303 if( isHTTP10( stream ) )
304 swrite( &headerStream,
"Pragma: no-cache\r\n", 18 );
305 status = swrite( &headerStream,
"\r\n", 2 );
307 headerLength = stell( &headerStream );
308 sMemDisconnect( &headerStream );
310 return( sendHTTPData( stream, headerBuffer, headerLength,
335 assert(
isReadPtr( buffer, maxLength ) );
336 assert(
isWritePtr( length,
sizeof(
int ) ) );
350 char headerBuffer[ HTTP_LINEBUF_SIZE + 8 ];
352 status = sendHTTPError( stream, headerBuffer, HTTP_LINEBUF_SIZE,
364 status = writeResponseHeader( stream, httpDataInfo->contentType,
365 httpDataInfo->contentTypeLen,
366 httpDataInfo->bufSize );
371 httpDataInfo->contentTypeLen > 0 );
374 REQUIRES( netStream->host != NULL && netStream->hostLen > 0 );
380 if( httpDataInfo->bufSize > 0 && \
384 status = writeRequestHeader( stream, httpDataInfo->reqInfo,
385 httpDataInfo->contentType,
386 httpDataInfo->contentTypeLen,
387 httpDataInfo->bufSize, forceGet );
393 status = netStream->bufferedTransportWriteFunction( stream,
394 httpDataInfo->buffer, httpDataInfo->bufSize,
395 &httpDataInfo->bytesTransferred,
403 char headerBuffer[ HTTP_LINEBUF_SIZE + 8 ];
410 sMemOpen( &headerStream, headerBuffer, HTTP_LINEBUF_SIZE );
411 if( isHTTP10( stream ) )
412 swrite( &headerStream,
" HTTP/1.0\r\n", 11 );
415 swrite( &headerStream,
" HTTP/1.1\r\nHost: ", 17 );
416 swrite( &headerStream, netStream->host, netStream->hostLen );
417 swrite( &headerStream,
"\r\n", 2 );
419 swrite( &headerStream,
"Connection: close\r\n", 19 );
421 status = swrite( &headerStream,
"\r\n", 2 );
423 headerLength = stell( &headerStream );
424 sMemDisconnect( &headerStream );
426 status = sendHTTPData( stream, headerBuffer, headerLength,
427 TRANSPORT_FLAG_FLUSH );
440 netStream->writeFunction = writeFunction;