@@ -104,47 +104,6 @@ Http2Options::Http2Options(Environment* env) {
104104 }
105105}
106106
107- inline void CopyHeaders (Isolate* isolate,
108- Local<Context> context,
109- MaybeStackBuffer<nghttp2_nv>* list,
110- Local<Array> headers) {
111- Local<Value> item;
112- Local<Array> header;
113-
114- for (size_t n = 0 ; n < headers->Length (); n++) {
115- item = headers->Get (context, n).ToLocalChecked ();
116- header = item.As <Array>();
117- Local<Value> key = header->Get (context, 0 ).ToLocalChecked ();
118- Local<Value> value = header->Get (context, 1 ).ToLocalChecked ();
119- CHECK (key->IsString ());
120- CHECK (value->IsString ());
121- size_t keylen = StringBytes::StorageSize (isolate, key, ASCII);
122- size_t valuelen = StringBytes::StorageSize (isolate, value, ASCII);
123- nghttp2_nv& nv = (*list)[n];
124- nv.flags = NGHTTP2_NV_FLAG_NONE;
125- Local<Value> flag = header->Get (context, 2 ).ToLocalChecked ();
126- if (flag->BooleanValue (context).ToChecked ())
127- nv.flags |= NGHTTP2_NV_FLAG_NO_INDEX;
128- nv.name = Malloc<uint8_t >(keylen);
129- nv.value = Malloc<uint8_t >(valuelen);
130- nv.namelen =
131- StringBytes::Write (isolate,
132- reinterpret_cast <char *>(nv.name ),
133- keylen, key, ASCII);
134- nv.valuelen =
135- StringBytes::Write (isolate,
136- reinterpret_cast <char *>(nv.value ),
137- valuelen, value, ASCII);
138- }
139- }
140-
141- inline void FreeHeaders (MaybeStackBuffer<nghttp2_nv>* list) {
142- for (size_t n = 0 ; n < list->length (); n++) {
143- free ((*list)[n].name );
144- free ((*list)[n].value );
145- }
146- }
147-
148107void Http2Session::OnFreeSession () {
149108 ::delete this ;
150109}
@@ -860,7 +819,7 @@ void Http2Session::Send(uv_buf_t* buf, size_t length) {
860819}
861820
862821void Http2Session::OnTrailers (Nghttp2Stream* stream,
863- MaybeStackBuffer<nghttp2_nv>* trailers ) {
822+ const SubmitTrailers& submit_trailers ) {
864823 DEBUG_HTTP2 (" Http2Session: prompting for trailers on stream %d\n " ,
865824 stream->id ());
866825 Local<Context> context = env ()->context ();
@@ -879,8 +838,8 @@ void Http2Session::OnTrailers(Nghttp2Stream* stream,
879838 if (ret->IsArray ()) {
880839 Local<Array> headers = ret.As <Array>();
881840 if (headers->Length () > 0 ) {
882- trailers-> AllocateSufficientStorage ( headers-> Length () );
883- CopyHeaders (isolate, context, trailers, headers );
841+ Headers trailers (isolate, context, headers);
842+ submit_trailers. Submit (* trailers, trailers. length () );
884843 }
885844 }
886845 }
0 commit comments