@@ -123,9 +123,9 @@ export fn http_get() i32 {
123123 var req = http .HttpRequest .init ("GET" , "https://jsonplaceholder.typicode.com/todos/1" );
124124 defer req .deinit (allocator );
125125
126- // set headers on the request object
127- req .setHeader (allocator , "some-name" , "some-value" ) catch unreachable ;
128- req .setHeader (allocator , "another" , "again" ) catch unreachable ;
126+ // // set headers on the request object
127+ // req.setHeader(allocator, "some-name", "some-value") catch unreachable;
128+ // req.setHeader(allocator, "another", "again") catch unreachable;
129129
130130 // make the request and get the response back
131131 const res = plugin .request (req , null ) catch unreachable ;
@@ -135,11 +135,15 @@ export fn http_get() i32 {
135135 plugin .setError ("request failed" );
136136 return @as (i32 , res .status );
137137 }
138+ var headers = res .headers (plugin .allocator ) catch {
139+ plugin .setError ("failed to get headers from response!" );
140+ return -1 ;
141+ };
142+ defer headers .deinit ();
138143
139- const headers = res .headers (allocator ) catch unreachable ;
140144 const content_type = headers .get ("content-type" );
141145 if (content_type ) | t | {
142- plugin .log (.Debug , t );
146+ plugin .log (.Debug , t . value ); // something like 'application/json; charset=utf-8'
143147 }
144148
145149 // get the bytes for the res body
0 commit comments