88
void CSHeader::write(CSOutputStream *out)
88
void CSHeader::write(CSOutputStream *out, bool trace)
91
printf("%s: %s\n", iName->getCString(), iValue->getCString());
93
97
out->print("\r\n");
225
void CSHTTPHeaders::addHeader(const char *name, uint64_t value)
229
snprintf(buffer, 30, "%"PRIu64, value);
230
addHeader(name, buffer);
221
233
void CSHTTPHeaders::removeHeader(CSString *name)
246
258
CSString *CSHTTPHeaders::getHeaderValue(const char *name)
252
n = CSString::newString(name);
258
266
for (uint32_t i=0; i<iHeaders->size(); i++) {
259
267
h = (CSHeader *) iHeaders->get(i);
260
if (h->getName()->compare(n) == 0) {
268
if (h->getName()->compare(name) == 0) {
261
269
v = h->getValue();
271
void CSHTTPHeaders::writeHeader(CSOutputStream *out)
276
for (uint32_t i=0; i<iHeaders->size(); i++) {
277
h = (CSHeader *) iHeaders->get(i);
278
const char *CSHTTPHeaders::getHeaderCStringValue(const char *name)
283
for (uint32_t i=0; i<iHeaders->size(); i++) {
284
h = (CSHeader *) iHeaders->get(i);
285
if (h->getName()->compare(name) == 0) {
286
return h->getValue()->getCString();
293
void CSHTTPHeaders::writeHeader(CSOutputStream *out, bool trace)
298
for (uint32_t i=0; i<iHeaders->size(); i++) {
299
h = (CSHeader *) iHeaders->get(i);
300
h->write(out, trace);
330
352
sb = iInput->readLine();
334
printf("HTTP: %s\n", sb->getCString());
357
CSL.log(self, CSLog::Protocol, "HTTP Request - Header:\n");
358
printf("%s\n", sb->getCString());
336
360
if (sb->length() == 0) {
428
void CSHTTPInputStream::readBody()
433
if (getContentLength(&body_size)) {
434
iBody.setLength((size_t) body_size);
436
while (len < body_size) {
437
tfer = read(iBody.getBuffer(len), (size_t)(body_size - len));
439
CSException::throwException(CS_CONTEXT, CS_ERR_BODY_INCOMPLETE, "POST data incomplete");
444
CSStringBuffer *sb = NULL;
446
/* Read until we have an empty line. */
451
if (sb->length() == 0) {
455
iBody.append(sb->getBuffer(0), sb->length());
456
iBody.append((char) '\n');
404
462
bool CSHTTPInputStream::getRange(uint64_t *size, uint64_t *offset)
531
591
iOutput->release();
534
void CSHTTPOutputStream::writeHeaders()
594
void CSHTTPOutputStream::print(const char *str, bool trace)
602
void CSHTTPOutputStream::print(int32_t value, bool trace)
606
iOutput->print(value);
609
void CSHTTPOutputStream::print(uint64_t value, bool trace)
612
printf("%"PRIu64, value);
613
iOutput->print(value);
616
void CSHTTPOutputStream::writeHeaders(bool trace)
618
writeHeader(this, trace);
540
void CSHTTPOutputStream::writeHead()
622
void CSHTTPOutputStream::writeHead(bool trace)
542
iOutput->print("HTTP/1.1 ");
543
iOutput->print(iStatus);
545
iOutput->print(getReasonPhrase(iStatus));
546
iOutput->print("\r\n");
547
writeHeader(iOutput);
548
iOutput->print("Content-Length: ");
549
iOutput->print(iContentLength);
550
iOutput->print("\r\n");
626
CSL.log(self, CSLog::Protocol, "HTTP Reply - Header:\n");
627
print("HTTP/1.1 ", trace);
628
print(iStatus, trace);
630
print(getReasonPhrase(iStatus), trace);
631
print("\r\n", trace);
632
writeHeader(iOutput, trace);
633
print("Content-Length: ", trace);
634
print(iContentLength, trace);
635
print("\r\n", trace);
551
636
if (iRangeSize && (iStatus == 200)) {
552
iOutput->print("Content-Range: bytes ");
553
iOutput->print(iRangeOffset);
555
iOutput->print(iRangeOffset + iRangeSize -1);
557
iOutput->print(iTotalLength);
558
iOutput->print("\r\n");
637
print("Content-Range: bytes ", trace);
638
print(iRangeOffset, trace);
640
print(iRangeOffset + iRangeSize -1, trace);
642
print(iTotalLength, trace);
643
print("\r\n", trace);
560
iOutput->print("\r\n");
645
print("\r\n", trace);
563
650
void CSHTTPOutputStream::clearBody()
580
667
iContentLength = iBody.length();
583
void CSHTTPOutputStream::appendBody(int value)
586
iContentLength = iBody.length();
670
void CSHTTPOutputStream::appendBody(int32_t value)
673
iContentLength = iBody.length();
676
void CSHTTPOutputStream::appendBody(uint32_t value)
679
iContentLength = iBody.length();
682
void CSHTTPOutputStream::appendBody(uint64_t value)
685
iContentLength = iBody.length();
688
const char *CSHTTPOutputStream::getBodyData()
690
return iBody.getCString();
693
size_t CSHTTPOutputStream::getBodyLength()
695
return iBody.length();
698
void CSHTTPOutputStream::setBody(CSStringBufferImpl *buf)
701
iContentLength = iBody.length();
589
704
void CSHTTPOutputStream::close()