/// <summary> /// Opens the stream in current session. /// </summary> /// <param name="id">the stream id.</param> /// <param name="headers">The S+M headers.</param> /// <param name="isFinal">the final flag.</param> /// <returns>The Stream.</returns> private Http2Stream OpenStream(int id, ProtocolHeaders headers, bool isFinal) { if (id <= this.lastSeenStreamId) { this.End(StatusCode.ProtocolError); return(null); } this.lastSeenStreamId = id; // don't have to wait for stream opening Http2Stream stream = new Http2Stream(id, this); this.streams.Add(stream); stream.OnClose += this.OnCloseStream; if (IsServer) { stream.OpenServer(headers, isFinal); // Settings must be sent for session once for session if (stream.StreamId <= 2) { this.protocol.SendSettings(stream); } this.protocol.SendSynReply(stream); } else { stream.OpenClient(headers, isFinal); } if (this.OnStreamOpened != null) { this.OnStreamOpened(this, new StreamEventArgs(stream)); } return(stream); }
/// <summary> /// Sends the data. /// </summary> /// <param name="stream">The stream.</param> /// <param name="frame">The base frame.</param> private void SendFrame(Http2Stream stream, BaseFrame frame) { try { byte[] frameBinary = this.serializer.Serialize(frame); frame.Length = frameBinary.Length; SendMessage(frameBinary); if (frame.IsFinal) { stream.State = Http2StreamState.HalfClosed; } if (this.OnFrameSent != null) { this.OnFrameSent(this, new FrameEventArgs(frame)); } } catch (Exception e) { if (this.OnStreamError != null) { this.OnStreamError(this, new StreamErrorEventArgs(stream, e)); } else { throw; } } }
/// <summary> /// Sends the window update request. /// </summary> /// <param name="stream">The stream.</param> /// <param name="creditAddition">The credit addition.</param> public void SendWindowUpdate(Http2Stream stream, Int64 windowAddition) { this.SendFrame(this.builder.BuildWindowUpdateFrame(stream, windowAddition)); }
/// <summary> /// Sends the syn stream request. /// </summary> /// <param name="stream">The stream.</param> /// <param name="headers">The headers.</param> /// <param name="isFin">FIN flag.</param> public void SendSynStream(Http2Stream stream, ProtocolHeaders headers, bool isFin) { this.SendFrame(this.builder.BuildSynStreamFrame(stream, headers, isFin)); }
/// <summary> /// Sends the RST. /// </summary> /// <param name="stream">The stream.</param> /// <param name="reason">The reason for RST.</param> public void SendRST(Http2Stream stream, StatusCode reason) { this.SendFrame(stream, this.builder.BuildRSTFrame(stream, reason)); }
/// <summary> /// Sends the data. /// </summary> /// <param name="stream">The stream.</param> /// <param name="data">The data.</param> /// <param name="isFin">FIN flag.</param> public void SendData(Http2Stream stream, ProtocolData data, bool isFin) { this.SendFrame(stream, this.builder.BuildDataFrame(stream, data, isFin)); }
/// <summary> /// Sends the headers. /// </summary> /// <param name="stream">The stream.</param> /// <param name="headers">The headers.</param> /// <param name="isFin">FIN flag.</param> public void SendHeaders(Http2Stream stream, ProtocolHeaders headers, bool isFin) { this.SendFrame(stream, this.builder.BuildHeadersFrame(stream, headers, isFin)); }
public void SendSettings(Http2Stream stream) { this.SendFrame(this.builder.BuildSettingsFrame(stream)); }
/// <summary> /// Opens the stream in current session. /// </summary> /// <param name="id">the stream id.</param> /// <param name="headers">The S+M headers.</param> /// <param name="isFinal">the final flag.</param> /// <returns>The Stream.</returns> private Http2Stream OpenStream(int id, ProtocolHeaders headers, bool isFinal) { if (id <= this.lastSeenStreamId) { this.End(StatusCode.ProtocolError); return null; } this.lastSeenStreamId = id; // don't have to wait for stream opening Http2Stream stream = new Http2Stream(id, this); this.streams.Add(stream); stream.OnClose += this.OnCloseStream; stream.Open(headers, isFinal); if (this.OnStreamOpened != null) { this.OnStreamOpened(this, new StreamEventArgs(stream)); } return stream; }
public void SendSynReply(Http2Stream stream) { var headers = new ProtocolHeaders(); headers[ProtocolHeaders.ContentType] = "text/plain"; headers[ProtocolHeaders.Status] = "200"; headers[ProtocolHeaders.Version] = "spdy/3"; this.SendFrame(this.builder.BuildSynReplyFrame(stream, headers)); }
/// <summary> /// Opens the stream in current session. /// </summary> /// <param name="id">the stream id.</param> /// <param name="headers">The S+M headers.</param> /// <param name="isFinal">the final flag.</param> /// <returns>The Stream.</returns> private Http2Stream OpenStream(int id, ProtocolHeaders headers, bool isFinal) { if (id <= this.lastSeenStreamId) { this.End(StatusCode.ProtocolError); return null; } this.lastSeenStreamId = id; // don't have to wait for stream opening Http2Stream stream = new Http2Stream(id, this); this.streams.Add(stream); stream.OnClose += this.OnCloseStream; if (IsServer) { stream.OpenServer(headers, isFinal); // Settings must be sent for session once for session if (stream.StreamId <= 2) this.protocol.SendSettings(stream); this.protocol.SendSynReply(stream); } else { stream.OpenClient(headers, isFinal); } if (this.OnStreamOpened != null) { this.OnStreamOpened(this, new StreamEventArgs(stream)); } return stream; }