Add dedicated Http faker with status codes, headers, user agents and more#1835
Add dedicated Http faker with status codes, headers, user agents and more#1835bodiam wants to merge 3 commits into
Conversation
…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
PR Summary
|
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
| - "font/ttf" | ||
| - "font/woff" | ||
| - "font/woff2" | ||
| user_agent: |
There was a problem hiding this comment.
There's a bit of duplication here with internet(), I know, but maybe internet is not the best name anymore.
| "informational", "successful", "redirect", "client_error", "server_error" | ||
| ); | ||
|
|
||
| private static final List<String> ALL_BODY_TYPES = List.of( |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
it's all within the scope of the change, it's all all in the scope of the universe.
| // ------------------------------------------------------------------------- | ||
| // Status codes — return int | ||
| // ------------------------------------------------------------------------- |
There was a problem hiding this comment.
This seems kinda redundant
There was a problem hiding this comment.
how so? you mean the int? or the whole comment?
There was a problem hiding this comment.
The whole comment. The methods declare their return type.
| // ------------------------------------------------------------------------- | ||
| // 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(); | ||
| } |
There was a problem hiding this comment.
Why multi-line single line comment? Why not just make proper JavaDoc? (Esp in a single method like this)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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" |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Yes, you're right. Maybe I'll just remove form from the list.
| // ------------------------------------------------------------------------- | ||
| // Enums | ||
| // ------------------------------------------------------------------------- | ||
|
|
||
| public enum Browser { |
There was a problem hiding this comment.
Wow Claude, enums are enums? Insightful
There was a problem hiding this comment.
I used Mythos. Maybe that's why ;)
Introduces net.datafaker.providers.base.Http with:
redirect(), clientError(), serverError() — all return int
covering Chrome, Firefox, Safari, Edge, and mobile browsers
Registers http.yml in EnFile and Http in BaseProviders.
Includes HttpTest with 168 assertions covering all methods.
https://claude.ai/code/session_01WM2gJRU7t1i8sXu6wLx6ak