Add back url_buffer as HTTP_String
Making the URL buffer allocation more explicit by storing it as an HTTP_String. This provides both the pointer and length, making the code clearer and more self-documenting.
This commit is contained in:
@@ -3885,9 +3885,12 @@ void http_request_builder_url(HTTP_RequestBuilder builder,
|
|||||||
return; // TODO: set error
|
return; // TODO: set error
|
||||||
memcpy(url_copy, url.ptr, url.len);
|
memcpy(url_copy, url.ptr, url.len);
|
||||||
|
|
||||||
// Parse the copied URL (url.scheme.ptr will point to url_copy)
|
conn->url_buffer.ptr = url_copy;
|
||||||
if (http_parse_url(url_copy, url.len, &conn->url) != 1) {
|
conn->url_buffer.len = url.len;
|
||||||
free(url_copy);
|
|
||||||
|
// Parse the copied URL (all url.* pointers will reference url_buffer)
|
||||||
|
if (http_parse_url(conn->url_buffer.ptr, conn->url_buffer.len, &conn->url) != 1) {
|
||||||
|
free(conn->url_buffer.ptr);
|
||||||
return; // TODO: set error
|
return; // TODO: set error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4054,7 +4057,7 @@ int http_request_builder_send(HTTP_RequestBuilder builder)
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
conn->state = HTTP_CLIENT_CONN_FREE;
|
conn->state = HTTP_CLIENT_CONN_FREE;
|
||||||
free((void*)conn->url.scheme.ptr);
|
free(conn->url_buffer.ptr);
|
||||||
byte_queue_free(&conn->input);
|
byte_queue_free(&conn->input);
|
||||||
byte_queue_free(&conn->output);
|
byte_queue_free(&conn->output);
|
||||||
client->num_conns--;
|
client->num_conns--;
|
||||||
@@ -4302,7 +4305,7 @@ void http_free_response(HTTP_Response *response)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
conn->state = HTTP_CLIENT_CONN_FREE;
|
conn->state = HTTP_CLIENT_CONN_FREE;
|
||||||
free((void*)conn->url.scheme.ptr);
|
free(conn->url_buffer.ptr);
|
||||||
byte_queue_free(&conn->input);
|
byte_queue_free(&conn->input);
|
||||||
byte_queue_free(&conn->output);
|
byte_queue_free(&conn->output);
|
||||||
client->num_conns--;
|
client->num_conns--;
|
||||||
|
|||||||
@@ -894,8 +894,11 @@ typedef struct {
|
|||||||
// TODO: comment
|
// TODO: comment
|
||||||
bool trace_bytes;
|
bool trace_bytes;
|
||||||
|
|
||||||
|
// Allocated copy of the URL string
|
||||||
|
HTTP_String url_buffer;
|
||||||
|
|
||||||
// Parsed URL for connection establishment
|
// Parsed URL for connection establishment
|
||||||
// url.scheme.ptr points to the allocated copy of the URL string
|
// All url.* pointers reference into url_buffer
|
||||||
HTTP_URL url;
|
HTTP_URL url;
|
||||||
|
|
||||||
// Data received from the server
|
// Data received from the server
|
||||||
|
|||||||
+8
-5
@@ -224,9 +224,12 @@ void http_request_builder_url(HTTP_RequestBuilder builder,
|
|||||||
return; // TODO: set error
|
return; // TODO: set error
|
||||||
memcpy(url_copy, url.ptr, url.len);
|
memcpy(url_copy, url.ptr, url.len);
|
||||||
|
|
||||||
// Parse the copied URL (url.scheme.ptr will point to url_copy)
|
conn->url_buffer.ptr = url_copy;
|
||||||
if (http_parse_url(url_copy, url.len, &conn->url) != 1) {
|
conn->url_buffer.len = url.len;
|
||||||
free(url_copy);
|
|
||||||
|
// Parse the copied URL (all url.* pointers will reference url_buffer)
|
||||||
|
if (http_parse_url(conn->url_buffer.ptr, conn->url_buffer.len, &conn->url) != 1) {
|
||||||
|
free(conn->url_buffer.ptr);
|
||||||
return; // TODO: set error
|
return; // TODO: set error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +396,7 @@ int http_request_builder_send(HTTP_RequestBuilder builder)
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
conn->state = HTTP_CLIENT_CONN_FREE;
|
conn->state = HTTP_CLIENT_CONN_FREE;
|
||||||
free((void*)conn->url.scheme.ptr);
|
free(conn->url_buffer.ptr);
|
||||||
byte_queue_free(&conn->input);
|
byte_queue_free(&conn->input);
|
||||||
byte_queue_free(&conn->output);
|
byte_queue_free(&conn->output);
|
||||||
client->num_conns--;
|
client->num_conns--;
|
||||||
@@ -641,7 +644,7 @@ void http_free_response(HTTP_Response *response)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
conn->state = HTTP_CLIENT_CONN_FREE;
|
conn->state = HTTP_CLIENT_CONN_FREE;
|
||||||
free((void*)conn->url.scheme.ptr);
|
free(conn->url_buffer.ptr);
|
||||||
byte_queue_free(&conn->input);
|
byte_queue_free(&conn->input);
|
||||||
byte_queue_free(&conn->output);
|
byte_queue_free(&conn->output);
|
||||||
client->num_conns--;
|
client->num_conns--;
|
||||||
|
|||||||
+4
-1
@@ -75,8 +75,11 @@ typedef struct {
|
|||||||
// TODO: comment
|
// TODO: comment
|
||||||
bool trace_bytes;
|
bool trace_bytes;
|
||||||
|
|
||||||
|
// Allocated copy of the URL string
|
||||||
|
HTTP_String url_buffer;
|
||||||
|
|
||||||
// Parsed URL for connection establishment
|
// Parsed URL for connection establishment
|
||||||
// url.scheme.ptr points to the allocated copy of the URL string
|
// All url.* pointers reference into url_buffer
|
||||||
HTTP_URL url;
|
HTTP_URL url;
|
||||||
|
|
||||||
// Data received from the server
|
// Data received from the server
|
||||||
|
|||||||
Reference in New Issue
Block a user