Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task - Manage the format requested by the client #67

Closed
Tracked by #86
benoitdm-oslandia opened this issue Oct 13, 2022 · 3 comments
Closed
Tracked by #86

Task - Manage the format requested by the client #67

benoitdm-oslandia opened this issue Oct 13, 2022 · 3 comments
Assignees
Labels
Milestone

Comments

@benoitdm-oslandia
Copy link
Owner

benoitdm-oslandia commented Oct 13, 2022

In GitLab by @nrevelant on Oct 13, 2022, 16:43

Currently, pgfeatureserve seems to let the client choose the responses format on GET requests. :

  • through route suffix, like file extension (net.go) :
func RequestedFormat(r *http.Request) string {
	// first check explicit path
	path := r.URL.EscapedPath()
	if strings.HasSuffix(path, ".html") {
		return FormatHTML
	}
	if strings.HasSuffix(path, ".json") {
		return FormatJSON
	}
	if strings.HasSuffix(path, ".txt") {
		return FormatText
	}
	if strings.HasSuffix(path, ".svg") {
		return FormatSVG
	}
  • through the "Accept" header
	// Use Accept header if present
	hdrAccept := r.Header.Get("Accept")
	//fmt.Println("Accept:" + hdrAccept)
	if strings.Contains(hdrAccept, ContentTypeSchemaJSON) {
		return FormatSchemaJSON
	}
	if strings.Contains(hdrAccept, ContentTypeHTML) {
		return FormatHTML
	}
	return FormatJSON

However this parameter seems to have a limited support with mostly JSON formatted response ( handleItem() function inside handler.go ) :

		switch format {
		case api.FormatJSON:
			return writeItemJSON(ctx, w, name, fid, param, urlBase, crs)
		case api.FormatHTML:
			return writeItemHTML(w, tbl, name, fid, query, urlBase)
		default:
			return nil
		}

The TestWeakEtagFromDifferentRepresentationsDb test for example will cover this use case.

NB: In the case of an unsupported format, the return code should be : 406 Not Acceptable

@benoitdm-oslandia
Copy link
Owner Author

  1. Dans le cas de la réponse du handleItem on a bien du HTML :

    case api.FormatHTML:
     		return writeItemHTML(w, tbl, name, fid, query, urlBase)
  2. Pour le coup il faut prendre une décision pour l'affichage ou non de l'eTag dans la cas d'un retour HTML. Personnellement je pense que c'est une information utile au traitement de la donnée mais pas trop utile à l'affichage. Pour le coup, il ne serait pas nécessaire de modifier la sortie HTML pour prendre en compte l'eTag.

  3. Concernant :

    Dans le cas où le serveur ne peut fournir le format demandé par le client, le code de retour HTTP serait 406 Not Acceptable

    Je pense qu'il va falloir se pencher un peu plus sur la gestion des codes d'erreurs car ce ne sont pas toujours les bons qui sont utilisés ==> @jmkerloch

@benoitdm-oslandia
Copy link
Owner Author

marked this issue as related to #85

@benoitdm-oslandia
Copy link
Owner Author

In GitLab by @nrevelant on Nov 7, 2022, 14:31

marked this issue as related to #87

@benoitdm-oslandia benoitdm-oslandia self-assigned this Nov 7, 2022
@nick-rv nick-rv changed the title Task - Gérer le format de réponse demandé par le client Task - Manage the format requested by the client Nov 8, 2022
@benoitdm-oslandia benoitdm-oslandia added this to the 03_SPRINT milestone Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

1 participant