/// <summary>Creates a new <see cref="SPDYFrameType.Stream"/> frame.</summary> /// <param name="streamId">The ID of the new stream</param> /// <param name="headerData">The initial header data as returned from <see cref="SPDYConnection.CompressHeaders"/></param> /// <param name="unidirectional">If true, the stream must not be written to by the other side (i.e. is write-only). The default /// is false. /// </param> /// <param name="final">If true, the stream must not be written to by this side (i.e. is read-only). The default is false.</param> /// <param name="associatedStreamId">The ID of a stream that the new stream is associated with, or 0 if it's not associated with /// any other streams. The default is 0. /// </param> /// <param name="priority">The priority of the stream, from 0 (highest priority) to 7 (lowest priority). The default is 3.</param> public static SPDYFrame NewStream(int streamId, byte[] headerData, bool unidirectional = false, bool final = false, int associatedStreamId = 0, int priority = 3) { if (streamId <= 0) { throw new ArgumentOutOfRangeException(nameof(streamId)); } if (headerData == null) { throw new ArgumentNullException(nameof(headerData)); } if (associatedStreamId < 0) { throw new ArgumentOutOfRangeException(nameof(associatedStreamId)); } if ((uint)priority > 7) { throw new ArgumentOutOfRangeException(nameof(priority)); } var flags = (unidirectional ? SPDYFrameFlags.Unidirectional : 0) | (final ? SPDYFrameFlags.Final : 0); var f = new SPDYFrame(SPDYFrameType.Stream, flags, headerData.Length + 10); f.Write(streamId, 0); f.Write(associatedStreamId, 4); f.Data[8] = (byte)(priority << 5); f.Data[9] = 0; Array.Copy(headerData, 0, f.Data, 10, headerData.Length); return(f); }
/// <summary>Creates a new <see cref="SPDYFrameType.Reset"/> frame.</summary> /// <param name="streamId">The ID of the stream that is being closed</param> /// <param name="reason">The <see cref="SPDYResetReason"/> why the stream is being closed</param> public static SPDYFrame Reset(int streamId, SPDYResetReason reason) { if (streamId <= 0) { throw new ArgumentOutOfRangeException(nameof(streamId)); } var f = new SPDYFrame(SPDYFrameType.Reset, 0, 8); f.Write(streamId, 0); f.Write((uint)reason, 4); return(f); }
/// <summary>Creates a new <see cref="SPDYFrameType.GoAway"/> frame.</summary> /// <param name="lastAcceptedStream">The ID of the last stream accepted from the other side, or zero if no streams were accepted.</param> /// <param name="reason">The <see cref="SPDYShutdownReason"/> for the shutdown</param> public static SPDYFrame GoAway(int lastAcceptedStream, SPDYShutdownReason reason) { if (lastAcceptedStream < 0) { throw new ArgumentOutOfRangeException(nameof(lastAcceptedStream)); } var f = new SPDYFrame(SPDYFrameType.GoAway, 0, 8); f.Write(lastAcceptedStream, 0); f.Write((uint)reason, 4); return(f); }
/// <summary>Creates a new <see cref="SPDYFrameType.Window"/> frame.</summary> /// <param name="streamId">The ID of the stream whose control flow window is being enlarged, or 0 to enlarge the connection's /// global control flow window /// </param> /// <param name="delta">The number of additional bytes that the recipient is allowed to send</param> public static SPDYFrame Window(int streamId, int delta) { if (streamId < 0) { throw new ArgumentOutOfRangeException(nameof(streamId)); } if (delta <= 0) { throw new ArgumentOutOfRangeException(nameof(delta)); } var f = new SPDYFrame(SPDYFrameType.Window, 0, 8); f.Write(streamId, 0); f.Write(delta, 4); return(f); }
/// <summary>Creates a new <see cref="SPDYFrameType.Ping"/> frame.</summary> /// <param name="id">The ID of the ping frame</param> public static SPDYFrame Ping(uint id) { var f = new SPDYFrame(SPDYFrameType.Ping, 0, 4); f.Write(id, 0); return(f); }
/// <summary>Creates a new <see cref="SPDYFrameType.Settings"/> frame.</summary> /// <param name="clearPreviousSettings">If true, the recipient should clear previously persisted settings</param> /// <param name="settings">An array of <see cref="SPDYSetting"/> objects describing the new setting values</param> public static SPDYFrame Settings(bool clearPreviousSettings, params SPDYSetting[] settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } var f = new SPDYFrame( SPDYFrameType.Settings, clearPreviousSettings ? SPDYFrameFlags.Clear : 0, settings != null ? settings.Length * 8 + 4 : 4); f.Write(settings.Length, 0); for (int index = 4, i = 0; i < settings.Length; index += 8, i++) { SPDYSetting s = settings[i]; f.Write(s._flagsAndId, index); f.Write(s.Value, index + 4); } return(f); }
/// <summary>Creates a new <see cref="SPDYFrameType.Reply"/> frame.</summary> /// <param name="streamId">The ID of the stream that is being accepted</param> /// <param name="headerData">Additional header data as returned from <see cref="SPDYConnection.CompressHeaders"/></param> /// <param name="final">Whether this is the last frame referring to the given stream. The default is false.</param> public static SPDYFrame Reply(int streamId, byte[] headerData, bool final = false) { if (streamId <= 0) { throw new ArgumentOutOfRangeException(nameof(streamId)); } if (headerData == null) { throw new ArgumentNullException(nameof(headerData)); } var f = new SPDYFrame(SPDYFrameType.Reply, final ? SPDYFrameFlags.Final : 0, headerData.Length + 4); f.Write(streamId, 0); Array.Copy(headerData, 0, f.Data, 4, headerData.Length); return(f); }