Back to index

nordugrid-arc-nox  1.1.0~rc6
HTTPSHeader.cpp
Go to the documentation of this file.
00001 #include "HTTPSClient.h"
00002 
00003 namespace Arc {
00004   
00005   HTTPResponseHeader::HTTPResponseHeader(bool alive):keep_alive(alive),content_length_passed(false),content_range_passed(false) { };
00006   
00007   void HTTPResponseHeader::reset(bool alive) {
00008     keep_alive=alive;
00009     content_length_passed=false;
00010     content_range_passed=false;
00011     expires=(time_t)0; last_modified=(time_t)0;
00012   }
00013   
00014   bool HTTPResponseHeader::set(const char* name,const char* value) {
00015     if(strcasecmp("Connection:",name) == 0) {
00016       if(strcasecmp("close",value) == 0) { keep_alive=0; }
00017       else if(strcasecmp("keep-alive",value) == 0) { keep_alive=1; }
00018       else { return false; };
00019       return true;
00020     } else if(strcasecmp("Content-Length:",name) == 0) {
00021       content_length_passed=false;
00022       char *e;
00023       content_length=strtoull(value,&e,10);
00024       if((*e) != 0) return false;
00025       content_length_passed=true;
00026       return true;
00027     } else if(strcasecmp("Content-Range:",name) == 0) {
00028       content_range_passed=false;
00029       content_size=0;
00030       const char* p = value; for(;*p;p++) if(isspace(*p)) break;
00031       if(strncasecmp("bytes",value,p-value) != 0) return false;
00032       for(;*p;p++) if(!isspace(*p)) break;
00033       char *e;
00034       content_start=strtoull(p,&e,10);
00035       if((*e) != '-') return false; 
00036       p=e+1; content_end=strtoull(p,&e,10); p=e;
00037       if(((*e) != '/') && ((*e) != 0)) return false;
00038       if(content_start > content_end) return false;
00039       if((*p) == '/') {
00040         p++; content_size=strtoull(p,&e,10);
00041         if((*e) != 0) { return false; }
00042       };
00043       content_range_passed=true;
00044       return true;
00045     } else if(strcasecmp("Expires:",name) == 0) {
00046       expires=Time(value);
00047     } else if(strcasecmp("Last-Modified:",name) == 0) {
00048       last_modified=Time(value);
00049     };
00050     return true;
00051   }
00052   
00053 } // namespace Arc