Skip to content

Add dedicated Http faker with status codes, headers, user agents and more#1835

Open
bodiam wants to merge 3 commits into
mainfrom
claude/datafaker-http-faker-g7cvb
Open

Add dedicated Http faker with status codes, headers, user agents and more#1835
bodiam wants to merge 3 commits into
mainfrom
claude/datafaker-http-faker-g7cvb

Conversation

@bodiam

@bodiam bodiam commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Introduces net.datafaker.providers.base.Http with:

  • Status codes by category: statusCode(), informational(), successful(),
    redirect(), clientError(), serverError() — all return int
  • Reason phrases: statusMessage() and per-category *Message() variants
  • Combined form: statusCodeWithReason() → "200 OK"
  • Headers: requestHeader(), responseHeader()
  • MIME types: contentType()
  • User agents: userAgent(), userAgent(Browser), mobileUserAgent()
    covering Chrome, Firefox, Safari, Edge, and mobile browsers
  • Protocol: httpMethod(), httpVersion(), encoding()
  • Response bodies: responseBody() with JSON success/error templates

Registers http.yml in EnFile and Http in BaseProviders.
Includes HttpTest with 168 assertions covering all methods.

https://claude.ai/code/session_01WM2gJRU7t1i8sXu6wLx6ak

…more

Introduces net.datafaker.providers.base.Http with:
- Status codes by category: statusCode(), informational(), successful(),
  redirect(), clientError(), serverError() — all return int
- Reason phrases: statusMessage() and per-category *Message() variants
- Combined form: statusCodeWithReason() → "200 OK"
- Headers: requestHeader(), responseHeader()
- MIME types: contentType()
- User agents: userAgent(), userAgent(Browser), mobileUserAgent()
  covering Chrome, Firefox, Safari, Edge, and mobile browsers
- Protocol: httpMethod(), httpVersion(), encoding()
- Response bodies: responseBody() with JSON success/error templates

Registers http.yml in EnFile and Http in BaseProviders.
Includes HttpTest with 168 assertions covering all methods.

https://claude.ai/code/session_01WM2gJRU7t1i8sXu6wLx6ak
@what-the-diff

what-the-diff Bot commented Jun 8, 2026

Copy link
Copy Markdown

PR Summary

  • Introduction of HTTP-related Data Generation in BaseProviders interface
    A new method http() has been added to the BaseProviders interface. This method allows you to get an instance of the new Http provider.

  • Creation of a new Http Class for HTTP Data
    We've created a new Http class, which is responsible for generating various elements of HTTP data. These include status codes, headers, content types, user agents, and response bodies.

  • Addition of a Comprehensive HTTP Data Resource File
    We've introduced a new YAML file called http.yml. This file contains a thorough list of HTTP status codes, and details about request and response headers, content types, user agents, and more.

  • Update of the EnFile Class to Include http.yml
    The EnFile class now includes the path for the newly added http.yml file.

  • Introduction of Unit Tests for the Http Class
    New unit tests have been added in HttpTest.java. These tests cover various aspects of the HTTP data generation functionality introduced in the Http class.

Restructures response_body YAML from a flat JSON-only list into typed
sub-keys: json, xml, html, plain, csv, javascript, css, graphql, form,
and markdown. The no-arg responseBody() now picks randomly across all
types. The new responseBody(String contentType) method normalises the
MIME type (stripping parameters like "; charset=utf-8"), maps it to the
correct sub-key, and falls back to json for unrecognised types.

Test coverage expanded from 168 to 214 assertions, including a
@ParameterizedTest for all supported content types and a fallback test.

https://claude.ai/code/session_01WM2gJRU7t1i8sXu6wLx6ak
@codecov-commenter

codecov-commenter commented Jun 8, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.54%. Comparing base (53cdefd) to head (4cbb557).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #1835   +/-   ##
=========================================
  Coverage     92.53%   92.54%           
- Complexity     3523     3563   +40     
=========================================
  Files           344      345    +1     
  Lines          6969     7027   +58     
  Branches        684      685    +1     
=========================================
+ Hits           6449     6503   +54     
- Misses          358      360    +2     
- Partials        162      164    +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- "font/ttf"
- "font/woff"
- "font/woff2"
user_agent:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's a bit of duplication here with internet(), I know, but maybe internet is not the best name anymore.

Comment thread src/main/java/net/datafaker/providers/base/Http.java Outdated
"informational", "successful", "redirect", "client_error", "server_error"
);

private static final List<String> ALL_BODY_TYPES = List.of(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd suggest you call this TEXT_BODY_TYPES or something like that. It definitely isn't "all" and it doesn't cover any non-text based types as far as I can tell. (image etc)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's all within the scope of the change, it's all all in the scope of the universe.

Comment on lines +25 to +27
// -------------------------------------------------------------------------
// Status codes — return int
// -------------------------------------------------------------------------

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This seems kinda redundant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

how so? you mean the int? or the whole comment?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The whole comment. The methods declare their return type.

Comment on lines +93 to +100
// -------------------------------------------------------------------------
// Combined code + reason — return String like "200 OK"
// -------------------------------------------------------------------------

/** Returns a random status code and reason phrase, e.g. {@code "200 OK"} or {@code "404 Not Found"}. */
public String statusCodeWithReason() {
return randomStatusEntry();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why multi-line single line comment? Why not just make proper JavaDoc? (Esp in a single method like this)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Idk :) Ask Claude. But also, I wasn't sure if we actually enforced the formatting on this. I don't think we do, but I'm happy to change it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think spotless has anything for this. I'd rather the muitiple single line comment ummm "section breaks" were removed, if there's anywhere they're actually valuable then merge with the JavaDoc.

Comment on lines +324 to +329
form:
- "name=John+Doe&email=john%40example.com&status=active"
- "username=admin&password=secret&remember=true"
- "id=42&action=update&value=hello+world"
- "grant_type=authorization_code&code=abc123&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback"
- "query=search+term&page=1&per_page=20&sort=asc"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't make sense. When have you seen a response like this?

(I'm not saying it's impossible, but form url encoding is generally associated with requests)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right. Maybe I'll just remove form from the list.

Comment thread src/main/resources/en/http.yml
Comment on lines +233 to +237
// -------------------------------------------------------------------------
// Enums
// -------------------------------------------------------------------------

public enum Browser {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wow Claude, enums are enums? Insightful

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used Mythos. Maybe that's why ;)

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.

4 participants