internal void BeginStreamingRequestBody(HttpRequest request, Action<HttpBuffer> cb_buffer) { lock (_server._lock) { if (_isdisposed) return; // this is not the right place to throw if (_state != _State.RequestBodyUserWait) throw new InvalidOperationException("invalid state for request body streaming"); if (_requestbody_streaming_started) throw new InvalidOperationException("request body can only be streamed once"); if (_tx == null || _tx.Request != request) throw new InvalidOperationException("this request object is not active"); _requestbody_streaming_started = true; _requestbody_buffer = new RequestBodyBuffer(this); _requestbody_user_cb = cb_buffer; _state = _State.RequestBodyUserRead; _HandleCurrentState(); } }
void ev_writedone() { if (_state == _State.Failure) { Dispose(); } else if (_state == _State.Send100Continue) { ev_requestbodyready(); _HandleCurrentState(); } else if (_state == _State.SendResponseBody) { _state = _State.ResponseBodyUserWait; var cb = _responsebody_user_cb; var buf = _responsebody_buffer; _server._DispatchCallback(() => cb(buf)); } else if (_state == _State.SendResponseBodyLast) { // clear out all state _tx = null; _readoff = 0; _readcount = 0; _readbuf = new byte[4096]; _readoff = 0; _readcount = 0; _headerstate = _HeaderState.FirstLine; _linems = new MemoryStream(); _firstline = null; _headerlines = new List<string>(); _writeoff = 0; _writecount = 0; _writebytes = null; _requestbody_left = 0; _requestbody_full = null; _requestbody_multipart = null; _requestbody_streaming_started = false; _requestbody_buffer = null; _requestbody_user_cb = null; _responsebody_streaming_started = false; _responsebody_buffer = null; _responsebody_user_cb = null; _responsebody_done_cb = null; _responsebody_left = -1; _state = _State.RequestHeaders; if (_isconnectionclose || _ishttp10) { Dispose(); } else { _HandleCurrentState(); } } else if (_state == _State.SendResponseHeaders) { _state = _State.ResponseBodyUserWait; _server._DispatchCallback(() => _responsebody_user_cb(_responsebody_buffer)); } else { throw new InvalidOperationException(); } }
void _RequestBodyBufferComplete() { lock (_server._lock) { if (_isdisposed) return; // this is not the right place to throw if (_state != _State.RequestBodyUserWait) throw new InvalidOperationException("request is not waiting for buffer complete"); if (_requestbody_left > 0) { _state = _State.RequestBodyUserRead; _HandleCurrentState(); } else { _state = _State.ResponseHeadersUserWait; _requestbody_buffer = null; _requestbody_user_cb = null; _HandleCurrentState(); } } }