@@ -1254,6 +1254,14 @@ static int s_stream_write_data(
12541254 struct aws_http_stream * stream_base ,
12551255 const struct aws_http2_stream_write_data_options * options ) {
12561256 struct aws_h2_stream * stream = AWS_CONTAINER_OF (stream_base , struct aws_h2_stream , base );
1257+ if (!stream -> manual_write ) {
1258+ AWS_H2_STREAM_LOG (
1259+ ERROR ,
1260+ stream ,
1261+ "Manual writes are not enabled. You need to enable manual writes using by setting "
1262+ "'http2_use_manual_data_writes' to true in 'aws_http_make_request_options'" );
1263+ return aws_raise_error (AWS_ERROR_HTTP_MANUAL_WRITE_NOT_ENABLED );
1264+ }
12571265 struct aws_h2_connection * connection = s_get_h2_connection (stream );
12581266
12591267 /* queue this new write into the pending write list for the stream */
@@ -1272,23 +1280,20 @@ static int s_stream_write_data(
12721280 {
12731281 if (stream -> synced_data .api_state != AWS_H2_STREAM_API_STATE_ACTIVE ) {
12741282 s_unlock_synced_data (stream );
1275- s_stream_data_write_destroy ( stream , pending_write , AWS_ERROR_INVALID_STATE );
1276- AWS_LOGF_ERROR (
1277- AWS_LS_HTTP_STREAM ,
1278- "Cannot write DATA frames to an inactive or closed stream, stream=%p" ,
1279- ( void * ) stream_base );
1280- return aws_raise_error (AWS_ERROR_INVALID_STATE );
1283+ int error_code = stream -> synced_data . api_state == AWS_H2_STREAM_API_STATE_INIT
1284+ ? AWS_ERROR_HTTP_STREAM_NOT_ACTIVATED
1285+ : AWS_ERROR_HTTP_STREAM_HAS_COMPLETED ;
1286+ s_stream_data_write_destroy ( stream , pending_write , error_code );
1287+ AWS_H2_STREAM_LOG ( ERROR , stream , "Cannot write DATA frames to an inactive or closed stream" );
1288+ return aws_raise_error (error_code );
12811289 }
12821290
12831291 if (stream -> synced_data .manual_write_ended ) {
12841292 s_unlock_synced_data (stream );
1285- s_stream_data_write_destroy (stream , pending_write , AWS_ERROR_INVALID_STATE );
1286- AWS_LOGF_ERROR (
1287- AWS_LS_HTTP_STREAM ,
1288- "Cannot write DATA frames to a stream after end, stream=%p" ,
1289- (void * )stream_base );
1293+ s_stream_data_write_destroy (stream , pending_write , AWS_ERROR_HTTP_MANUAL_WRITE_HAS_COMPLETED );
1294+ AWS_H2_STREAM_LOG (ERROR , stream , "Cannot write DATA frames to a stream after manual write ended" );
12901295 /* Fail with error, otherwise, people can wait for on_complete callback that will never be invoked. */
1291- return aws_raise_error (AWS_ERROR_INVALID_STATE );
1296+ return aws_raise_error (AWS_ERROR_HTTP_MANUAL_WRITE_HAS_COMPLETED );
12921297 }
12931298 /* Not setting this until we're sure we succeeded, so that callback doesn't fire on cleanup if we fail */
12941299 if (options -> end_stream ) {
0 commit comments