Skip to content

Extract duplicate parseLine() function to shared utility header#2467

Merged
an-tao merged 3 commits intodrogonframework:masterfrom
AzmeerX:bugfix/deduplicate-parseLine-function-todo
Mar 23, 2026
Merged

Extract duplicate parseLine() function to shared utility header#2467
an-tao merged 3 commits intodrogonframework:masterfrom
AzmeerX:bugfix/deduplicate-parseLine-function-todo

Conversation

@AzmeerX
Copy link
Copy Markdown
Contributor

@AzmeerX AzmeerX commented Mar 16, 2026

This was marked with a TODO comment noting the duplication.

The parseLine() function for parsing HTTP header lines was duplicated:

  1. lib/src/MultipartStreamParser.cc (line 89-119)

Changes Made
Extracted the duplicate functions (parseLine(), startsWith(), startsWithIgnoreCase()) into a shared utility header:

  1. Created lib/inc/drogon/utils/ParsingUtils.h
  2. Implemented as inline functions to maintain zero-overhead performance
  3. Updated MultipartStreamParser.cc to include and use the new utility header (removed duplicate code, added include)

Verified compilation with this g++ -std=c++17 -I./lib/inc -c lib/src/MultipartStreamParser.cc
All function calls still work correctly; No changes to existing functionality—refactoring only

@AzmeerX
Copy link
Copy Markdown
Contributor Author

AzmeerX commented Mar 16, 2026

Let me know if you have any query regarding changes or need a further change

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors duplicated HTTP header-line parsing helpers into a shared drogon::utils header so multipart parsing code can reuse the same implementation.

Changes:

  • Added lib/inc/drogon/utils/ParsingUtils.h with inline startsWith(), startsWithIgnoreCase(), and parseLine().
  • Removed the local static helper implementations from lib/src/MultipartStreamParser.cc and switched it to include the new header.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
lib/src/MultipartStreamParser.cc Replaced local parsing helpers with shared utilities via new include.
lib/inc/drogon/utils/ParsingUtils.h Introduces shared inline parsing helpers intended for reuse across parsers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +15 to +20
#pragma once

#include <string_view>
#include <utility>
#include <cctype>

Comment on lines +19 to +20
using namespace drogon;

static bool startsWith(const std::string_view &a, const std::string_view &b)
{
if (a.size() < b.size())
{
return false;
}
for (size_t i = 0; i < b.size(); i++)
{
if (a[i] != b[i])
{
return false;
}
}
return true;
}

static bool startsWithIgnoreCase(const std::string_view &a,
const std::string_view &b)
{
if (a.size() < b.size())
{
return false;
}
for (size_t i = 0; i < b.size(); i++)
{
if (::tolower(a[i]) != ::tolower(b[i]))
{
return false;
}
}
return true;
}
using namespace drogon::utils;
Comment on lines +15 to +17
#include "MultipartStreamParser.h"
#include <cassert>
#include <drogon/utils/ParsingUtils.h>
}
for (size_t i = 0; i < b.size(); i++)
{
if (::tolower(a[i]) != ::tolower(b[i]))
@an-tao
Copy link
Copy Markdown
Member

an-tao commented Mar 17, 2026

@AzmeerX Thanks for the patch, but why can't I find a duplicate parseLine() function in the HttpRequestParser.cc file?

@AzmeerX
Copy link
Copy Markdown
Contributor Author

AzmeerX commented Mar 17, 2026

Sorry the duplicate was in MultiPart.cc not HttpRequestParser.cc. i've replaced that local parseLine() with the shared helpers in ParsingUtils.h, and also updated the PR description.
Also i have updated the code with copilot reviews

@AzmeerX
Copy link
Copy Markdown
Contributor Author

AzmeerX commented Mar 20, 2026

@an-tao are these changes good for merge?

@an-tao an-tao merged commit fcb0166 into drogonframework:master Mar 23, 2026
34 checks passed
@AzmeerX
Copy link
Copy Markdown
Contributor Author

AzmeerX commented Mar 29, 2026

@an-tao Hey, I noticed a small TODO in lib/src/SharedLibManager.cc around handling the return value of safeExec(genArgs) when generating views. Can I work on that one?

@AzmeerX AzmeerX deleted the bugfix/deduplicate-parseLine-function-todo branch March 29, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants