Пример #1
0
		void handleStatic(staticPage* Sp) {
			Response& resp(*this->resp);
			(_staticPage=Sp)->retain();
			try {
				int bufferL = resp.buffer.length();
				if(Sp->mime.length()>0)resp.headers["Content-Type"]=Sp->mime;
				{
					char* tmps = sp.beginAdd(22);
					int l = itoa64(Sp->fileLen, tmps);
					sp.endAdd(l);
					resp.headers.insert({"Content-Length", { tmps, l }});
					StreamWriter sw(resp.buffer);
					resp.serializeHeaders(sw);
				}
				if(Sp->fileLen>=CPPSP_SENDFILE_MIN_SIZE) {
					_sendFileOffset=0;
					s.sendAll(resp.buffer.data()+bufferL,resp.buffer.length()-bufferL,
						MSG_MORE, { &handler::sendHeadersCB, this });
				} else {
					String data=Sp->data;
					iov[0]= {resp.buffer.data()+bufferL, (size_t)(resp.buffer.length()-bufferL)};
					iov[1]= {data.data(), (size_t)data.length()};
					resp.outputStream->writevAll(iov, data.length()<=0?1:2, { &handler::writevCB, this });
				}
			} catch(exception& ex) {
				Sp->release();
				server->handleError(req,resp,ex,{&handler::finalize,this});
			}
		}
Пример #2
0
		void handleStatic(staticPage* Sp) {
			Response& resp(*this->resp);
			try {
				String data=Sp->data;
				int bufferL = resp.buffer.length();
				if(Sp->mime.length()>0)resp.headers["Content-Type"]=Sp->mime;
				{
					char* tmps = sp.beginAdd(16);
					int l = itoa(data.length(), tmps);
					sp.endAdd(l);
					resp.headers.insert({"Content-Length", { tmps, l }});
					StreamWriter sw(resp.buffer);
					resp.serializeHeaders(sw);
				}
				iov[0]= {resp.buffer.data()+bufferL, (size_t)(resp.buffer.length()-bufferL)};
				iov[1]= {data.data(), (size_t)data.length()};
				resp.outputStream->writevAll(iov, 2, { &handler::writevCB, this });
			} catch(exception& ex) {
				thr.handleError(req,resp,ex,{&handler::finalize,this});
			}
		}